簡體   English   中英

Rspec存根公共方法

[英]Rspec stub public method

您能否請我幫助您了解如何在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

您有什么解決辦法的想法嗎?

謝謝。

before(:each) { MyClass.any_instance.stub(:continue).and_return "What*s the story" }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM