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.configurein the buildfile will not be visible to the running specs.Two suggestions for passing info from the buildfile to your spec task:
spec_helperand require it from your specs (or via rspec's-rcommand line option and therspec_optsconfig parameter onRSpec::Core::RakeTask). You could use buildr's filtering to substitute values from the buildfile into the helper.ENVand then read them out from your specs. Environment variables are shared from parent to child processes.By request, an example for #1:
This assumes that you (probably in another task) generate the spec helper into
_(:target, 'spec_helper.rb')