Any_instance undefined in model
-
30-06-2021 - |
Question
I am writing up a rspec test - and for some reason, i am told that the method any_instance is undefined. I am quite surprised, because I have a very similar expectations in one of my controllers rspec files - and it works fine. Any ideas why this could be happening?
require 'spec_helper'
describe Subscriber do
it {should belong_to :user}
describe "send_message should use mobile to send message" do
subscriber = Subscriber.new(:number => "123")
Mobile.any_instance.should_receive(:send_sms).with("123")
subscriber.send_message("hello!")
end
end
Error
/subscriber_spec.rb:9:in `block (2 levels) in <top (required)>':
undefined method `any_instance' for Mobile:Class (NoMethodError)
My rspec version (taken from my gemfile is)
gem "rspec-rails", ">= 2.11.0", :group => [:development, :test]
Thanks!
La solution
Really clear: you didn't wrap your test in an it
block. That's all.
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow