From command line I invoke the rake task as follows;
rake add -- --num1 1 --num2 2
And the task is defined as follows;
require 'optparse'
task :add do
options = {}
OptionParser.new do |opts|
opts.banner = "Usage: rake add [options]"
opts.on("-o", "--num1 ARG", Integer) { |x| options[:x] = x }
opts.on("-t", "--num2 ARG", Integer) { |y| options[:y] = y }
end.parse!
puts options[:x].to_i + options[:y].to_i
exit
end
How can I invoke the task from the test case. Can I use
Rake::Task["add"].invoke
If so, how to pass arguments num1 and num2 ?