문제

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