0

I'm making a mock for some Object with RSpec and rspec-mocks. What I dis is the below.

In Spec file

describe 'foo' do
  before do
    Mock.start
  end
end

In Mock file

module Mock
  def self.start
    SomeClass.stub_chain(:foo).and_return(Mock.mock_create)
  end

  def self.mock_create
    return json
  end
end

But if I use stub_chain, the below deprecation warning occurs.

Using `stub_chain` from rspec-mocks' old `:should` syntax without explicitly enabling the syntax is deprecated. Use the new `:expect` syntax or explicitly enable `:should` instead.

Do you have any ideas which solve this warning? The allow method looks unuseful because I wanna code like Object.something_instead_of_stub_chain(:create).and_return(Mock.mock_create).

Sergio Tulentsev
  • 226,338
  • 43
  • 373
  • 367

1 Answers1

2

The new way of doing it is

   expect(SomeClass).to receive_message_chain(:foo, :bar, :baz).and_return(something_here)
   # or if not a chain
   expect(SomeClass).to receive(:foo).and_return(something_here)

Instead of expect you may use allow. Those will not fail if the method is not called at all but will return specified values when called.

Greg
  • 5,862
  • 1
  • 25
  • 52