1

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

以下是我的 gemfile 中包含的 gem:cucumber、cucumber-rails、rspec、rspec-rails、capybara、capybara-envjs、database_cleaner、launchy

我设置了以下内容:

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

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

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

当我评论该行时,以下场景可以正常工作: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

也许是因为数据库清理器,但我保留了默认配置:truncation

请问有什么想法吗?

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

4

1 回答 1

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 的时间点或代码。

于 2011-03-16T04:23:22.953 回答