meetupinator 0.4 → 0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,78 @@
1
+ require 'spec_helper'
2
+ require 'vcr_setup'
3
+ require 'meetupinator/meetup_api'
4
+
5
+ describe Meetupinator::MeetupAPI do
6
+ let(:group_id) { 980_007_2 }
7
+
8
+ describe '#new' do
9
+ context 'when there is no Meetup API key in the environment' do
10
+ before { ENV['MEETUP_API_KEY'] = nil }
11
+
12
+ it 'raises a no API key error if no API key is explicitly given' do
13
+ expect { subject }.to raise_exception('no MEETUP_API_KEY provided')
14
+ end
15
+
16
+ it 'uses the API key given in the constructor' do
17
+ key = 'My super-secret API key'
18
+ subject = Meetupinator::MeetupAPI.new key
19
+ expect(subject.api_key).to eq(key)
20
+ end
21
+ end
22
+
23
+ context 'when there is a Meetup API key in the environment' do
24
+ let(:env_api_key) { '1234' }
25
+
26
+ before { ENV['MEETUP_API_KEY'] = env_api_key }
27
+
28
+ it 'uses the API given in the env if no API key is explicitly given' do
29
+ expect(subject.api_key).to eq(env_api_key)
30
+ end
31
+
32
+ it 'uses the API key given in the constructor if one is given' do
33
+ key = 'My super-secret API key'
34
+ subject = Meetupinator::MeetupAPI.new key
35
+ expect(subject.api_key).to eq(key)
36
+ end
37
+ end
38
+ end
39
+
40
+ describe '#get_meetup_id' do
41
+ let(:group_url_name) { 'Ruby-On-Rails-Oceania-Melbourne' }
42
+
43
+ it 'returns the id of the meetup' do
44
+ VCR.use_cassette('groups') do
45
+ expect(subject.get_meetup_id(group_url_name)).to eq(group_id)
46
+ end
47
+ end
48
+ end
49
+
50
+ describe '#get_upcoming_events' do
51
+ context 'single group' do
52
+ let(:expected_number_of_events) { 6 }
53
+
54
+ it 'returns all the upcoming events' do
55
+ VCR.use_cassette('events_single_group') do
56
+ expect(subject.get_upcoming_events([group_id], nil).size).to eq(expected_number_of_events)
57
+ end
58
+ end
59
+
60
+ it 'returns all the upcoming events for the next week' do
61
+ VCR.use_cassette('events_next_week') do
62
+ expect(subject.get_upcoming_events([group_id], true).size).to eq(1)
63
+ end
64
+ end
65
+ end
66
+
67
+ context 'multiple groups' do
68
+ let(:meetup_ids) { [group_id, 183_050_22] }
69
+ let(:expected_number_of_events) { 73 }
70
+
71
+ it 'returns all the upcoming events' do
72
+ VCR.use_cassette('events_multiple_groups') do
73
+ expect(subject.get_upcoming_events([meetup_ids], nil).size).to eq(expected_number_of_events)
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,32 @@
1
+ # From http://stackoverflow.com/a/20583518/1668119
2
+ # modified to work with RSpec 3.0
3
+ RSpec::Matchers.define :match_stdout do |check|
4
+ @capture = nil
5
+
6
+ match do |block|
7
+ begin
8
+ stdout_saved = $stdout
9
+ $stdout = StringIO.new
10
+ block.call
11
+ ensure
12
+ @capture = $stdout
13
+ $stdout = stdout_saved
14
+ end
15
+
16
+ @capture.string.match check
17
+ end
18
+
19
+ failure_message do
20
+ "expected to #{description}"
21
+ end
22
+ failure_message_when_negated do
23
+ "expected not to #{description}"
24
+ end
25
+ description do
26
+ "match [#{check}] on stdout [#{@capture.string}]"
27
+ end
28
+
29
+ def supports_block_expectations?
30
+ true
31
+ end
32
+ end