我试图从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