Sasha Stadnik
Sasha Stadnik

Reputation: 532

Rspec stub public method

could you please me to help understand how to stub public method with Rspec in Rails.

class MyClass
  def start
    result = continue
    result << ' morning glory'
  end

  def continue
    'some text'
  end
end

add spec

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

Have you any ideas how to solve this ?

Thanks.

Upvotes: 0

Views: 233

Answers (1)

BroiSatse
BroiSatse

Reputation: 44725

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

Upvotes: 1

Related Questions