Dasmowenator Dasmowenator - 1 year ago 69
Ruby Question

How to specify the RSpec "syntax" parameter on the command line?

We have a shell script which launches our RSpec tests. It looks something like this:

"--format" "html"
"--out" "$to_dir/index.html"

"$rspec_dir/rspec" "${args[@]}" "$tests_to_run"
exit $?

When trying to upgrade RSpec, I'm getting an error that the
syntax is deprecated, and we need to explicitly enable it like so: How to avoid deprecation warning for stub_chain in RSpec 3.0?

However, since we're not using Rake, I need to figure out a way to do this when launching rspec through the command line. But when I try adjusting the command line options like so:

./rspec --format "html" --out "index.html" --syntax ":should"

It says
is not a valid option. How can I enable this deprecated syntax while invoking rspec directly through the command line?

(We can't use Rake because our internal build tools don't support it. That's why I need to find out how to do this through the command line.)

Answer Source

You can't configure RSpec expectations and mocks syntax on the command line. Edit your project's spec/spec_helper.rb to include the following:

RSpec.configure do |config|
  config.expect_with :rspec do |expectations|
    expectations.syntax = [:should, :expect]
  config.mock_with :rspec do |mocks|
    mocks.syntax = [:should, :expect]

After you're upgraded, you'll probably want to change all of your examples to use the new syntax (probably with transpec) and then disable the :should syntax.

More here https://relishapp.com/rspec/rspec-expectations/docs/syntax-configuration and here https://relishapp.com/rspec/rspec-mocks/docs/old-syntax/stub

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download