ted
ted

Reputation: 5329

Stub regex in rspec

How can a regex be stubed? e.g.

# somewhere deep in the code
reg = Regexp.new("foo bar")
res = reg.match string

# somewhere in rspec
reg = Regexp.new("foo bar")
reg.stub(:match).with(string).and_return "rspec_res" #doesn't work

Upvotes: 0

Views: 489

Answers (1)

davidrac
davidrac

Reputation: 10738

I think this should work:

reg = stub :match => "rspec_res"
Regex.stub(:new) { reg }

Upvotes: 1

Related Questions