我試圖從Webrat切換到水豚後得到測試工作。當我嘗試登錄到應用程序時,我收到了「無效的用戶名/密碼」錯誤,儘管只是使用factory_girl在工廠中創建了用戶。我理解它的方式,用戶應該堅持整個夾具,對吧?Rails水豚問題
factories.rb:
Factory.define :user do |user|
user.firstname "Test"
user.lastname "Test"
user.email "[email protected]"
user.password "testtest"
user.password_confirmation "testtest"
end
layout_links.spec.rb:
describe "LayoutLinks" do
before(:each) do
wrong_user = Factory(:user)
integration_sign_in(wrong_user)
end
it "should have a dashboard page" do
get '/dashboard'
page.should have_css('h1', :text => "Navigation#dashboard")
end
spec_helper.rb
def integration_sign_in(user)
visit signin_path
fill_in :email, :with => user.email
fill_in :password, :with => user.password
click_button "Sign in"
puts page.body
end
同樣在spec_helper.rb如下:
config.use_transaction al_fixtures =假
config.before(:suite) do
DatabaseCleaner.strategy = :truncation
end
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
不宜用戶堅持,然後在integration_sign_in
功能是成功的?我仍然可以通過開發環境中的瀏覽器正確登錄,該開發環境中有一個用戶,登錄在遷移之前可以與webrat正常工作,所以我不知道該怎麼想。謝謝!
更新:它看起來像會話不正確地去服務器。在服務器上,當我檢查會話電子郵件地址和密碼的值,該值是不正確的:
puts "Post Email: " + params[:session][:email]
puts "Post Password: " + params[:session][:password]
電子郵件變量的密碼變量,password變量沒有價值。爲什麼會這樣?客戶端集成測試可正確映射這些字段:
fill_in :email, :with => user.email
fill_in :password, :with => user.password
如何進一步測試?謝謝。
感興趣的Rails教程1e追隨者試圖放棄網頁 – prusswan 2012-02-10 09:42:29