require 'sinatra'
get '/' do
hello
end
helpers do
def hello
'Hello World!'
end
end
if defined?(RSpec)
require 'rack/test'
RSpec.configure { |c| c.include Rack::Test::Methods }
describe Sinatra::Application do
def app(); @app ||= Sinatra::Application.new end
context 'hello をスタブしてないとき、' do
it 'Hello World! を返す。' do
get '/'
expect(last_response.body).to eq('Hello World!')
end
end
context 'hello をスタブしてるとき、' do
before { allow(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