tags:

views:

41

answers:

1

Rake allows for the following syntax:

task :my_task, :arg1, :arg2 do |t, args|
  puts "Args were: #{args}"
end

I'd like to be able to do the same, but with RSpecs SpecTask.

The following unfortunately fails:

desc "Run example with argument"
SpecTask.new('my_task'), :datafile do |t, args|
  t.spec_files = FileList['*_spec.rb -datafile=#{args}']
  t.spec_opts = ["-c -f specdoc"]
end

Is it possible to achieve this with a SpecTask, or is there an alternative approach?

+1  A: 

if rspec doesn't support the args variable, you could pass it in as a command line parameter and/or a variable from another location.

rake datafile=somevalue

@datafile = ENV["datafile"]

desc "Run example with argument"
SpecTask.new :my_task do |t|
  t.spec_files = FileList["*._spec.rb -datafile=#{@datafile}"]
  #... etc
end
Derick Bailey
thanks Derick, that works nicely.
Bayard Randel