5

假设我有以下spec子目录:

lib
models
observers
workers

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

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

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

4

2 回答 2

1

不知道如何排除,但您可以在警卫中包含一个列表,如下所示:

guard 'rspec', :spec_paths => ['spec/models', 'spec/workers', 'spec/observers'] do
  # ...
end
于 2012-07-14T17:48:13.380 回答
1

一种解决方案是排除过滤器

RSpec.configure do |c|
  # declare an exclusion filter
  c.filter_run_excluding :broken => true
end

describe "something" do
  it "does one thing" do
  end

  # tag example for exclusion by adding metadata
  it "does another thing", :broken => true do
  end
end

describe排除标志也可以应用context

此外,是有用的配置选项:

RSpec.configure do |c|
  c.run_all_when_everything_filtered = true
end

因此,如果/lib排除其中的所有内容,您仍然可以使用手动运行规范rspec spec/lib/

于 2014-06-26T07:21:59.023 回答