RSpec - 如何排除子目录中的规范文件?

ker*_*lin 5 directory configuration rspec

假设我有以下spec子目录:

lib
models
observers
workers
Run Code Online (Sandbox Code Playgroud)

在spec_helper.rb文件中,如何告诉rspec排除lib子目录中的所有spec文件?

Spork.prefork do

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

  Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}

  RSpec.configure do |config|
    config.mock_with :rspec
    config.use_transactional_fixtures = false

    config.before(:suite) do
      DatabaseCleaner.clean_with :truncation
      DatabaseCleaner.strategy = :transaction
    end

    config.before(:each) do
      DatabaseCleaner.start
    end

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

    config.treat_symbols_as_metadata_keys_with_true_values = true
    config.filter_run :focus => true
  end

end

Spork.each_run do
  FactoryGirl.reload
end
Run Code Online (Sandbox Code Playgroud)

仅供参考 - 我正在使用防护来自动重新加载测试。

Tan*_*ili 1

不确定如何排除,但您可以在防护中包含一个列表,如下所示:

guard 'rspec', :spec_paths => ['spec/models', 'spec/workers', 'spec/observers'] do
  # ...
end
Run Code Online (Sandbox Code Playgroud)