Landon Alder
Landon Alder

Reputation: 326

Run block once before all capybara tests

I'm using Capybara with Rspec for integration testing a rails app. Is there any way to run a before block once before the first Capybara test runs without it running before every feature spec? Putting a block in my RSpec.configure block as such causes it to run before each feature spec:

RSpec.configure do |config|
    config.before(:all, type: :feature) do
      # do some stuff
    end
end

Upvotes: 2

Views: 688

Answers (2)

Thomas Walpole
Thomas Walpole

Reputation: 49870

RSpec.configure do |config|
    config.before(:suite) do
      # do some stuff
    end
end

Upvotes: 1

Aleksei Matiushkin
Aleksei Matiushkin

Reputation: 121000

I think you are overengineering the task. Since you are to run it once, just run it:

cb = lambda { puts 'I am run once' }
RSpec.configure do |config|
  cb.call
end

Upvotes: 0

Related Questions