require 'sinatra/base' class FakeGitHub < Sinatra::Base def simulate_error! @@simulate_error = true end def reset! @@simulate_error = false end def simulate_error? @@simulate_error end before_do if simulate_error? halt 403, { errors: { first_name: "can't be blank" } }.to_json end end get '/repos/:organization/:project/contributors' do json_response 200, 'contributors.json' end get '/repos/:organization/:project/issues' do json_response 200, 'issues.json' end private def json_response(response_code, file_name) content_type :json status response_code File.open(File.dirname(__FILE__) + '/fixtures/' + file_name, 'rb').read end end