Say I have the following spec
subdirectories:
lib
models
observers
workers
In the spec_helper.rb file, how do I tell rspec to exclude all spec files in the lib subdirectory?
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
FYI - I'm using guard to auto-reload tests.
Not sure how to exclude but you can include a list in guard like this:
guard 'rspec', :spec_paths => ['spec/models', 'spec/workers', 'spec/observers'] do
# ...
end
One solution is Exclusion Filters:
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
exclusion flag can be applied to describe
and context
too.
Also, this is useful config option:
RSpec.configure do |c|
c.run_all_when_everything_filtered = true
end
So if everything in /lib
is excluded, you will still be able
to run specs manually with rspec spec/lib/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With