ruby on rails - undefined method `receive_message_chain' -
surprisingy can't find this.
trying stub chain of methods:
twitter::rest::client.new(<some credentials>).user.followers_count
what want this:
allow_any_instance_of(twitter::rest::client).to receive_message_chain(:user, :followers_count).and_return 0
but did not work. gave error undefined method 'receive_message_chain'
.
so found tutorial on rspec-mocks 3.0: https://github.com/rspec/rspec-mocks/blob/master/features/method_stubs/receive_message_chain.feature
and tried this:
subject = twitter::rest::client allow(subject).to receive_message_chain(:user, :followers_count).and_return 0 expect(twitter::rest::client.new.users.followers_count).to eq 0
just try out - , did not work either. there i'm doing wrong?
i have rspec-mocks (3.0.0.beta1)
in gemfile.lock
.
other types of stubs (like .to receive(:method)
work fine.
the method receive_message_chain
introduced in 3.0.0.beta2, described in https://github.com/rspec/rspec-mocks/blob/master/changelog.md#300beta2--2014-02-17, if upgrade version of rspec-mocks
(currently @ 3.0.0.rc1), should ok syntax.
Comments
Post a Comment