在我的Rake文件:如何爲RSpec編寫自定義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
在rspec_config.rb
RSpec.configure {|c| c.fail_fast = true}
我的文件結構:
|-- 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
當耙任務將運行它會做上述操作順序文件結構。 如何確保'001_hello'失敗,那麼它不應該運行'002_hello'?
目前它運行在相反的順序,即。 '003_hello'然後'002_hello'然後'001_hello'。
感謝Thomakos,但是如果我按照你的說法做了以下的錯誤:':29:'require':no such file to load - hello1(LoadError) \t from <內部:lib/rubygems/custom_require>:29:在'require'中 \t from /home/suvankars/RnD/rspec/001_hello/spec/hello_spec.rb:1:in''' –
suvankar
'重新從你的載入路徑丟失文件 - 然後 - 這與排序無關。我會更新我的文章,並回答如何添加這些文件。理想情況下,您應該以其他方式將這些文件添加到路徑中,否則應該在您的規格中包含文件的相對路徑。 –
我明白了。感謝Thomakos指出。 – suvankar