Capybara JS测试在单独的线程上运行?

时间:2014-10-06 14:17:48

标签: ruby-on-rails capybara rspec3

当我把js:true时,我无法看到我的Capybara测试工作。我认为这与我在测试中如何处理数据库有关。这里的任何帮助都会很棒。这是我的错误:

Failure/Error: Unable to find matching line from backtrace
ActiveRecord::RecordNotFound:
Couldn't find Executive with 'id'=vid_url [WHERE "users"."type" IN ('Executive')]

我的rails_helper.rb

require "codeclimate-test-reporter"
SimpleCov.start do
  formatter SimpleCov::Formatter::MultiFormatter[
    SimpleCov::Formatter::HTMLFormatter,
    CodeClimate::TestReporter::Formatter
  ]
  add_filter '/spec/'
end

ENV["RAILS_ENV"] ||= 'test'
require 'spec_helper'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'capybara/email/rspec'
require 'capybara/rails'
require 'capybara/webkit/matchers'
require 'database_cleaner'
require 'shoulda/matchers'
require 'webmock/rspec'

# Select Javascript driver
Capybara.javascript_driver = :webkit

# Speed up Devise
Devise.stretches = 1

# Allow net access so we stub out only necessary HTTP requests
WebMock.allow_net_connect!
#WebMock.disable_net_connect!(allow_localhost: true)

# Requires supporting ruby files with custom matchers and macros, etc, in
# spec/support/ and its subdirectories. 
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }

# Checks for pending migrations before tests are run.
# If you are not using ActiveRecord, you can remove this line.
ActiveRecord::Migration.maintain_test_schema!

RSpec.configure do |config|

  # Faster feedback when running all specs
  config.fail_fast = true

  # FactoryGirl syntax methods
  config.include FactoryGirl::Syntax::Methods

  config.use_transactional_fixtures = false

  config.before(:each) do |example|
    DatabaseCleaner.strategy = example.metadata[:js] ? :truncation : :transaction
    DatabaseCleaner.start
    stub_request(:any, /api.hellosign.com/).to_rack(FakeHelloSign)
  end

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

  config.include(Capybara::Webkit::RspecMatchers, type: :feature)

  config.infer_spec_type_from_file_location!

  # Helpers
  config.include Features::ExecutiveHelpers, type: :feature
  config.include Features::BuyerHelpers, type: :feature
  config.include Features::AccessRequestHelpers, type: :feature
  config.include Helpers::SessionHelpers
  config.include Helpers::PathHelpers
  config.include Helpers::CountHelpers
  config.include Helpers::Mailers
  config.include Helpers::DebuggingHelpers
  config.include Devise::TestHelpers, type: :controller
  config.include Requests::UserSessionRequestHelper, type: :request
end

0 个答案:

没有答案