Do I need to stub EVERYTHING in this method in order to pass?
<p>I am generally new to mocha and I hate using this gem but I need to use it in order to pass a test that I am constructing. What is giving me problems is what I'm supposed to mock and how I am supposed to mock it. To illustrate my point, Here is an example of a method that I am testing:</p>

<pre><code> def statistics_of_last_24_hrs
    stats = ses.statistics.find_all { |s| s[:sent].between?(Time.now.utc - 24.hours, Time.now.utc) }
    sent_last_24_hrs = ses.quotas[:sent_last_24_hours].to_f
    no_of_bounces = stats.inject(0.0) { |a, e| a + e[:bounces] }
    no_of_complaints = stats.inject(0.0) { |a, e| a + e[:complaints] }
    bounce_rate = sent_last_24_hrs.zero? ? 0.0 : (no_of_bounces / sent_last_24_hrs) * 100
    complaint_rate = sent_last_24_hrs.zero? ? 0.0 : (no_of_complaints / sent_last_24_hrs) * 100
    fail(Reverification::SimpleEmailServiceLimitError, 'Bounce Rate exceeded 5%') if bounce_rate &gt;= 5.0 
    fail(Reverification::SimpleEmailServiceLimitError, 'Complant Rate exceeded .1%')if complaint_rate &gt;= 0.1 
  end
</code></pre>

<p>Basically what this code is doing is getting some statistics from an Amazon api call and then calculating them to determine if my bounce/complaint rate has exceeded the limit. The limit is 5% and 0.1% respectively.</p>

<p>Basically for my test all I really need to do is to stub the variables <code>bounce_rate</code> and <code>complaint_rate</code> in order to test whether the right exception is thrown.</p>

<p>This is where I am getting stuck. Here is a barebones test that I would ideally write:</p>

<pre><code>it 'should raise SimpleEmailServieLimitError if bounce rate is above 5%' do
  assert_raise Reverification::SimpleEmailServiceLimitError do
     Reverification::Process.statistics_of_last_24_hrs
  end
end
</code></pre>

<p>How can I stub the <code>bounce_rate</code> and then the <code>complaint_rate</code>. I've done some searching around and came to the conclusion that there isn't a way to stub variables. I also looked at this link <a href="http://gofreerange.com/mocha/docs/method_list.html" rel="nofollow">List of Mocha Methods</a>Which confirms my findings.</p>

<p>Is there a way I can just write a test like this:</p>

<pre><code> it 'should raise SimpleEmailServieLimitError if bounce rate is above 5%' do
  stubs(:bounce_rate).returns(true)
  assert_raise Reverification::SimpleEmailServiceLimitError do
     Reverification::Process.statistics_of_last_24_hrs
  end
end
</code></pre>

<p>Or do I have to stub every method call in this method so that the test will look something like this:</p>

<pre><code>it 'should raise SimpleEmailServieLimitError if bounce rate is above 5%' do
  sent_last_24_hrs = 20
  over_bounce_limit = MOCK::AWS::SimpleEmailService.over_bounce_limit
  AWS::SimpleEmailService.any_instance.stubs(:statistics).returns(stub(find_all: over_bounce_limit))
  AWS::SimpleEmailService.any_instance.stubs(:quotas).returns(stub(sent_last_24_hours: sent_last_24_hrs))
  etc. etc. etc...........
  assert_raise Reverification::SimpleEmailServiceLimitError do
     Reverification::Process.statistics_of_last_24_hrs
  end
end
</code></pre>

<p>Is there an easier way to do this?</p>