我是Cucumber的新手,完全不知道为什么集成测试会失败。我有以下几个场景:
Scenario: User changes profile
Given I have an account
When I change my profile
Then my profile should be saved
Scenario: User changes login
Given I have an account
When I change my login information
Then my account should be changed这些步骤定义如下:
Given /^I have an account$/ do
@user = Factory.create(:user)
visit login_path
fill_in "Email", :with => @user.email
fill_in "Password", :with => 'secret'
click_button "Sign in"
end
When /^I change my profile$/ do
visit edit_user_profile_path(@user)
fill_in "First name", :with => "John"
fill_in "Last name", :with => "Doe"
click_button "Update Profile"
end
Then /^my profile should be saved$/ do
@user.profile.first_name.should == "John"
@user.profile.last_name.should == "Doe"
end
When /^I change my login information$/ do
visit edit_user_path(@user)
fill_in "Email", :with => "foo@example.com"
click_button "Update Login Information"
end
Then /^my account should be changed$/ do
@user.email.should == "foo@example.com"
end在这两种情况下,我都不能满足"Then“条件,并显示以下消息:
# Scenario 1
expected: "John"
got: "Test1" (using ==) (RSpec::Expectations::ExpectationNotMetError)
# Scenario 1
expected: "foo@example.com"
got: "test2@example.com" (using ==) (RSpec::Expectations::ExpectationNotMetError)因此,在这两种情况下,提交表单以更新用户登录或配置文件后,工厂信息仍然存在。但是,如果我在真正的浏览器中测试它,它就能完美地工作。那么,为什么这个测试失败了?
谢谢你的帮助!
发布于 2011-02-10 05:59:45
@user只是一个存在于cucumber代码块中的变量。它将不会被更改。在测试中要更改的是数据库记录。要检查它是否确实已更改,您必须访问显示用户名的某个页面。
(就像你在现实生活中的测试一样)
https://stackoverflow.com/questions/4948817
复制相似问题