Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'Feature' and 'Scenario' aliases from Capybara throw an 'undefined method' error when used with RSpec

Tags:

rspec

capybara

It looks like those aliases are not loaded properly. I'm using Rails 3.X, rspec 2.8 and capybara 1.1.2 to write some integration tests. I think that my installation of Capybara is successful as it all works with the standard 'describe' and 'it' tags, but 'feature' and 'scenario' aliases from Capybara throw an 'undefined method' error.

I don't see anything in the documentation mentioning more configuration: https://github.com/jnicklas/capybara I have simply added the 'require capybara/rspec' in my spec_helper.rb

like image 553
Vincent Peres Avatar asked Jan 25 '12 21:01

Vincent Peres


1 Answers

It seems like you can't combine describe/it with feature/scenario syntax. I was getting the same error when I nested a scenario block inside a describe block. Once I replaced the describe with feature, the test ran. One gotcha: It also does not seem to like nested feature blocks, which I guess makes sense in the context of acceptance testing.

describe "some feature" do  # <== BAD
  scenario "some scenario" do
    #spec code here
  end
end

feature "some feature" do  # <== GOOD
  scenario "some scenario" do
    #spec code here
  end
end

UPDATE I dug into Capybara's source code, and before and it don't get aliased by background and scenario unless the describe block gets created with capybara_feature => true which happens when you create the block with feature instead of describe.

like image 190
Ruy Diaz Avatar answered Oct 11 '22 19:10

Ruy Diaz