I’ve been digging into Ruby lately and am working on throwing something together to put to use what I’m learning.
I’ve got a Sinatra app that outputs a random quote. I’d like to put some RSpec testing around this since that seems to be the right path to take.
For testing the class, I did something like this:
it "prints a random line" do
QuoteFile.any_instance.stub(:random).and_return(@quote.to_s)
@quotefile.random.should == "Sample quote"
end
So I’ve taken this and put it into a basic Sinatra app. My RSpec file looks like this:
describe 'Quote App' do
include Rack::Test::Methods
def app
Sinatra::Application
end
it "prints random quote" do
get '/'
????
end
end
My question is: How do I stub out the random aspect in the “get ‘/’?
Thanks guys!
Use
in your Sinatra test and check for the output. Here’s an example.