如何使用Cucumber-Capybara断言是否存在闪存变量?

时间:2011-09-09 06:06:36

标签: ruby-on-rails ruby-on-rails-3 cucumber capybara web

我正在使用Cucumber和Capybara运行Rails 3.0.7项目,我有一个步骤定义来检查是否存在flash [:error]:

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

当我进行黄瓜测试时,我收到错误

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'

这是处理变量断言的正确方法吗?我注意到如果我使用会话[:某事],就会发生同样的错误。

2 个答案:

答案 0 :(得分:2)

您应该检查页面上实际可见的内容,例如在这种情况下:

page.should_not have_css('.flash')

答案 1 :(得分:0)

要断言 no context.Database.SqlQuery<EntityType>( @"declare param1 int = --some logic declare param2 varchar = --some logic EXEC Components @param1=@param1,@param2=@param2" ); 消息集(任何类型),您可以这样做:

flash

要断言特定类型集(本例中为assert_predicate flash, :empty? )没有flash消息,您可以执行以下操作:

:error