Grab pizza while we're waiting to kick things off
First make sure all external calls are intercepted
# spec/spec_helper.rb require 'webmock/rspec' WebMock.disable_net_connect!(allow_localhost: true)
If small number, you could manually set
config.before(:each) do
stub_request(:get, /api.facebook.com/).
with(headers: {'Accept'=>'*/*'}).
to_return(status: 200, body: "payload", headers: {})
end
end`
Record real API calls as cassettes and playback responses
Use Webmock gem to intercept calls and redirect them to your Fake class
config.before(:each) do
stub_request(:any, /api.athenahealth.com/).to_rack(FakeAthena)
end
Create your sinatra app
# spec/support/fake_athena.rb require "sinatra/base" require "sinatra/namespace" class FakeAthena < Sinatra::Base register Sinatra::Namespace end
Set up endpoints and fixtures as needed by tests
#spec/support/fake_athena.rb
get "/providers/:provider_id" do
json_response 200, "provider.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
#spec/fixtures/provider.json
[{
"firstname": "Marc",
"specialty": "Family Medicine",
"acceptingnewpatients": "false",
"providertypeid": "MD",
"billable": "true",
"ansinamecode": "Allopathic & Osteopathic Physicians : Family Practice (207Q00000X)",
"lastname": "Feingold",
"providerid": "71",
"ansispecialtycode": "207Q00000X",
"hideinportal": "false",
"entitytype": "Person",
"npi": "1306805015",
"providertype": "MD"
}]
# spec/features/patient_checks_in_for_appointment_spec.rb expect(page).to have_content "Dr. Marc Feingold"
# spec/support/fake_athena.rb
def self.has_updated_patient?
updated_patient
end
put "/patients/:patient_id" do
self.class.updated_patient = true
json_response 200, "update_patient.json"
end
# spec/features/patient_checks_in_for_appointment_spec.rb expect(FakeAthena).to have_updated_patient
# spec/support/fake_athena.rb def self.reset self.updated_patient = false end # spec/rails_helper.rb config.after(:each) do FakeAthena.reset end
"Ask the Group Anything"