在我的Rake文件中:
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
Run Code Online (Sandbox Code Playgroud)
在rspec_config.rb中
RSpec.configure {|c| c.fail_fast = true}
Run Code Online (Sandbox Code Playgroud)
我的文件结构:
|-- 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
Run Code Online (Sandbox Code Playgroud)
当rake任务运行时,它将按顺序对上述文件结构进行操作.如何确保'001_hello'失败然后它不应该运行'002_hello'?
目前它以相反的顺序运行,即.'003_hello'然后'002_hello'然后'001_hello'.
您需要修改任务模式以使文件以特定顺序运行.例如:
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
Run Code Online (Sandbox Code Playgroud)
这将按###_*/spec/*_spec.rb字母顺序运行所有匹配的文件.
| 归档时间: |
|
| 查看次数: |
5149 次 |
| 最近记录: |