Fix for --example so that it is not double-escaped when running tests over DRb
Created by: mcmire
I found a little unexpected bug with the escaping behavior of --example. Basically, if you're running RSpec over DRb, and you run a command like
rspec spec/whatever_spec.rb --example "foo bar"
you'll get an error like
No examples matched {:full_description=>/(?-mix:foo\\\ bar)/}.
The issue is that the first time the options are parsed, --example is escaped, so RSpec ends up with a regex like /foo\ bar/
. The options then get passed to the RSpec server over DRb, but before that happens, --example is stringified again, simply by getting the source
of the regex. Unfortunately /foo\ bar/.source
is not "foo bar", it's "foo\ bar", so that's what get passed along.
I've fixed this by stripping any backslashes that appear in the --example group prior to being passed on. We do have to make the assumption that any backslashes that do appear were inserted by RSpec and aren't intentional, but I think that's a fair assumption.