我正在運行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