title: Trying to test my randomiser in rspec by passing specific numbers to it
body: <p>I am currently trying to create a test for the below code. I wrote the test first and then wrote the code and realised my test is not doing what I want it to do.</p>
  <pre><code>class Weather
  
    def initialize
      @weather = 'sunny'
    end
  
    def weather_randomiser
      case rand(1..10)
      when 1..8 then @weather = 'sunny'
      when 9..10 then @weather = 'stormy'
      end
    end
  
    def stormy?
      weather_randomiser
      @weather == 'stormy'
    end
  end
  </code></pre>
  <p>My test is as follows:</p>
  <pre><code>require 'weather.rb'
  
  describe Weather do
    it 'randomises weather and sets the weather to the randomised result' do
      weather = Weather.new
      allow(weather).to receive(:weather_randomiser).and_return(9)
      expect(weather).to be_stormy
      allow(weather).to receive(:weather_randomiser).and_return(2)
      expect(weather).to_not be_stormy
    end
  end
  </code></pre>
  <p>Can you please explain how I go about testing the weather_randomiser and stormy? methods similar to this/ is it possible with my code.</p>
  <p>Further could you explain how you got to where you did as I would like to understand not just have an answer.</p>
  <p>Thank you very much in advance :)</p>