Sending Arguments in Command Line while running RSpec tests

Suppose you want to run your rspec specs on various product environments & at run-time you want to mention where you would like the scripts to run, you can create a command line parameter say ENVIRONMENT and assign it a value like this :-

ENVIRONMENT= “dev” rspec spec/sanity_test_spec.rb

Similarly you can assign it values like prod, preproduction etc.

In your spec files you can retrieve the parameter value like this :-

runtime_param = ENV[‘ENVIRONMENT’]
puts “Evironment value got on runtime is #{runtime_param}”

The keyword ‘ENV’ is a built-in ruby term(I suppose) which handles this functionality.