title: RSpec mock fails with "undefined method `-' for nil:NilClass"
body: <p>I have a simple method that I want to test with RSpec.  I want to ensure that <code>apply</code> decrements <code>player.capacity</code> by one.  To do this, I have mocked a player object and am testing to see if it receives the correct messages.</p>
  
  <h2>Code</h2>
  
  <pre><code>class DecreaseCapacity &lt; Item
    def apply player
      player.capacity -= 1
    end
  end
  </code></pre>
  
  <h2>Test</h2>
  
  <pre><code>describe DecreaseCapacity, "#apply" do
    it "should decrease capacity by one" do
      player = double()
      player.should_receive(:capacity)   # reads the capacity
      player.should_receive(:capacity=)  # decrement by one
      subject.apply player
    end
  end
  </code></pre>
  
  <h2>Failure Message</h2>
  
  <pre><code>1) DecreaseCapacity#apply should decrease the player's capacity by one
     Failure/Error: subject.apply player
     undefined method `-' for nil:NilClass
     # ./item.rb:39:in `apply'
     # ./item_spec.rb:25
  </code></pre>
  
  <p>What's going on here?  Why is <code>player.capacity -= 1</code> attempting to call <code>-</code> on <code>nil</code>?</p>