How can I claim to have flash variables with Cucumber-Capybara?

I am running a Rails 3.0.7 project with Cucumber and Capybara, and I have a step definition that checks if flash [: error] exists:

Then /^I should be able to see the main page properly$/ do current_path.should == "/" flash[:error].should == nil end 

When I run my cucumber test, I get an error

 And I should be able to see the main page properly # features/step_definitions/user_auth_steps.rb:17 undefined method `flash' for nil:NilClass (NoMethodError) ./features/step_definitions/user_auth_steps.rb:19:in `/^I should be able to see the main page properly$/' features/user_auth.feature:10:in `And I should be able to see the main page properly' 

Is this the right way to handle variable statements? I noticed that if I use [: something] sessions, the same type of error will occur.

+4
source share
2 answers

You should check what is actually visible on the page, for example. in this case:

 page.should_not have_css('.flash') 
+2
source

To claim that there is no flash message set (of any type), you can do:

 assert_predicate flash, :empty? 

To state that in this example there is no flash message of a specific set of types ( :error ), you can do:

 assert_predicate flash[:error], :nil? 
0
source

All Articles