黄瓜似乎跳过了给定的步骤
据我所知,黄瓜在这两个场景之间只访问数据库一次,但它会在场景之间清除数据库。
功能:
Feature: a new user vists the site and signs up
in order to get new users
when an unlogged in users comes to the website
then they should see the sign-up dialog
and be able to signup for the website
Background:
Given I have at least one deal
Scenario: a new user is asked to signup
Given I am on show deal
Then I should see "New Here?"
@javascript
Scenario: new user signup failure
Given I am on show deal
When I fill in "consumer[user_attributes][email]" with "[email protected]"
And I press "consumer_submit"
Then I should see "1 error prohibited"
步骤定义:
Given /^I have at least one deal$/ do
Deal.create copy:'Example Deal Copy', copy_header:'Example Deal Header', copy_subheader:'Example Deal Subheader' if Deal.all.size == 0
end
结果:
Background: # features/new_user_signup.feature:7
Given I have at least one deal # features/step_definitions/new_user_signup_steps.rb:1
Scenario: a new user is asked to signup # features/new_user_signup.feature:10
Given I am on show deal # features/step_definitions/web_steps.rb:44
Then I should see "New Here?" # features/step_definitions/web_steps.rb:105
@javascript
Scenario: new user signup failure # features/new_user_signup.feature:15
Given I am on show deal # features/step_definitions/web_steps.rb:44
Couldn't find Deal with ID=1 (ActiveRecord::RecordNotFound)
./app/controllers/deals_controller.rb:17:in `show'
<internal:prelude>:10:in `synchronize'
./features/step_definitions/web_steps.rb:45:in `/^(?:|I )am on (.+)$/'
features/new_user_signup.feature:16:in `Given I am on show deal'
When I fill in "consumer[user_attributes][email]" with "[email protected]" # features/step_definitions/web_steps.rb:60
And I press "consumer_submit" # features/step_definitions/web_steps.rb:52
Then I should see "1 error prohibited" # features/step_definitions/web_steps.rb:105
Failing Scenarios:
cucumber features/new_user_signup.feature:15 # Scenario: new user signup failure
无论我放在第二个位置,都会出现 ActiveRecord 错误。为什么我的第二种情况数据库中没有记录?
As best I can tell cucumber is only hitting the database once between these two scenarios, but it's clearing out the database between scenarios.
The Features:
Feature: a new user vists the site and signs up
in order to get new users
when an unlogged in users comes to the website
then they should see the sign-up dialog
and be able to signup for the website
Background:
Given I have at least one deal
Scenario: a new user is asked to signup
Given I am on show deal
Then I should see "New Here?"
@javascript
Scenario: new user signup failure
Given I am on show deal
When I fill in "consumer[user_attributes][email]" with "[email protected]"
And I press "consumer_submit"
Then I should see "1 error prohibited"
The Step Definition:
Given /^I have at least one deal$/ do
Deal.create copy:'Example Deal Copy', copy_header:'Example Deal Header', copy_subheader:'Example Deal Subheader' if Deal.all.size == 0
end
The Result:
Background: # features/new_user_signup.feature:7
Given I have at least one deal # features/step_definitions/new_user_signup_steps.rb:1
Scenario: a new user is asked to signup # features/new_user_signup.feature:10
Given I am on show deal # features/step_definitions/web_steps.rb:44
Then I should see "New Here?" # features/step_definitions/web_steps.rb:105
@javascript
Scenario: new user signup failure # features/new_user_signup.feature:15
Given I am on show deal # features/step_definitions/web_steps.rb:44
Couldn't find Deal with ID=1 (ActiveRecord::RecordNotFound)
./app/controllers/deals_controller.rb:17:in `show'
<internal:prelude>:10:in `synchronize'
./features/step_definitions/web_steps.rb:45:in `/^(?:|I )am on (.+)$/'
features/new_user_signup.feature:16:in `Given I am on show deal'
When I fill in "consumer[user_attributes][email]" with "[email protected]" # features/step_definitions/web_steps.rb:60
And I press "consumer_submit" # features/step_definitions/web_steps.rb:52
Then I should see "1 error prohibited" # features/step_definitions/web_steps.rb:105
Failing Scenarios:
cucumber features/new_user_signup.feature:15 # Scenario: new user signup failure
Whichever scenario I put second will give the ActiveRecord error. Why are there no records in the database for my second scenario?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
现在我知道你是如何映射“show deal”的了,我想说问题是 Deal 实例可能存在,但它的 id 不等于 1。你能检查一下吗?
这里有一个提示:当您在 path.rb 中定义路径时,您可以执行以下操作:
甚至可以这样:
只要您像这样定义了“我在”网页步骤:
这比“交易/1”:)
Now I know how you've mapped "show deal" I am tempted to say that the problem is that the Deal instance possibly exists but it's id is not equal 1. Can you check please?
And here is a tip: while you're defining paths in your path.rb, you may do something like this:
or even this:
As long as you've defined your "I am on" webstep like this:
It's far better than "deals/1" :)