好的,我不确定在设置 capybara 时缺少什么,但在测试访问链接时似乎无法正常工作。所以我有一个 3.2 的应用程序,我的 specs_helper 设置如下:
require "spork"
Spork.prefork do
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'factory_girl'
require 'capybara/rspec'
require 'capybara/rails'
Capybara.javascript_driver = :selenium
Capybara.default_wait_time = 5
include Devise::TestHelpers # see spec/support/devise.rb
include CarrierWave::Test::Matchers
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
include New_spec_helpers
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
RSpec.configure do |config|
config.mock_with :rspec
config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.use_transactional_fixtures = false
config.before :each do
Capybara.default_selector = :css
if Capybara.current_driver == :rack_test
DatabaseCleaner.strategy = :transaction
else
DatabaseCleaner.strategy = :truncation
end
DatabaseCleaner.start
end
config.after do
DatabaseCleaner.clean
end
end
end
Spork.each_run do
FactoryGirl.factories.clear
FactoryGirl.define do
sequence(:code) { |n| "code#{n}" }
sequence(:title) { |n| "title#{n}" }
end
Dir[Rails.root.join("spec/factories/**/*.rb")].each{|f| load f}
PortfolioNew::Application.reload_routes!
end
然后我的测试设置如下:
before(:each) do
build_projects
visit(projects_path)
end
it "test js" , :js=>true do
current_path.should == projects_path
end
然而,我得到的回报是:
Failure/Error: current_path.should == projects_path
expected: "/projects"
got: nil (using ==)
我检查了我的路线,项目路径绝对正确且有效。任何关于这个问题的想法将不胜感激