2

这是我的第一个在线问题,所以请发表评论,我会尝试更新我的问题以澄清。

我对 Web 开发很陌生,目前正在为公司项目开发测试套件。当我尝试对涉及javascript的函数进行集成测试时,它工作得很好。我尝试同时使用 webkit(从 gi​​t 捆绑)和 selenium。Webkit 给出了以下错误消息。

Wrote response false "Unable to load URL: http://127.0.0.1:56618/ because of error loading http://127.0.0.1:56618/: Connection closed" 
Cleaning database...done
Received "Reset" 
Started "Reset" 
Finished "Reset" 
Wrote response true "" 
  should see invalid message (FAILED - 1)
Failures:
  1) Users GET /sign_in with invalid account should see invalid message
 Failure/Error: visit root_path
 Capybara::Webkit::InvalidResponseError:
   Unable to load URL: http://127.0.0.1:56618/ because of error loading http://127.0.0.1:56618/: Connection closed

在使用 Selenium 时,FireFox 会抱怨:

Your Firefox profile cannot be loaded. It may be missing or inaccessible.

有人知道可能是什么问题吗?提前致谢!

我的 sepc_helper.rb

Spork.prefork do
  ...
  ..
  .
  RSpec.configure do |config|
    config.use_transactional_fixtures = false
    config.before(:suite) { require "#{Rails.root}/db/seeds.rb" }
    config.before(:each) do
      if Capybara.current_driver == :rack_test
        DatabaseCleaner.strategy = :transaction                                                                               
      else
        DatabaseCleaner.strategy = :truncation
      end
      DatabaseCleaner.start
    end

    config.after(:each) do
      if Capybara.current_driver == :rack_test
        DatabaseCleaner.clean
      else
        DatabaseCleaner.clean
        load "#{Rails.root}/db/seeds.rb"
      end 
    end 

  end
end

Spork.each_run do
  ActiveRecord::Schema.verbose = false
  load "#{Rails.root.to_s}/db/schema.rb"
  Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
end
4

1 回答 1

2

我不确定,但你可以试试这个,

spec_helper.rb在您的文件中添加以下代码

require 'spork'
Spork.prefork do

   # This file is copied to spec/ when you run 'rails generate rspec:install'

  ENV["RAILS_ENV"] ||= 'test'
  require File.expand_path("../../config/environment", __FILE__)

  require 'rspec/rails'

  require 'rspec/autorun'

  require 'email_spec'


  # Add this to load Capybara integration:

  require 'capybara/rspec'
  require 'capybara/rails'

  # Database Cleaner
  #require 'database_cleaner'

  # DatabaseCleaner.strategy = :truncation


  # 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}

Spork.each_run do
end

做一件事取消注释数据库清理器。

于 2012-10-15T13:03:34.430 回答