rspec测试无法启用javascript

时间:2016-07-25 22:09:33

标签: ruby-on-rails ruby-on-rails-4 selenium rspec-rails

我接受了rspec和selenium的下一次测试:

require 'rails_helper'

feature "Creating an student" do
  context "When an student visit the sign_up page" do
    scenario "Should be able to create an student" do
      state = FactoryGirl.create(:state)
      city = FactoryGirl.create(:city, state: state)
      institution = FactoryGirl.create(:institution)
      visit root_path
      .........

注册的设计功能是:

def new 
  @institutions = Institution.all.order(:name)
  @states = State.all
  @cities = City.all
  super
end

当我在我的控制器中搜索州和城市时,我发现了这个,但是当我启用javascript时

scenario "Should be able to create an student", js: true do

州和城市归零。

更新1

我的spec_helper文件是这样的:

require 'database_cleaner'
require 'capybara'

Capybara.register_driver :chrome do |app|
  Capybara::Selenium::Driver.new(app, :browser => :chrome)
end

Capybara.javascript_driver = :chrome
Capybara.default_max_wait_time = 10

RSpec.configure do |config|
  config.before(:suite) do
    DatabaseCleaner.clean_with(:truncation)
    DatabaseCleaner.strategy = :transaction
  end⋅

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

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

我不知道为什么会这样。

0 个答案:

没有答案