Acceptance test failed when js enabled
I am having a weird problem with my acceptance test for login page.
The login works fine when js in not enabled ie. the following case:
scenario "login with valid authentication" do
visit login_path
page.should have_content("Sprout Login开发者_运维技巧")
fill_in("user_login", :with => "mark")
fill_in("user_password", :with => "secured")
click_button "Sign in"
page.should have_content("mark")
end
But when I enabled javascript, the login fails and gives invalid login message.
scenario "login with valid authentication", :js => true do
visit login_path
page.should have_content("Sprout Login")
fill_in("user_login", :with => "mark")
fill_in("user_password", :with => "secured")
click_button "Sign in"
page.should have_content("mark")
end
BTW I am using Devise for authentication. Thanks in Advance.
UPDATE: recently noticed that when js is enabled, test server is not starting and hence login fails. Any idea?
Your tests will fail unless a default user is created and logs in before each test runs. Devise provides test helpers to make it simple to create and log in a default user. Create a file spec/support/devise.rb:
RSpec.configure do |config|
config.include Devise::TestHelpers, :type => :controller
end
I was having the same issue and found a thread with a solution:
RSpec.configure do |config|
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
end
For the DatabaseCleaner stuff to work you'll need to include the database_cleaner
gem. If you haven't used it before, you may need to rake db:test:prepare
before rerunning your tests. I hope this works for you, too!
精彩评论