0

如何对正则表达式进行存根?例如

# 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
4

1 回答 1

1

我认为这应该有效:

reg = stub :match => "rspec_res"
Regex.stub(:new) { reg }
于 2012-08-02T15:20:25.647 回答