In my Rake file:
require 'rspec/core/rake_task'
desc 'Default: run specs.'
task :default => :spec
desc "Run specs"
RSpec::Core::RakeTask.new do |task|
task.pattern = "**/spec/*_spec.rb"
task.rspec_opts = Dir.glob("[0-9][0-9][0-9]_*").collect { |x| "-I#{x}" }.sort
task.rspec_opts << '-r ./rspec_config'
task.rspec_opts << '--color'
task.rspec_opts << '-f documentation'
end
In rspec_config.rb
RSpec.configure {|c| c.fail_fast = true}
My file structure:
|-- 001_hello
| |-- hello1.rb
| `-- spec
| `-- hello_spec.rb
|-- 002_hello
| |-- hello2.rb
| `-- spec
| `-- hello_spec.rb
|-- 003_hello
| |-- hello3.rb
| `-- spec
| `-- hello_spec.rb
|-- Rakefile
`-- rspec_config.rb
when rake task will run it will do the operation sequentially on the above file structure. How to ensure that if '001_hello' fails then it should not run '002_hello'?
Currently it run on reverse order ie. '003_hello' then '002_hello' then '001_hello'.
You need to modify the task pattern to get files to run in a particular order. For instance:
RSpec::Core::RakeTask.new do |task|
task.pattern = Dir['[0-9][0-9][0-9]_*/spec/*_spec.rb'].sort
task.rspec_opts = Dir.glob("[0-9][0-9][0-9]_*").collect { |x| "-I#{x}" }
task.rspec_opts << '-r ./rspec_config --color -f d'
end
This will run all files matching ###_*/spec/*_spec.rb
in alphabetical order.
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