I'm new to Ruby, and I've been trying to learn Rake, RSpec, and Cucumber. I found some code that will help me test my Rake tasks, but I'm having trouble getting it to work. I was told here: http://blog.codahale.com/2007/12/20/rake-vs-rspec-fight/to drop this:
def describe_rake_task(task_name, filename, &block)
require "rake"
describe "Rake task #{task_name}" do
attr_reader :task
before(:all) do
@rake = Rake::Application.new
Rake.application = @rake
load filename
@task = Rake::Task[task_name]
end
after(:all) do
Rake.application = nil
end
def invoke!
for action in task.instance_eval { @actions }
instance_eval(&action)
end
end
instance_eval(&block)
end
end
into my spec_helper.rb file.
I've managed to take this code out and run it in my cucumber steps like this:
When /^I run the update_installers task$/ do
@rake = Rake::Application.new
Rake.application = @rake
load "lib/tasks/rakefile.rb"
@task = Rake::Task["update_installers"]
for action in @task.instance_eval { @actions }
instance_eval(&action)
end
instance_eval(&block)
Rake.application = nil
end
but when I try to get things working in rspec, I get the following error.
ArgumentError in 'Rake task install_grapevine should install to the mygrapevine directory'
wrong number of arguments (1 for 2) /spec/spec_helper.rb: 21:in
instance_eval' /spec/spec_helper.rb: 21:in
block in invoke!' /spec/spec_helper.rb: 20:ineach' /spec/spec_helper.rb: 20:in
invoke!' /spec/tasks/rakefile_spec.rb:12:in `block (2 levels) in '
Unfortunately, I've got just under a week of ruby under by belt, so the metaprogramming stuff is over my head. Could anyone point me in the right direction?