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