Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to send arguments to `rake cucumber` without using environment variables?

I see that it is possible to pass arguments to a rake task:

task :task_name, :arg_name do |t, args|

What I'd like to do is pass arguments into a cucumber rake task:

Cucumber::Rake::Task.new({:tags => 'db:test:prepare'}) do |t, args|
  t.cucumber_opts = ['--tags', #args?]
end

Is this sort of thing possible? This way I could do:

rake cucumber:tags['tag1', 'tag2', ...]

And have it run only those tags. Most sources say to use an environment variable, which I have done, but I'd prefer to just provide the arguments the "right" way.

like image 282
Logan Serman Avatar asked Nov 02 '12 15:11

Logan Serman


People also ask

How do I run a rake task?

Go to Websites & Domains and click Ruby. After gems installation you can try to run a Rake task by clicking Run rake task. In the opened dialog, you can provide some parameters and click OK - this will be equivalent to running the rake utility with the specified parameters in the command line.

What are Rake tasks in Rails?

Rake is a popular task runner for Ruby and Rails applications. For example, Rails provides the predefined Rake tasks for creating databases, running migrations, and performing tests. You can also create custom tasks to automate specific actions - run code analysis tools, backup databases, and so on.

What is task in Ruby?

A Task is the basic unit of work in a Rakefile. Tasks have associated actions (possibly more than one) and a list of prerequisites.


1 Answers

You can get it to work by doing something like this:

task :task_name, :arg1 do |t, args|
  Cucumber::Rake::Task.new(:run) do |t|
    t.cucumber_opts = "--format pretty --tags @#{args[:arg1]}"
  end
  Rake::Task[:run].invoke()
end
like image 122
Kent Le Avatar answered Oct 05 '22 03:10

Kent Le