我正在运行Rails 4,试图与Rspec和Capybara建立一些集成测试。我想设立后卫来进行'宙斯测试'。每当我做出改变。问题是,一旦有事情形成水豚DSL被调用时,或者当我尝试使用路线帮手,我给出这样的错误:警卫不加载Capybara DSL
undefined local variable or method `root_path' for #<RSpec::Core::ExampleGroup::Nested_2::Nested_1:0x007f55682c6d60>
如果我换成“/” root_path得到它:
undefined method `visit' for #<RSpec::Core::ExampleGroup::Nested_2::Nested_1:0x007f556833bbb0>
如果我只是运行'rspec规格'。或'宙斯测试'。它工作正常。
我试过删除'cmd:'宙斯测试。'选项从我的Guardfile,但我有同样的问题。似乎很清楚,问题出在Guard身上,与宙斯无关。
在我的Gemfile:
group :development, :test do
gem 'capybara'
gem 'rspec-rails'
gem 'factory_girl_rails'
gem 'guard-rspec', require: false
gem 'better_errors'
gem 'binding_of_caller'
end
规格帮手:
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'factory_girl_rails'
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
RSpec.configure do |config|
config.include FactoryGirl::Syntax::Methods
config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.use_transactional_fixtures = true
config.infer_base_class_for_anonymous_controllers = false
config.order = "random"
end
规格我试图运行:
require 'spec_helper'
describe "HomePage" do
describe "Root page" do
before { visit root_path }
it "works!" do
page.status_code.should be(200)
end
it 'contains bottom nav buttons' do
page.should have_link 'How it works'
page.should have_link 'Customer Service'
page.should have_link 'Terms of Service'
page.should have_link 'Contact Us'
end
end
end
谢谢,但我在我的问题中确实提到了它在Guard之外可以正常工作。我尝试了这个以及config.include Capybara :: DSL,但都没有帮助Guard工作。 – Joeman29