【发布时间】:2014-06-16 09:04:06
【问题描述】:
我正在运行 Rails 4,尝试使用 Rspec 和 Capybara 设置一些集成测试。我想设置警卫来运行“宙斯测试”。每当我做出改变时。问题是,每当调用 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 spec .'或“宙斯测试”。它工作正常。
我已尝试删除 'cmd: 'zeus test 。'我的 Guardfile 中的选项,但我遇到了同样的问题。很明显,问题出在 Guard 身上,与 zeus 无关。
在我的 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
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-4 rspec capybara guard