Skip to content

Commit f246a2e

Browse files
committed
Split shared context
1 parent 16c8169 commit f246a2e

File tree

3 files changed

+31
-20
lines changed

3 files changed

+31
-20
lines changed

spec/lib/statistics/aggregation_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
require 'statistics'
33

44
RSpec.describe Statistics::Aggregation do
5-
include_context 'Use stubs for Faraday'
5+
include_context 'Use stubs for Connpass'
6+
include_context 'Use stubs for Doorkeeper'
67

78
before(:all) do
89
Dojo.delete_all

spec/lib/statistics/client_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
require 'statistics'
33

44
RSpec.describe Statistics::Client do
5-
include_context 'Use stubs for Faraday'
6-
75
context 'Connpass' do
6+
include_context 'Use stubs for Connpass'
7+
88
describe '#search' do
99
subject { Statistics::Client::Connpass.new.search(keyword: 'coderdojo') }
1010

@@ -32,6 +32,8 @@
3232
end
3333

3434
context 'Doorkeeper' do
35+
include_context 'Use stubs for Doorkeeper'
36+
3537
describe '#search' do
3638
subject { Statistics::Client::Doorkeeper.new.search(keyword: 'coderdojo') }
3739

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,4 @@
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-
1+
RSpec.shared_context 'Use stub connection of Faraday' do
182
let(:stub_connection) do
193
Faraday.new do |f|
204
f.response :json, :content_type => /\bjson$/
@@ -33,3 +17,27 @@
3317
allow_any_instance_of(Statistics::Client).to receive(:connection_for).and_return(stub_connection)
3418
end
3519
end
20+
21+
RSpec.shared_context 'Use stubs for Connpass' do
22+
include_context 'Use stub connection of Faraday'
23+
24+
let(:connpass_response) do
25+
[
26+
200,
27+
{ 'Content-Type' => 'application/json' },
28+
'{"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}'
29+
]
30+
end
31+
end
32+
33+
RSpec.shared_context 'Use stubs for Doorkeeper' do
34+
include_context 'Use stub connection of Faraday'
35+
36+
let(:doorkeeper_response) do
37+
[
38+
200,
39+
{ 'Content-Type' => 'application/json' },
40+
'[{"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}}]'
41+
]
42+
end
43+
end

0 commit comments

Comments
 (0)