Cucumber:场景创建条目并在测试之前删除它 =>失败
我是黄瓜新手,我在 Rails 3 应用程序中遇到了困难:)
以下是我的 gemfile 中包含的 gem:cucumber、cucumber-rails、rspec、rspec-rails、capybara、capybara-envjs、database_cleaner、launchy
我进行了以下设置:
require 'capybara/envjs'
Capybara.javascript_driver = :envjs
在我的网站中,任何人都可以订阅新闻通讯。它通过 ajax 工作得很好,并显示一条漂亮的类似咆哮的消息:
- mail valid =>欢迎...
- 邮件无效=>哎呀...
当我评论该行时,以下场景工作正常:我的邮件列表中应该有 1 封邮件
。
通过这一行,我收到以下错误消息: 我的邮件列表中应该有 1 封邮件 # features/step_definitions/mailing_steps.rb:1 预计:1、 得到:0(使用==)(RSpec::Expectations::ExpectationNotMetError)
@javascript
Scenario: Entering Valid Mail
Given I am on the about page
When I fill in "mailing[mail]" with "[email protected]"
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:我应该补充一点,像白痴一样刷新我的数据库,我看到邮件首先添加然后被删除。
I'm newbie in cucumber and I'm struggling with it in my Rails 3 app :)
Here are the gems included in my gemfile: cucumber, cucumber-rails, rspec, rspec-rails, capybara, capybara-envjs, database_cleaner, launchy
I set up the following:
require 'capybara/envjs'
Capybara.javascript_driver = :envjs
In my website, it's possible for anyone to subscribe to the news letter. It works fine through ajax and displays a nice growl-like message:
- mail valid => Welcome...
- mail invalid => Oops...
The following scenario works fine, when I comment the line: I should have 1 mail in my mailing list
.
With this line, I have the following error message: 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 "[email protected]"
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"
Here is the step I added:
Then /^I should have ([0-9]+) mail in my mailing list?$/ do |count|
Mailing.count.should == count.to_i
end
Maybe it's due to database cleaner but I kept the default configuration :truncation
Any idea please?
PS: I should add that refreshing my database like a moron, I see the mail first added then being deleted.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会挂断电话
调试器
并检查有多少邮件。
调试器将需要安装 gem 'ruby-debug' 或 'ruby-debug19'。
如果 Mailing.count 为 0,我会将该调试器行移动到测试的早期位置,直到找到它为 1 的位置,然后隔离其变为 0 的时间点或代码。
I would drop the line
debugger at
And inspect how many Mailing's there are.
debugger will require the gem 'ruby-debug' or 'ruby-debug19' to be installed.
If Mailing.count is 0, I would move that debugger line into earlier in the test until I found where it was 1 and then isolate the point in time or code where its going to 0.