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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s