pew_pew 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,53 +1,57 @@
1
- require 'spec_helper'
2
-
3
- describe PewPew::Resources::Messages, :resource, :domain do
4
- let(:resource) { described_class.new(client) }
5
-
6
- context '#send_email' do
7
- let(:params) {
8
- {
9
- to: 'pewpew@devoh.com',
10
- from: 'pewpew@devoh.com',
11
- subject: 'Test',
12
- text: 'This is a test message.'
13
- }
14
- }
15
-
16
- let(:file) { Faraday::UploadIO.new('spec/fixtures/image.png', 'image/png') }
17
-
18
- subject { resource.send_email(params) }
19
-
20
- specify { should be_success }
21
-
22
- context 'with an attachment' do
23
- before do
24
- params.merge!(attachment: file)
1
+ module PewPew
2
+ module Resources
3
+ RSpec.describe Messages, :resource, :domain do
4
+ let(:resource) { described_class.new(client) }
5
+
6
+ context '#send_email' do
7
+ let(:params) {
8
+ {
9
+ to: 'pewpew@devoh.com',
10
+ from: 'pewpew@devoh.com',
11
+ subject: 'Test',
12
+ text: 'This is a test message.'
13
+ }
14
+ }
15
+
16
+ let(:file) {
17
+ Faraday::UploadIO.new('spec/fixtures/image.png', 'image/png')
18
+ }
19
+
20
+ subject { resource.send_email(params) }
21
+
22
+ specify { should be_success }
23
+
24
+ context 'with an attachment' do
25
+ before do
26
+ params.merge!(attachment: file)
27
+ end
28
+
29
+ specify { should be_success }
30
+ end
31
+
32
+ context 'with an inline attachment' do
33
+ before do
34
+ params.merge!(
35
+ html: "#{params[:text]} <img src=\"cid:image.png\">",
36
+ inline: file
37
+ )
38
+ end
39
+
40
+ specify { should be_success }
41
+ end
25
42
  end
26
43
 
27
- specify { should be_success }
28
- end
44
+ context '#send_mime' do
45
+ let(:message) do
46
+ Faraday::UploadIO.new('spec/fixtures/mime.eml', 'message/rfc822')
47
+ end
29
48
 
30
- context 'with an inline attachment' do
31
- before do
32
- params.merge!(
33
- html: "#{params[:text]} <img src=\"cid:image.png\">",
34
- inline: file
35
- )
36
- end
49
+ let(:params) { { to: 'pewpew@devoh.com', message: message } }
37
50
 
38
- specify { should be_success }
39
- end
40
- end
51
+ subject { resource.send_mime(params) }
41
52
 
42
- context '#send_mime' do
43
- let(:message) do
44
- Faraday::UploadIO.new('spec/fixtures/mime.eml', 'message/rfc822')
53
+ specify { should be_success }
54
+ end
45
55
  end
46
-
47
- let(:params) { { to: 'pewpew@devoh.com', message: message } }
48
-
49
- subject { resource.send_mime(params) }
50
-
51
- specify { should be_success }
52
56
  end
53
57
  end
@@ -1,135 +1,137 @@
1
- require 'spec_helper'
1
+ module PewPew
2
+ module Resources
3
+ RSpec.describe Routes, :resource do
4
+ let(:resource) { described_class.new(client) }
2
5
 
3
- describe PewPew::Resources::Routes, :resource do
4
- let(:resource) { described_class.new(client) }
6
+ context '#all' do
7
+ let(:response) { resource.all }
5
8
 
6
- context '#all' do
7
- let(:response) { resource.all }
9
+ subject { response }
8
10
 
9
- subject { response }
11
+ specify { should be_success }
10
12
 
11
- specify { should be_success }
13
+ its(:status) { should == 200 }
14
+ its(:total_count) { should == 1 }
12
15
 
13
- its(:status) { should == 200 }
14
- its(:total_count) { should == 1 }
16
+ context 'item' do
17
+ subject { response.items.first }
15
18
 
16
- context 'item' do
17
- subject { response.items.first }
18
-
19
- its(:id) { should == '4fc850083533542f7704bc05' }
20
- its(:priority) { should == 1 }
21
- its(:description) { should == 'Forward Gmail' }
22
- its(:expression) { should == "match_recipient('.*@gmail.com')" }
23
- its(:actions) { should == ["forward('gmail@example.com')"] }
24
- its(:created_at) { should == 'Fri, 01 Jun 2012 05:15:52 GMT' }
25
- end
26
- end
27
-
28
- context '#find' do
29
- let(:response) { resource.find('4fc850083533542f7704bc05') }
19
+ its(:id) { should == '4fc850083533542f7704bc05' }
20
+ its(:priority) { should == 1 }
21
+ its(:description) { should == 'Forward Gmail' }
22
+ its(:expression) { should == "match_recipient('.*@gmail.com')" }
23
+ its(:actions) { should == ["forward('gmail@example.com')"] }
24
+ its(:created_at) { should == 'Fri, 01 Jun 2012 05:15:52 GMT' }
25
+ end
26
+ end
30
27
 
31
- subject { response }
28
+ context '#find' do
29
+ let(:response) { resource.find('4fc850083533542f7704bc05') }
32
30
 
33
- specify { should be_success }
31
+ subject { response }
34
32
 
35
- its(:status) { should == 200 }
33
+ specify { should be_success }
36
34
 
37
- context 'route' do
38
- subject { response.route }
35
+ its(:status) { should == 200 }
39
36
 
40
- its(:id) { should == '4fc850083533542f7704bc05' }
41
- its(:priority) { should == 1 }
42
- its(:description) { should == 'Forward Gmail' }
43
- its(:expression) { should == "match_recipient('.*@gmail.com')" }
44
- its(:actions) { should == ["forward('gmail@example.com')"] }
45
- its(:created_at) { should == 'Fri, 01 Jun 2012 05:15:52 GMT' }
46
- end
47
- end
37
+ context 'route' do
38
+ subject { response.route }
48
39
 
49
- context '#create' do
50
- let(:params) do
51
- {
52
- priority: 1,
53
- description: 'Forward Gmail',
54
- expression: "match_recipient('.*@gmail.com')",
55
- action: "forward('gmail@example.com')"
56
- }
57
- end
40
+ its(:id) { should == '4fc850083533542f7704bc05' }
41
+ its(:priority) { should == 1 }
42
+ its(:description) { should == 'Forward Gmail' }
43
+ its(:expression) { should == "match_recipient('.*@gmail.com')" }
44
+ its(:actions) { should == ["forward('gmail@example.com')"] }
45
+ its(:created_at) { should == 'Fri, 01 Jun 2012 05:15:52 GMT' }
46
+ end
47
+ end
58
48
 
59
- let(:response) { resource.create(params) }
49
+ context '#create' do
50
+ let(:params) do
51
+ {
52
+ priority: 1,
53
+ description: 'Forward Gmail',
54
+ expression: "match_recipient('.*@gmail.com')",
55
+ action: "forward('gmail@example.com')"
56
+ }
57
+ end
58
+
59
+ let(:response) { resource.create(params) }
60
+
61
+ subject { response }
62
+
63
+ context 'with a single action' do
64
+ specify { should be_success }
65
+
66
+ its(:status) { should == 200 }
67
+ its(:message) { should == 'Route has been created' }
68
+
69
+ context 'route' do
70
+ subject { response.route }
71
+
72
+ its(:id) { should == '4fc850083533542f7704bc05' }
73
+ its(:priority) { should == params[:priority] }
74
+ its(:description) { should == params[:description] }
75
+ its(:expression) { should == params[:expression] }
76
+ its(:actions) { should == [params[:action]] }
77
+ its(:created_at) { should == 'Fri, 01 Jun 2012 05:15:52 GMT' }
78
+ end
79
+ end
80
+
81
+ context 'with multiple actions' do
82
+ before do
83
+ params.merge!(action: [params[:action], 'stop()'])
84
+ end
85
+
86
+ specify { should be_success }
87
+
88
+ its(:status) { should == 200 }
89
+ its(:message) { should == 'Route has been created' }
90
+
91
+ context 'route' do
92
+ subject { response.route }
93
+
94
+ its(:id) { should == '4fc854bd9d12a36fc504d4b3' }
95
+ its(:priority) { should == params[:priority] }
96
+ its(:description) { should == params[:description] }
97
+ its(:expression) { should == params[:expression] }
98
+ its(:actions) { should == params[:action] }
99
+ its(:created_at) { should == 'Fri, 01 Jun 2012 05:35:57 GMT' }
100
+ end
101
+ end
102
+ end
60
103
 
61
- subject { response }
104
+ context '#update' do
105
+ let(:params) { { priority: 2 } }
106
+ let(:response) { resource.update('4fc850083533542f7704bc05', params) }
62
107
 
63
- context 'with a single action' do
64
- specify { should be_success }
108
+ subject { response }
65
109
 
66
- its(:status) { should == 200 }
67
- its(:message) { should == 'Route has been created' }
110
+ specify { should be_success }
68
111
 
69
- context 'route' do
70
- subject { response.route }
112
+ its(:status) { should == 200 }
113
+ its(:message) { should == 'Route has been updated' }
71
114
 
72
115
  its(:id) { should == '4fc850083533542f7704bc05' }
73
116
  its(:priority) { should == params[:priority] }
74
- its(:description) { should == params[:description] }
75
- its(:expression) { should == params[:expression] }
76
- its(:actions) { should == [params[:action]] }
117
+ its(:description) { should == 'Forward Gmail' }
118
+ its(:expression) { should == "match_recipient('.*@gmail.com')" }
119
+ its(:actions) { should == ["forward('gmail@example.com')"] }
77
120
  its(:created_at) { should == 'Fri, 01 Jun 2012 05:15:52 GMT' }
78
121
  end
79
- end
80
122
 
81
- context 'with multiple actions' do
82
- before do
83
- params.merge!(action: [params[:action], 'stop()'])
84
- end
123
+ context '#remove' do
124
+ let(:response) { resource.remove('4fc854bd9d12a36fc504d4b3') }
85
125
 
86
- specify { should be_success }
126
+ subject { response }
87
127
 
88
- its(:status) { should == 200 }
89
- its(:message) { should == 'Route has been created' }
128
+ specify { should be_success }
90
129
 
91
- context 'route' do
92
- subject { response.route }
130
+ its(:status) { should == 200 }
131
+ its(:message) { should == 'Route has been deleted' }
93
132
 
94
133
  its(:id) { should == '4fc854bd9d12a36fc504d4b3' }
95
- its(:priority) { should == params[:priority] }
96
- its(:description) { should == params[:description] }
97
- its(:expression) { should == params[:expression] }
98
- its(:actions) { should == params[:action] }
99
- its(:created_at) { should == 'Fri, 01 Jun 2012 05:35:57 GMT' }
100
134
  end
101
135
  end
102
136
  end
103
-
104
- context '#update' do
105
- let(:params) { { priority: 2 } }
106
- let(:response) { resource.update('4fc850083533542f7704bc05', params) }
107
-
108
- subject { response }
109
-
110
- specify { should be_success }
111
-
112
- its(:status) { should == 200 }
113
- its(:message) { should == 'Route has been updated' }
114
-
115
- its(:id) { should == '4fc850083533542f7704bc05' }
116
- its(:priority) { should == params[:priority] }
117
- its(:description) { should == 'Forward Gmail' }
118
- its(:expression) { should == "match_recipient('.*@gmail.com')" }
119
- its(:actions) { should == ["forward('gmail@example.com')"] }
120
- its(:created_at) { should == 'Fri, 01 Jun 2012 05:15:52 GMT' }
121
- end
122
-
123
- context '#remove' do
124
- let(:response) { resource.remove('4fc854bd9d12a36fc504d4b3') }
125
-
126
- subject { response }
127
-
128
- specify { should be_success }
129
-
130
- its(:status) { should == 200 }
131
- its(:message) { should == 'Route has been deleted' }
132
-
133
- its(:id) { should == '4fc854bd9d12a36fc504d4b3' }
134
- end
135
137
  end
@@ -1,26 +1,28 @@
1
- require 'spec_helper'
1
+ module PewPew
2
+ module Resources
3
+ RSpec.describe Stats, :resource, :domain do
4
+ let(:resource) { described_class.new(client) }
2
5
 
3
- describe PewPew::Resources::Stats, :resource, :domain do
4
- let(:resource) { described_class.new(client) }
6
+ context '#all' do
7
+ let(:response) { resource.all }
5
8
 
6
- context '#all' do
7
- let(:response) { resource.all }
9
+ subject { response }
8
10
 
9
- subject { response }
11
+ specify { should be_success }
10
12
 
11
- specify { should be_success }
13
+ its(:status) { should == 200 }
14
+ its(:total_count) { should == 10 }
12
15
 
13
- its(:status) { should == 200 }
14
- its(:total_count) { should == 10 }
16
+ context 'item' do
17
+ subject { response.items.first }
15
18
 
16
- context 'item' do
17
- subject { response.items.first }
18
-
19
- its(:created_at) { should == 'Fri, 01 Jun 2012 00:00:00 GMT' }
20
- its(:event) { should == 'sent' }
21
- its(:id) { should == '4fc837558393c1618263d76c' }
22
- its(:tags) { should == {} }
23
- its(:total_count) { should == 11 }
19
+ its(:created_at) { should == 'Fri, 01 Jun 2012 00:00:00 GMT' }
20
+ its(:event) { should == 'sent' }
21
+ its(:id) { should == '4fc837558393c1618263d76c' }
22
+ its(:tags) { should == {} }
23
+ its(:total_count) { should == 11 }
24
+ end
25
+ end
24
26
  end
25
27
  end
26
28
  end
@@ -1,99 +1,105 @@
1
- require 'spec_helper'
1
+ module PewPew
2
+ module Resources
3
+ RSpec.describe Unsubscribes, :resource, :domain do
4
+ let(:resource) { described_class.new(client) }
2
5
 
3
- describe PewPew::Resources::Unsubscribes, :resource, :domain do
4
- let(:resource) { described_class.new(client) }
6
+ context '#all' do
7
+ let(:response) { resource.all }
5
8
 
6
- context '#all' do
7
- let(:response) { resource.all }
9
+ subject { response }
8
10
 
9
- subject { response }
11
+ specify { should be_success }
10
12
 
11
- specify { should be_success }
13
+ its(:status) { should == 200 }
14
+ its(:total_count) { should == 2 }
12
15
 
13
- its(:status) { should == 200 }
14
- its(:total_count) { should == 2 }
16
+ context 'item' do
17
+ subject { response.items.first }
15
18
 
16
- context 'item' do
17
- subject { response.items.first }
19
+ its(:address) { should == 'test@example.com' }
20
+ its(:created_at) { should == 'Sat, 02 Jun 2012 02:54:37 GMT' }
21
+ its(:id) { should == '4fc9806d8393c1618264c360' }
22
+ its(:tag) { should == '*' }
23
+ end
24
+ end
18
25
 
19
- its(:address) { should == 'test@example.com' }
20
- its(:created_at) { should == 'Sat, 02 Jun 2012 02:54:37 GMT' }
21
- its(:id) { should == '4fc9806d8393c1618264c360' }
22
- its(:tag) { should == '*' }
23
- end
24
- end
26
+ context '#find' do
27
+ let(:response) { resource.find('test@example.com') }
25
28
 
26
- context '#find' do
27
- let(:response) { resource.find('test@example.com') }
29
+ subject { response }
28
30
 
29
- subject { response }
31
+ specify { should be_success }
30
32
 
31
- specify { should be_success }
33
+ its(:status) { should == 200 }
34
+ its(:total_count) { should == 2 }
32
35
 
33
- its(:status) { should == 200 }
34
- its(:total_count) { should == 2 }
36
+ context 'unsubscribe' do
37
+ subject { response.items.first }
35
38
 
36
- context 'unsubscribe' do
37
- subject { response.items.first }
39
+ its(:address) { should == 'test@example.com' }
40
+ its(:created_at) { should == 'Sat, 02 Jun 2012 02:54:37 GMT' }
41
+ its(:id) { should == '4fc9806d8393c1618264c360' }
42
+ its(:tag) { should == '*' }
43
+ end
44
+ end
38
45
 
39
- its(:address) { should == 'test@example.com' }
40
- its(:created_at) { should == 'Sat, 02 Jun 2012 02:54:37 GMT' }
41
- its(:id) { should == '4fc9806d8393c1618264c360' }
42
- its(:tag) { should == '*' }
43
- end
44
- end
46
+ context '#create' do
47
+ let(:response) { resource.create(params) }
45
48
 
46
- context '#create' do
47
- let(:response) { resource.create(params) }
49
+ subject { response }
48
50
 
49
- subject { response }
51
+ context 'with a tag' do
52
+ let(:params) { { address: 'test@example.com', tag: 'newsletter' } }
50
53
 
51
- context 'with a tag' do
52
- let(:params) { { address: 'test@example.com', tag: 'newsletter' } }
54
+ specify { should be_success }
53
55
 
54
- specify { should be_success }
56
+ its(:status) { should == 200 }
57
+ its(:message) {
58
+ should == 'Address has been added to the unsubscribes table'
59
+ }
55
60
 
56
- its(:status) { should == 200 }
57
- its(:message) { should == 'Address has been added to the unsubscribes table' }
61
+ its(:address) { should == 'test@example.com' }
62
+ end
58
63
 
59
- its(:address) { should == 'test@example.com' }
60
- end
64
+ context 'without a tag' do
65
+ let(:params) { { address: 'test@example.com' } }
61
66
 
62
- context 'without a tag' do
63
- let(:params) { { address: 'test@example.com' } }
67
+ specify { should be_success }
64
68
 
65
- specify { should be_success }
69
+ its(:status) { should == 200 }
70
+ its(:message) {
71
+ should == 'Address has been added to the unsubscribes table'
72
+ }
66
73
 
67
- its(:status) { should == 200 }
68
- its(:message) { should == 'Address has been added to the unsubscribes table' }
74
+ its(:address) { should == 'test@example.com' }
75
+ end
76
+ end
69
77
 
70
- its(:address) { should == 'test@example.com' }
71
- end
72
- end
78
+ context '#remove' do
79
+ subject { response }
73
80
 
74
- context '#remove' do
75
- subject { response }
81
+ context 'with an address' do
82
+ let(:response) { resource.remove('test@example.com') }
76
83
 
77
- context 'with an address' do
78
- let(:response) { resource.remove('test@example.com') }
84
+ specify { should be_success }
79
85
 
80
- specify { should be_success }
86
+ its(:status) { should == 200 }
87
+ its(:message) { should == 'Unsubscribe event has been removed' }
81
88
 
82
- its(:status) { should == 200 }
83
- its(:message) { should == 'Unsubscribe event has been removed' }
84
-
85
- its(:address) { should == 'test@example.com' }
86
- end
89
+ its(:address) { should == 'test@example.com' }
90
+ end
87
91
 
88
- context 'with an unsubscribe event ID' do
89
- let(:response) { resource.remove('4fc9806d8393c1618264c360') }
92
+ context 'with an unsubscribe event ID' do
93
+ let(:response) { resource.remove('4fc9806d8393c1618264c360') }
90
94
 
91
- specify { should be_success }
95
+ specify { should be_success }
92
96
 
93
- its(:status) { should == 200 }
94
- its(:message) { should == 'Unsubscribe event has been removed' }
97
+ its(:status) { should == 200 }
98
+ its(:message) { should == 'Unsubscribe event has been removed' }
95
99
 
96
- its(:address) { should == '4fc9806d8393c1618264c360' }
100
+ its(:address) { should == '4fc9806d8393c1618264c360' }
101
+ end
102
+ end
97
103
  end
98
104
  end
99
105
  end
@@ -1,21 +1,33 @@
1
- require 'spec_helper'
1
+ module PewPew
2
+ RSpec.describe Response do
3
+ it { should be_a Hashie::Mash }
2
4
 
3
- describe PewPew::Response do
4
- it { should be_a(Hashie::Mash) }
5
+ context '#count' do
6
+ subject(:response) { described_class.new(count: 2) }
5
7
 
6
- context '#count' do
7
- it 'returns the value of the count attribute' do
8
- described_class.new(count: 2).count.should == 2
8
+ it 'returns the value of the count attribute' do
9
+ expect(response.count).to eq 2
10
+ end
9
11
  end
10
- end
11
12
 
12
- context '#success?' do
13
- it 'returns true if the status is 200' do
14
- described_class.new(status: 200).should be_success
15
- end
13
+ context '#success?' do
14
+ subject(:response) { described_class.new(status: status) }
15
+
16
+ context 'when the status is 200' do
17
+ let(:status) { 200 }
18
+
19
+ it 'returns true' do
20
+ expect(response).to be_success
21
+ end
22
+ end
23
+
24
+ context 'when the status is 400' do
25
+ let(:status) { 400 }
16
26
 
17
- it 'returns false if the status is 400' do
18
- described_class.new(status: 400).should_not be_success
27
+ it 'returns false' do
28
+ expect(response).to_not be_success
29
+ end
30
+ end
19
31
  end
20
32
  end
21
33
  end
data/spec/pew_pew_spec.rb CHANGED
@@ -1,13 +1,12 @@
1
- require 'spec_helper'
2
-
3
- describe PewPew do
1
+ RSpec.describe PewPew do
4
2
  [
5
3
  Relax::Client.instance_methods(false),
6
4
  PewPew::Client.instance_methods(false)
7
5
  ].flatten.each do |method|
8
6
  it "delegates .#{method} to .client" do
9
- described_class.send(:client).should_receive(method)
10
- described_class.send(method)
7
+ expect(described_class.send(:client)).to receive(method)
8
+
9
+ described_class.send method
11
10
  end
12
11
  end
13
12
  end
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'pew_pew'
2
+ require 'rspec/its'
2
3
 
3
4
  # These defaults are only for use when developing this client library. Please
4
5
  # do not use them in your own applications. Sign up for your own account here:
@@ -7,7 +8,6 @@ ENV['MAILGUN_API_KEY'] ||= 'key-02n9f3ijl9sm9u97-8p7r-d7-15q-ui1'
7
8
  ENV['MAILGUN_DOMAIN'] ||= 'pewpew.mailgun.org'
8
9
 
9
10
  RSpec.configure do |config|
10
- config.treat_symbols_as_metadata_keys_with_true_values = true
11
11
  config.run_all_when_everything_filtered = true
12
12
  config.filter_run :focus
13
13
  end
@@ -1,4 +1,6 @@
1
- shared_context 'API request', :resource do
1
+ require 'cgi'
2
+
3
+ RSpec.shared_context 'API request', :resource do
2
4
  let(:cassette_name) { described_class.name.split(/::/).last.downcase }
3
5
  let(:client) { PewPew::Client.new }
4
6
 
@@ -14,7 +16,7 @@ shared_context 'API request', :resource do
14
16
 
15
17
  vcr_options = {
16
18
  record: (ENV['VCR_RECORD'] || :none).to_sym,
17
- match_requests_on: [:method, :uri, :headers, :body],
19
+ match_requests_on: [:method, :uri, :multipart_headers, :multipart_body],
18
20
  erb: {
19
21
  basic_auth: basic_auth,
20
22
  domain: client.config.domain,
@@ -22,6 +24,6 @@ shared_context 'API request', :resource do
22
24
  }
23
25
  }
24
26
 
25
- VCR.use_cassette(cassette_name, vcr_options, &example)
27
+ VCR.use_cassette cassette_name, vcr_options, &example
26
28
  end
27
29
  end