你能不能帮我理解如何在Rails中使用Rspec存根公共方法。
class MyClass
def start
result = continue
result << ' morning glory'
end
def continue
'some text'
end
end
添加规范
context '#start' do
let(:myclass) { MyClass.new }
let(:result) { "What*s the story morning glory" }
**1 variant(not working)**
before { myclass.stub(:continue) { "What*s the story" } }
**2 variant(not working)**
before { MyClass.any_instance.stub(:continue) { "What*s the story" } }
it { expect(myclass.start).to eql result }
end
您有任何想法如何解决这个问题吗?
感谢。
答案 0 :(得分:1)
before(:each) { MyClass.any_instance.stub(:continue).and_return "What*s the story" }