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!

有帮助吗?

解决方案

Really clear: you didn't wrap your test in an it block. That's all.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top