Я использую 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