How to pass command-line parameter to Rspec script?

Dear all,

Anyone know how to pass command-line parameter to Rspec script?

For example:
I want to run the test.rb script. Suppose there is a parameter that is
set in test.rb script is sleep. For the convenience,I want to set the
parameter for sleep in the command-line.
If type : $ spec test.rb --sleep 10
The script will sleep 10 seconds.
If type $ spec test.rb --sleep 5
The script will sleep 5 seconds.

Anyone can describe the detail how to do that?

Thanks in advance!

On Apr 18, 2011, at 10:58 PM, Zhong wrote:

If type $ spec test.rb --sleep 5
The script will sleep 5 seconds.

Anyone can describe the detail how to do that?

You can’t pass arbitrary arguments to the rspec command, but you can set
an environment variable like this:

SLEEP=10 rspec test.rb

Then within the script, the value of ENV[“SLEEP”] is “10”, so you can
say:

sleep(ENV[“SLEEP”].to_f)

HTH,
David

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs