Cucumber:场景创建条目并在测试之前删除它 =>失败

发布于 2024-10-08 19:41:41 字数 1340 浏览 3 评论 0原文

我是黄瓜新手,我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡紫姑娘! 2024-10-15 19:41:41

我会挂断电话
调试器

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

I would drop the line
debugger at

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文