开发者

Rails Capybara Problems

开发者 https://www.devze.com 2023-02-25 00:33 出处:网络
I am trying to get tests working after switching from Webrat to Capybara.When I try to sign in to the application I am getting a \"Invalid username/password\" error, despite just having created the us

I am trying to get tests working after switching from Webrat to Capybara. When I try to sign in to the application I am getting a "Invalid username/password" error, despite just having created the user in a Factory using factory_girl. The way I understand it, the user should persist for the entirety of the fixture, right?

factories.rb:

Factory.define :user do |user|
  user.firstname             "Test"
  user.lastname              "Test" 
  user.email                 "test@test.com"
  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

Also in spec_helper.rb is the following:

config.use_transactional_fixtures = false

    config.before(:suite) do
        DatabaseCleaner.strategy = :truncation
    end

    config.before(:each) do
        DatabaseCleaner.start
    end

    config.after(:each) do
        DatabaseCleaner.clean
    end

Shouldn't the user persist and then be successful in the integration_sign_in function? I can still sign in correctly through the browser in the development environment, which has a user and the sign in was working correctly with webrat before the migration, so I am not sure what to think. Thanks!

UPDATE: It looks like the session isn't going to the server correctly. On the server, when I check the value of email and password in the session, the values are incorrect:

puts "Post Email: " + params[:session][:email]
puts "Post Password: " + params[:session][:password]

the email variable has the password variable, and the password variable has no value. Why would this 开发者_Python百科be? The client integration test maps the fields correctly:

fill_in :email,    :with => user.email
fill_in :password, :with => user.password

How can I test this further? Thanks.


So this worked for me

fill_in "Email", :with => user.email
fill_in "Password", :with => user.password

whereas using the symbols failed


It looks like the session wasn't going to the server correctly. I am not sure how to account for this.

0

精彩评论

暂无评论...
验证码 换一张
取 消