title: Mocking a non database backed model in Rails with Rspec
body: <p>I am trying to create a non ActiveRecord model in my Ruby on Rails application according to <a href="http://railscasts.com/episodes/121-non-active-record-model" rel="nofollow">http://railscasts.com/episodes/121-non-active-record-model</a>. I am facing hard time testing it though.</p>
  
  <p>I have following class in my <code>app/models/sms.rb</code> file.</p>
  
  <pre><code>class Sms
    def initialize
      # Do stuff here
    end
  
    def deliver
      # Do some stuff here
    end
  end
  </code></pre>
  
  <p>I am unable to mock deliver method on my Sms class.</p>
  
  <pre><code>it 'should do someting' do
    @sms = mock(Sms)
    @sms.should_receive(:deliver).and_return(true)
  
    post :create, :user_id =&gt; @user.id
    flash[:notice].should == "SMS sent successfully."
    response.should redirect_to(some_url)
  end
  </code></pre>
  
  <p>In my controller code I do have a line that says <code>@sms.deliver</code>. Yet above gives following error:</p>
  
  <pre><code>   Failure/Error: @sms.should_receive(:deliver).and_return(true)
        (Mock Sms).deliver(any args)
        expected: 1 time
        received: 0 times
  </code></pre>
  
  <p>Any pointers?</p>