Skip to content

Instantly share code, notes, and snippets.

@timuruski
Created August 12, 2011 03:48
Show Gist options
  • Select an option

  • Save timuruski/1141404 to your computer and use it in GitHub Desktop.

Select an option

Save timuruski/1141404 to your computer and use it in GitHub Desktop.
Sinatra sings the helper stubbing blues
require 'sinatra/base'
require 'rack/test'
class MyApp < Sinatra::Base
disable :show_exceptions
helpers do
def msg
"hello world"
end
end
get '/' do
msg
end
end
describe "sinatra helpers" do
include Rack::Test::Methods
def app; MyApp.new end
it "fails to stub" do
app.stub(:msg) { 'goodbye world' }
get "/"
last_response.body.should == 'goodbye world'
end
it "fails to stub miserably" do
MyApp.any_instance.stub(:msg).and_return { 'goodbye world' }
get "/"
last_response.body.should == 'goodbye world'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment