ruby - How to run RSpec scripts with custom arguments -
i have specific requirement run rspec scripts supplying configuration file during run time.
rspec doesn't allow supply custom arguments through command-line except pre-defined ones "--tag, --format, --output etc.."
is there workaround this?
after lot of digging in through various online resources , stackoverflow, found workaround this:
by using dotenv
gem, can achieve this.
install dotenv
$ gem install dotenv
create .env file in test script folder custom arguments "key=value" pairs, e.x:
config_file=test_config.yaml
read values environment variables in spec file
require 'dotenv' dotenv.load describe "passing arguments" before(:all) @configfile = env['config_file'] end "initiating device config" puts "using device config file #{@configfile}" end end
now read config file name environment variable in test scrips.
Comments
Post a Comment