如何使用正则表达式? 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
答案 0 :(得分:1)
我认为这应该有效:
reg = stub :match => "rspec_res"
Regex.stub(:new) { reg }