简体   繁体   English

rspec / guard运行minitest并获得无效选项:-f

[英]rspec/guard running minitest and getting invalid option: -f

I'm running rails 4.1 and when I run rspec inside of guard, it give me the following error at the end: 我正在运行Rails 4.1,并且在警卫队内部运行rspec时,最后会出现以下错误:

invalid option: -f

minitest options:
    -h, --help                       Display this help.
    -s, --seed SEED                  Sets random seed
    -v, --verbose                    Verbose. Show progress processing files.
    -n, --name PATTERN               Filter run on /pattern/ or string.

Known extensions: pride
    -p, --pride                      Pride. Show your testing pride!

This is a minitest error, but as far as I can find, I'm not running minitest anywhere. 这是最小测试错误,但据我所知,我没有在任何地方运行最小测试。 Any idea where this might come from? 知道这可能来自哪里吗?

spec_helper spec_helper

require 'rubygems'

ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'capybara/rspec'
require 'monban/test/helpers'
require 'rails/test_help'

Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
Monban.test_mode!

RSpec.configure do |config|
  config.fixture_path = "#{::Rails.root}/spec/fixtures"

  config.include FactoryGirl::Syntax::Methods
  config.include Monban::Test::Helpers, type: :feature
  config.include Monban::Test::ControllerHelpers, type: :controller
  config.use_transactional_fixtures = true
  config.infer_base_class_for_anonymous_controllers = false
  config.order = "random"

  config.before :each do
    DatabaseCleaner.strategy = :transaction
    DatabaseCleaner.start
  end

  config.after(:each) do
    DatabaseCleaner.clean
  end

  config.after :each do
    Monban.test_reset!
  end
end

Guardfile Guardfile

guard :rspec, cmd: 'spring rspec' do
  watch(%r{^spec/.+_spec\.rb$})
  watch(%r{^lib/(.+)\.rb$})     { |m| "spec/lib/#{m[1]}_spec.rb" }
  watch('spec/spec_helper.rb')  { "spec" }

  # Rails example
  watch(%r{^app/(.+)\.rb$})                           { |m| "spec/#{m[1]}_spec.rb" }
  watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$})          { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
  watch(%r{^app/controllers/(.+)_(controller)\.rb$})  { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
  watch(%r{^spec/support/(.+)\.rb$})                  { "spec" }
  watch('config/routes.rb')                           { "spec/routing" }
  watch('app/controllers/application_controller.rb')  { "spec/controllers" }

  # Capybara features specs
  watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$})     { |m| "spec/features/#{m[1]}_spec.rb" }

  # Turnip features and steps
  watch(%r{^spec/acceptance/(.+)\.feature$})
  watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$})   { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
end

Turns out, I was running minitest because of this line in my spec_helper : 事实证明,由于我的spec_helper的这一行,我正在运行spec_helper

require 'rails/test_help'

Removing that makes it not run minitest. 删除使其无法运行minitest。 However, I added that line to keep my test schema up to date with my development schema, a new feature in Rails 4.1. 但是,我添加了这一行以使测试架构与开发架构保持最新,这是Rails 4.1中的一项新功能 What I should have done is removed this line from my spec_helper : 我应该做的是从我的spec_helper删除以下行:

ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)

and replaced it with this: 并替换为:

ActiveRecord::Migration.maintain_test_schema!

This seems to be the rspec equivalent to the minitest line that I removed. 这似乎是与我删除的minitest行等效的rspec。 I found this in the rspec generators here: https://github.com/rspec/rspec-rails/blob/aa5c5f76a9ae847648f48e0ea7802b8e83c11d0f/lib/generators/rspec/install/templates/spec/spec_helper.rb.tt#L15-L23 我在这里的rspec生成器中发现了这个: https : //github.com/rspec/rspec-rails/blob/aa5c5f76a9ae847648f48e0ea7802b8e83c11d0f/lib/generators/rspec/install/templates/spec/spec_specer_helper.rb.tt#L15-L23

Now my schema stays up to date and minitest doesn't run. 现在,我的架构保持最新状态,并且minitest无法运行。

Had the same issue. 有同样的问题。 For me, removing test-unit gem fixed it. 对我来说,删除test-unit宝石将其修复。

Some other gems can cause this as well: https://github.com/guard/guard-rspec/issues/169 其他一些宝石也可能导致这种情况: https : //github.com/guard/guard-rspec/issues/169

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM