How can I get Rspec to run all tests nested under a folder?

筅森魡賤 提交于 2019-12-20 17:38:14

问题


I like to run my Rspec tests with Spork running in a separate tab. I usually run my tests using rspec spec, by which I intend to say "search recursively and run everything in the spec folder."

I've recently realized that this does not actually run all my tests. I now have a spec file in spec/requests which isn't being run. I know this because I've edited one of the tests to raise an error, and run the following:

  • rspec spec - no error raised.
  • rspec spec/requests - still no error raised, and 0 examples, 0 failures!
  • rspec spec/requests/my_controller.rb - bingo. 17 examples, 1 failure and the failure has my error message.

Why isn't Rspec finding all my test files? Is this a matter of configuration, or do I need to use a different command to run my tests?

I need to run all my tests at once to ensure that I'm not introducing regressions.

(Not using Spork makes no difference, by the way.)


回答1:


Rspec should already look recursively through the directory you named and find all tests. Note however, that it's looking for files ending in _spec.rb. Maybe some of your files are not named correctly?

If you need to be more specific about which files it should find, you can also use the --pattern option. For example: rspec --pattern spec/requests/*_spec.rb. (Option --pattern is equal to -P. Taken from rspec --help)




回答2:


you can create a rake task

desc "Run PCMag tests"
  RSpec::Core::RakeTask.new('test') do |t|
  t.rspec_opts = ["-Ilib","--format documentation","--color"]
  t.pattern = ['spec/test/*.rb']
end

Then execute command rake test.

Above command will execute all .rb tests under folder 'test'

Please check following link for more details.

http://testautomationarchives.blogspot.in/2013/10/rspec-rake-framework-in-ruby-with.html



来源:https://stackoverflow.com/questions/9362799/how-can-i-get-rspec-to-run-all-tests-nested-under-a-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!