I'm having a problem with my Selenium test, it looks like the test data is not getting added to the right environment or Selenium is trying to read from the wrong one.
The below test passes without :js => true
but with it it fails
it "allows the user to create a new test", :js => true do
FactoryGirl.create(:user, email:'test@test.com', password:'passw0rd')
p 'Here'
p User.all
visit '/' # Login view
fill_in "email", with: 'test@test.com'
fill_in "password", with: "passw0rd"
click_button 'Login'
expect(current_path).to eq '/home'
end
The test fails because the user isn't getting logged in and hence not reaching '/home'. I added print outs to see if the user was actually getting added to the database and it is...
"Here"
#<ActiveRecord::Relation [#<User id: 1, email: "test@test.com", password: "$2a$10$JQBuNH95JWDjCTx0OH7JMuxcO.0XgAz6wtYc/2G8pps...", created_at: "2014-08-27 11:34:44", updated_at: "2014-08-27 11:34:44">]>
However when I added another print out to my login_controller
def create
p 'Here 2'
p User.all
... # User authenitcation
end
The console looks like
"Here"
#<ActiveRecord::Relation [#<User id: 1, email: "test@test.com", password: "$2a$10$JQBuNH95JWDjCTx0OH7JMuxcO.0XgAz6wtYc/2G8pps...", created_at: "2014-08-27 11:34:44", updated_at: "2014-08-27 11:34:44">]>
"Here 2"
#<ActiveRecord::Relation []>
So for some reason the User that is being added in the test isn't in the Database at the time the authentication is taking place, leading me to think Selenium is looking at a different environment i.e development when it should be looking at test?
If it helps here is some of my spec_helper
file with the database_cleaner config
...
RSpec.configure do |config|
config.use_transactional_fixtures = false
config.before(:suite) do
DatabaseCleaner.strategy = :truncation
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end
config.before(:each, :js => true) do
DatabaseCleaner.strategy = :truncation
end
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
...
end
Any thoughts on how to fix this? I don't know whether Selenium is looking at the wrong environment or my database_cleaner config is wrong