黄瓜:在test =>之前创建条目并删除它的场景失败

时间:2010-12-22 17:31:33

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

我是黄瓜新手,我在Rails 3应用程序中苦苦挣扎:)

以下是我的gemfile中包含的宝石:黄瓜,黄瓜轨道,rspec,rspec-rails,水豚,capybara-envjs,database_cleaner,launchy

我设置了以下内容:

require 'capybara/envjs'
Capybara.javascript_driver = :envjs

在我的网站上,任何人都可以订阅新闻信。它通过ajax工作正常,并显示一个很好的咆哮信息:

  • mail valid =>欢迎...
  • 邮件无效=>糟糕...

当我评论该行时,以下情况正常:I should have 1 mail in my mailing list

有了这一行,我收到以下错误消息:And I should have 1 mail in my mailing list # features/step_definitions/mailing_steps.rb:1 expected: 1, got: 0 (using ==) (RSpec::Expectations::ExpectationNotMetError)

@javascript
Scenario: Entering Valid Mail
Given I am on the about page
When  I fill in "mailing[mail]" with "cucumber@cucumber.com"
And   I press "REGISTER"
Then  I should be on the about page
And   I should have 1 mail in my mailing list
And   I should see "Welcome" within "#gritter-notice-wrapper"

以下是我添加的步骤:

Then /^I should have ([0-9]+) mail in my mailing list?$/ do |count|
  Mailing.count.should == count.to_i
end

也许这是由于数据库更清洁,但我保留了默认配置:截断

请问好吗?

PS:我应该像白痴一样添加刷新我的数据库,我看到邮件先添加然后被删除。

1 个答案:

答案 0 :(得分:0)

我会放弃这条线 调试器在

Then /^I should have ([0-9]+) mail in my mailing list?$/ do |count|
  debugger
  Mailing.count.should == count.to_i
end

检查有多少邮件。

调试器将需要安装gem'ruby-debug'或'ruby-debug19'。

如果Mailing.count为0,我会将调试器行移到测试的早期,直到找到它为1的位置,然后将时间点或代码隔离到0。