启用js时,验收测试失败



我在登录页面的验收测试中遇到了一个奇怪的问题。

登录工作正常,当js在未启用ie。以下情况:

  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

但是当我启用javascript时,登录失败并给出无效的登录消息。

  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

顺便说一句,我正在使用设计进行身份验证。提前感谢。

更新:最近注意到,当js启用时,测试服务器没有启动,因此登录失败。任何想法?

除非在每次测试运行之前创建默认用户并登录,否则测试将失败。设计提供了测试助手,使创建和登录默认用户变得简单。创建一个文件spec/support/design .rb:

RSpec.configure do |config|
  config.include Devise::TestHelpers, :type => :controller
end

我有同样的问题,发现一个线程的解决方案:

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

要使DatabaseCleaner工作,您需要包含database_cleaner gem。如果以前没有使用过它,则可能需要在重新运行测试之前执行rake db:test:prepare。我希望这对你也有用!

最新更新