Loading spec.opts when testing pure Ruby program
I'm writing spec for my pure ruby program and what I want to 开发者_运维百科do is to somehow load spec.opts
in my test suite.
I Rails we can just create a corresponding file and put it in the spec
folder of an app. But when I put a spec.opts
file in folder with my program in it - the magic doesn't work :)
My motivation is to get rid of passing options, i.e.
spec my_program_spec.rb -c -f s
every time I run spec
command.
Is this Rspec 2? If so, options go into .rspec
instead of spec.opts
. .rspec
can go in the project root, or in the user home directory (./.rspec or ~/.rspec).
If it is Rspec 1, put spec.opts
in the project root folder.
The --options flag lets you specify a file of options rather than entering them one-by-one:
spec --options spec/spec.opts
You could also create a Rakefile in the root directory of the project and put something like this in it:
require 'spec/rake/spectask'
Spec::Rake::SpecTask.new do |t|
t.spec_opts = ['--options', 'spec/spec.opts']
end
This would let you run your test suite with the file of options using Rake:
rake spec
(I haven't used RSpec 2 yet, so all of this is RSpec 1).
精彩评论