我是新來的黃瓜,完全失去了爲什麼這個集成測試失敗。我有以下情況:黃瓜+ Webrat不提交表單?
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 => "[email protected]"
click_button "Update Login Information"
end
Then /^my account should be changed$/ do
@user.email.should == "[email protected]"
end
我不能在這兩種情況下與此消息的 「然後」 條件:
# Scenario 1
expected: "John"
got: "Test1" (using ==) (RSpec::Expectations::ExpectationNotMetError)
# Scenario 1
expected: "[email protected]"
got: "[email protected]" (using ==) (RSpec::Expectations::ExpectationNotMetError)
所以,兩種情況下,在提交表單更新用戶登錄或配置文件後,工廠信息仍然存在。但是,如果我在真正的瀏覽器中測試它,它完美地工作。那麼,爲什麼這個測試失敗?
感謝您的幫助!
你有一個函數來獲取當前登錄的用戶,而不是使用@user嗎? –
我有一個current_user方法,但可以從測試中訪問嗎?你的意思是使用而不是@user來更新表單或檢查結果嗎?在任何情況下,我都沒有看到它是怎麼回事,這些表單顯然是抓住了正確的用戶,並且頁面正確地加載到了webrat中(我知道,因爲它沒有提出任何填寫或點擊的錯誤) ,控制器不允許,除非當前用戶是一個編輯... – Andrew