Skip to content

Commit 0024192

Browse files
committed
Shared context for API stubs
1 parent ec719e1 commit 0024192

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

spec/rails_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# directory. Alternatively, in the individual `*_spec.rb` files, manually
2121
# require only the support files necessary.
2222
#
23-
# Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
23+
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
2424

2525
# Checks for pending migration and applies them before tests are run.
2626
# If you are not using ActiveRecord, you can remove this line.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
RSpec.shared_context 'Use stubs for Faraday' do
2+
let(:connpass_response) do
3+
[
4+
200,
5+
{ 'Content-Type' => 'application/json' },
6+
'{"results_returned": 1, "events": [{"event_url": "https://coderdojo-okutama.connpass.com/event/12345/", "event_type": "participation", "owner_nickname": "nalabjp", "series": {"url": "https://coderdojo-okutama.connpass.com/", "id": 9876, "title": "CoderDojo series"}, "updated_at": "2017-04-29T14:59:30+09:00", "lat": "35.801763000000", "started_at": "2017-05-07T10:00:00+09:00", "hash_tag": "CoderDojo", "title": "CoderDojo title", "event_id": 12345, "lon": "139.087656000000", "waiting": 2, "limit": 10, "owner_id": 2525, "owner_display_name": "nalabjp", "description": "CoderDojo description", "address": "Okutama-cho Tokyo", "catch": "CoderDojo catch", "accepted": 10, "ended_at": "2017-05-07T12:00:00+09:00", "place": "Tokyo"}], "results_start": 200, "results_available": 518}'
7+
]
8+
end
9+
10+
let(:doorkeeper_response) do
11+
[
12+
200,
13+
{ 'Content-Type' => 'application/json' },
14+
'[{"event":{"title":"CoderDojo title","id":1234,"starts_at":"2017-05-28T01:00:00.000Z","ends_at":"2017-05-28T04:00:00.000Z","venue_name":"奥多摩町","address":"奥多摩町","lat":"35.801763000000","long":"139.087656000000","ticket_limit":30,"published_at":"2017-04-22T03:43:04.000Z","updated_at":"2017-05-10T11:31:21.810Z","group":5555,"banner":null,"description":"CoderDojo description","public_url":"https://coderdojo-okutama.doorkeeper.jp/events/8888","participants":12,"waitlisted":0}}]'
15+
]
16+
end
17+
18+
let(:stub_connection) do
19+
Faraday.new do |f|
20+
f.response :json, :content_type => /\bjson$/
21+
f.adapter :test, Faraday::Adapter::Test::Stubs.new do |stub|
22+
# connpass
23+
stub.get('/event/') { connpass_response }
24+
25+
# doorkeeper
26+
stub.get('/events') { doorkeeper_response }
27+
stub.get('/groups/5555/events') { doorkeeper_response }
28+
end
29+
end
30+
end
31+
32+
before do
33+
allow_any_instance_of(Statistics::Client).to receive(:connection_for).and_return(stub_connection)
34+
end
35+
end

0 commit comments

Comments
 (0)