Thursday, June 9, 2016

[Linux/Unix] How to pass command line arguments to RSpec script?

RSpec doesn't allow you pass custom arguments in command line, however you can pass them as environment variable in Linux (doesn't work for windows)

Suppose you want to pass configuration file to the script as argument while running rspec, you can do this way:

CONFIG_FILE="example.yaml" rspec example_spec.rb

Access the environment variable in the script

describe "something" do  before(:each) do    config_file = ENV["CONFIG_FILE"]
  end
  it "does something that passes" do    expect(5).to eq(5)
  end
end
 
 

No comments:

Post a Comment