Sam Joseph
Sam Joseph

Reputation: 4694

Rakefile causes RSpec to run tests twice

I have a weird issues with rake running RSpec. RSpec by itself works fine, but when run via rake using this Rakefile:

require 'rubocop/rake_task'
require 'rspec/core/rake_task'

RuboCop::RakeTask.new(:cop)
RSpec::Core::RakeTask.new(:spec)

task default: [:cop, :spec]

it generates output like this:

Failures:

1) member of public accesses bike docking station unable to release as none available Failure/Error: expect { docking_station.release_bike }.to raise_error 'No Bikes Available' expected Exception with "No Bikes Available" but nothing was raised # /Users/me/Projects/boris-bikes/spec/feature/public_bike_access_spec.rb:12:in `block (2 levels) in '

2) member of public accesses bike docking station unable to release as none available Failure/Error: expect { docking_station.release_bike }.to raise_error 'No Bikes Available' expected Exception with "No Bikes Available" but nothing was raised # ./spec/feature/public_bike_access_spec.rb:12:in `block (2 levels) in '

Finished in 0.01419 seconds (files took 0.36303 seconds to load) 10 examples, 2 failures

Failed examples:

rspec /Users/me/Projects/boris-bikes/spec/feature/public_bike_access_spec.rb:10 # member of public accesses bike docking station unable to release as none available rspec ./spec/feature/public_bike_access_spec.rb:10 # member of public accesses bike docking station unable to release as none available

/Users/me/.rvm/rubies/ruby-2.2.0/bin/ruby -I/Users/me/.rvm/gems/ruby-2.2.0/gems/rspec-support-3.2.1/lib:/Users/me/.rvm/gems/ruby-2.2.0/gems/rspec-core-3.2.0/lib /Users/me/.rvm/gems/ruby-2.2.0/gems/rspec-core-3.2.0/exe/rspec --pattern spec/**{,/*/**}/*_spec.rb failed

it seems to be finding the same spec file twice in the same location;

Users/me/Projects/boris-bikes/spec/feature/public_bike_access_spec.rb:10

AND

./spec/feature/public_bike_access_spec.rb:10

Any ideas what might be causing this?

Upvotes: 0

Views: 210

Answers (1)

Dan Kohn
Dan Kohn

Reputation: 34327

Rspec adds itself to default. You want to remove it first with clear and then re-add it:

task(:default).clear.enhance [:cop, :spec]

Upvotes: 0

Related Questions