好吧我不确定在设置水豚时我缺少什么,但在测试时,访问链接似乎不起作用。所以我有一个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 ==)
我检查了我的路线,项目路径肯定是正确和有效的。我们将非常感激地对这个问题提出任何想法
答案 0 :(得分:1)
好的,我在这篇类似的帖子Rails 3 rspec + capybara - current_path is nil?
的评论中发现了这个问题原来与Capybara的网络冲突是在旧测试时留下的。
所以对于任何有兴趣的人我只是从我的宝石文件中评论出来并且一切都很好!
答案 1 :(得分:0)
尝试将visit
调用移至it
块:
before(:each) do
build_projects
end
it "test js" , :js=>true do
visit(projects_path)
current_path.should == projects_path
end