Stackoverflow question with code to reproduce the issue:
In a nutshell, if I assign a regex with a capture using a let statement. Something like this:
let(:my_matcher) { /RegexWithCapture(\d)/ }
Then it fails in the it block when I actually try to use my_matcher
"RegexWithCapture7".match(my_matcher)[1].should == 7
#=> fails
#=> NoMethodError: undefined method `[]' for /RegexWithCapture(\d)$/:Regexp
But!, If I invoke the matcher prior to using it, everything works as I'd expect.
my_matcher #just invoking it does the trick
"RegexWithCapture7".match(my_matcher)[1].should == 7
#=> passes
I haven't tested the above code, I'm just using it to explain the problem but the stackoverflow question has an actual reproducible case. Here's a Gist with the same code as the SO question: https://gist.github.com/forforf/5112445 it's a bit easier to read.
I'm really curious why the behavior changes by just invoking the let variable.
Ruby 1.9.3 & RSpec 2.13.0 fwiw.