Created
December 6, 2013 03:48
-
-
Save yuanying/7818242 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sinatra' | |
get '/' do | |
hello | |
end | |
helpers do | |
def hello | |
'Hello World!' | |
end | |
end | |
if defined?(RSpec) | |
require 'rack/test' | |
RSpec.configure do |c| | |
c.include Rack::Test::Methods | |
c.before(:each) do | |
@current_app = app.helpers.dup | |
expect(app.helpers).to receive(:dup).and_return(@current_app) | |
end | |
end | |
describe Sinatra::Application do | |
def app(); @app ||= Sinatra::Application.new end | |
def current_app(); @current_app end | |
context 'hello をスタブしてないとき、' do | |
it 'Hello World! を返す。' do | |
get '/' | |
expect(last_response.body).to eq('Hello World!') | |
end | |
end | |
context 'hello をスタブしてるとき、' do | |
before { allow(current_app).to receive(:hello).and_return('Hello Stub!') } | |
it 'Hello Stub! を返す。' do | |
get '/' | |
expect(last_response.body).to eq('Hello Stub!') | |
end | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment