I have »buildr« »buildfile« which triggers some »rspec« tests. I would like to pass some path parameters to the tests, so that It wont cause trouble to load test-resources files. In the »buildfile« I have got this code to trigger the tests:
RSpec.configure do |config|
config.add_setting :spec_resources_dir, :default => _(:src, 'spec', 'ruby', 'resources')
end
RSpec::Core::RakeTask.new(:run_rspec) do |t|
t.pattern = 'src/spec/**/*_spec.rb'
end
task test => [:run_rspec]
But if I try to retrieve the value in the specfile like this:
RSpec.configuration.spec_resources_dir
I get this error
undefined method `spec_resources_dir' […] (NoMethodError)
Any ideas?
RSpec's rake task runs the specs in a separate process, so configuration you do with RSpec.configure
in the buildfile will not be visible to the running specs.
Two suggestions for passing info from the buildfile to your spec task:
spec_helper
and require it from your specs (or via rspec's -r
command line option and the rspec_opts
config parameter on RSpec::Core::RakeTask
). You could use buildr's filtering to substitute values from the buildfile into the helper.ENV
and then read them out from your specs. Environment variables are shared from parent to child processes.By request, an example for #1:
RSpec::Core::RakeTask.new do |t|
t.rspec_opts = "-r '#{_(:target, 'spec_helper.rb')}'"
end
This assumes that you (probably in another task) generate the spec helper into _(:target, 'spec_helper.rb')