I'm running a Rails 3.0.7 project with Cucumber and Capybara and I have a step definition that checks if a 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 correct way of handling variable assertions? I've noticed that if I were to use sessions[:something], the same type of error happens.
You should be checking what's actually visible on the page, e.g. in this case:
To assert that there is no
flash
message set (of any type), you can do:To assert that there is no
flash
message of a particular type set (:error
in this example), you can do: