Created
November 4, 2013 22:19
-
-
Save bf4/7310171 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/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 |
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
feature 'External request' do | |
scenario 'GitHub service failure' do | |
FakeGithub.simulate_error! | |
uri = URI('https://api.github.com/repos/thoughtbot/factory_girl/contributors') | |
response = JSON.load(Net::HTTP.get(uri)) | |
# some assertions | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment