Ruby on rails 3 水豚问题
在从Webrat切换到Capybara之后,我正在尝试让测试正常工作。当我尝试登录到应用程序时,我收到一个“无效用户名/密码”错误,尽管我刚刚在工厂中使用Factory_girl创建了用户。按照我的理解,用户应该坚持整个装置,对吗 factories.rb:Ruby on rails 3 水豚问题,ruby-on-rails-3,rspec,capybara,Ruby On Rails 3,Rspec,Capybara,在从Webrat切换到Capybara之后,我正在尝试让测试正常工作。当我尝试登录到应用程序时,我收到一个“无效用户名/密码”错误,尽管我刚刚在工厂中使用Factory_girl创建了用户。按照我的理解,用户应该坚持整个装置,对吗 factories.rb: Factory.define :user do |user| user.firstname "Test" user.lastname "Test" user.email
Factory.define :user do |user|
user.firstname "Test"
user.lastname "Test"
user.email "test@test.com"
user.password "testtest"
user.password_confirmation "testtest"
end
布局链接.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\u transactional\u fixtures=false
config.before(:suite) do
DatabaseCleaner.strategy = :truncation
end
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
用户不应该坚持下去,然后在集成\u登录
功能中成功吗?我仍然可以在开发环境中通过浏览器正确登录,开发环境中有一个用户,并且在迁移之前,登录在webrat中工作正常,因此我不确定该怎么想。谢谢
更新:会话似乎无法正确地连接到服务器。在服务器上,当我在会话中检查电子邮件和密码的值时,这些值不正确:
puts "Post Email: " + params[:session][:email]
puts "Post Password: " + params[:session][:password]
电子邮件变量有密码变量,密码变量没有值。为什么会这样?客户端集成测试正确映射字段:
fill_in :email, :with => user.email
fill_in :password, :with => user.password
我如何进一步测试这一点?谢谢。看起来会话没有正确地连接到服务器。我不知道如何解释这一点。所以这对我来说很有效
fill_in "Email", :with => user.email
fill_in "Password", :with => user.password
然而使用符号失败了我只是在“填充”中使用符号而不是字符串时重新创建了您的问题。。。然而,对我来说,字符串仍然不起作用。你是怎么修好的?实际上琴弦很好。。。Rails教程1e的追随者试图删除webrat,这让我混淆了我感兴趣的测试和开发