Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to pass command line arguments to spec/rspec?

Trying to pass some arguments to rspec, but coulnd't find any proper command-line options for the purpose. I could use environment variable for that, but not sure it is the best (and most transparent) way to configure the tests.

So, how can I pass the command-line arguments? If can't - which is the best and most acceptable alternative?

like image 399
BreakPhreak Avatar asked Nov 04 '22 18:11

BreakPhreak


1 Answers

One clean way to do this is to add tags for your options, though this might not work in your case.

rspec --tag sleep_5_seconds

And then in your spec_helper.rb

RSpec.configure do |c|
  before(:each, :sleep_5_seconds => true) do
    setup_5_second_sleep
  end
end

This code hasn't been run, but that's the concept. You could also do it with an around block if you need to setup and teardown based on the variable.

like image 70
Lukas Oberhuber Avatar answered Nov 09 '22 13:11

Lukas Oberhuber