tcr 0.0.5 → 0.1.0
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +2 -0
- data/README.md +6 -9
- data/lib/tcr/recordable_tcp_socket.rb +21 -1
- data/lib/tcr/version.rb +1 -1
- data/spec/fixtures/email_with_image.eml +28 -0
- data/spec/fixtures/mandrill_smtp.json +8 -0
- data/spec/fixtures/multitest-smtp.json +6 -6
- data/spec/fixtures/multitest.json +2 -2
- data/spec/fixtures/smtp-success.json +212 -0
- data/spec/tcr_spec.rb +47 -28
- data/tcr.gemspec +1 -0
- metadata +23 -5
- data/spec/fixtures/google_smtp.json +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 370d8b4720c47b31f8f3241356eb3b973c47670e
|
4
|
+
data.tar.gz: 3c186c24296a576017891360fe0f87c7e77574f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d27e46c2ccf0a2ffe523ff71cf462a66d11605688d9dd2ebe902dbe8a42b224cda2e06c553f8b3ac85a3ddcfb4a203318d4400fb9d87ffded52e35f6e927408
|
7
|
+
data.tar.gz: 25b55961826513bb19715b71c62dc1e8cf4a20d3062f9a113d70d779642a9110e32c6f52268ce7b03a9046c8c6ea179958174b27dbdba2d987dfeff57e379e56
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -2,9 +2,6 @@
|
|
2
2
|
|
3
3
|
[](https://travis-ci.org/robforman/tcr)
|
4
4
|
|
5
|
-
[ ](https://www.codeship.io/projects/53337)
|
6
|
-
|
7
|
-
|
8
5
|
|
9
6
|
|
10
7
|
TCR is a *very* lightweight version of [VCR](https://github.com/vcr/vcr) for TCP sockets.
|
@@ -33,15 +30,15 @@ require 'tcr'
|
|
33
30
|
|
34
31
|
TCR.configure do |c|
|
35
32
|
c.cassette_library_dir = 'fixtures/tcr_cassettes'
|
36
|
-
c.hook_tcp_ports = [
|
33
|
+
c.hook_tcp_ports = [2525]
|
37
34
|
end
|
38
35
|
|
39
36
|
class TCRTest < Test::Unit::TestCase
|
40
37
|
def test_example_dot_com
|
41
|
-
TCR.use_cassette('
|
42
|
-
tcp_socket = TCPSocket.open("
|
38
|
+
TCR.use_cassette('mandrill_smtp') do
|
39
|
+
tcp_socket = TCPSocket.open("smtp.mandrillapp.com", 2525)
|
43
40
|
io = Net::InternetMessageIO.new(tcp_socket)
|
44
|
-
assert_match /220
|
41
|
+
assert_match /220 smtp.mandrillapp.com ESMTP/, io.readline
|
45
42
|
end
|
46
43
|
end
|
47
44
|
end
|
@@ -54,7 +51,7 @@ Run this test once, and TCR will record the tcp interactions to fixtures/tcr_cas
|
|
54
51
|
[
|
55
52
|
[
|
56
53
|
"read",
|
57
|
-
"220
|
54
|
+
"220 smtp.mandrillapp.com ESMTP\r\n"
|
58
55
|
]
|
59
56
|
]
|
60
57
|
]
|
@@ -66,7 +63,7 @@ You can disable TCR hooking TCPSocket ports for a given block via `turned_off`:
|
|
66
63
|
|
67
64
|
```ruby
|
68
65
|
TCR.turned_off do
|
69
|
-
tcp_socket = TCPSocket.open("
|
66
|
+
tcp_socket = TCPSocket.open("smtp.mandrillapp.com", 2525)
|
70
67
|
end
|
71
68
|
```
|
72
69
|
|
@@ -63,6 +63,9 @@ module TCR
|
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
|
+
def setsockopt(*args)
|
67
|
+
end
|
68
|
+
|
66
69
|
private
|
67
70
|
|
68
71
|
def _intercept_socket
|
@@ -92,7 +95,12 @@ module TCR
|
|
92
95
|
end
|
93
96
|
end
|
94
97
|
|
95
|
-
def _read(method, *args
|
98
|
+
def _read(method, *args)
|
99
|
+
blocking = true
|
100
|
+
if args.last.is_a?(::Hash)
|
101
|
+
blocking = args.pop.fetch(:blocking, true)
|
102
|
+
end
|
103
|
+
|
96
104
|
if live
|
97
105
|
data = @socket.__send__(method, *args)
|
98
106
|
recording << ["read", data]
|
@@ -125,6 +133,18 @@ module TCR
|
|
125
133
|
true
|
126
134
|
end
|
127
135
|
|
136
|
+
def sync
|
137
|
+
self
|
138
|
+
end
|
139
|
+
|
140
|
+
def sync=(arg)
|
141
|
+
self
|
142
|
+
end
|
143
|
+
|
144
|
+
def flush
|
145
|
+
self
|
146
|
+
end
|
147
|
+
|
128
148
|
def session
|
129
149
|
self
|
130
150
|
end
|
data/lib/tcr/version.rb
CHANGED
@@ -0,0 +1,28 @@
|
|
1
|
+
From: Braxton Lind <dagmar@macejkovic.org>
|
2
|
+
To: "Rob Forman, Jr." <rob.forman@salesloft.com>
|
3
|
+
Message-ID: <56d6626fdc766_107a53fc0f08602044064d@Robs-MacBook-Pro.local.mail>
|
4
|
+
Subject: Look at this dog
|
5
|
+
Mime-Version: 1.0
|
6
|
+
Content-Type: multipart/related;
|
7
|
+
boundary="--==_mimepart_56d6626fdc766_107a53fc0f0860204405bd";
|
8
|
+
charset=UTF-8
|
9
|
+
Content-Transfer-Encoding: 7bit
|
10
|
+
|
11
|
+
|
12
|
+
----==_mimepart_56d6626fdc766_107a53fc0f0860204405bd
|
13
|
+
Content-Type: text/html;
|
14
|
+
charset=UTF-8
|
15
|
+
Content-Transfer-Encoding: 7bit
|
16
|
+
|
17
|
+
because it's awesome! <img src="cid:56d6626fdc766_107a53fc0f086020440474@Robs-MacBook-Pro.local.mail" style="width: 1px;"><img src="https://test.host/email_trackers/3afe095f-d02a-4bc3-b0fd-21104141893e/open.gif" alt="" width="1" height="1">
|
18
|
+
----==_mimepart_56d6626fdc766_107a53fc0f0860204405bd
|
19
|
+
Content-Type: image/gif;
|
20
|
+
charset=UTF-8;
|
21
|
+
filename=image1.gif
|
22
|
+
Content-Transfer-Encoding: base64
|
23
|
+
Content-Disposition: inline
|
24
|
+
Content-ID: <56d6626fdc766_107a53fc0f086020440474@Robs-MacBook-Pro.local.mail>
|
25
|
+
|
26
|
+
R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
|
27
|
+
|
28
|
+
----==_mimepart_56d6626fdc766_107a53fc0f0860204405bd--
|
@@ -2,7 +2,7 @@
|
|
2
2
|
[
|
3
3
|
[
|
4
4
|
"read",
|
5
|
-
"220
|
5
|
+
"220 smtp.mandrillapp.com ESMTP\r\n"
|
6
6
|
],
|
7
7
|
[
|
8
8
|
"write",
|
@@ -10,7 +10,7 @@
|
|
10
10
|
],
|
11
11
|
[
|
12
12
|
"read",
|
13
|
-
"250-
|
13
|
+
"250-relay-5.us-east-1.relay-prod\r\n250-PIPELINING\r\n250-SIZE 26214400\r\n250-STARTTLS\r\n250-AUTH PLAIN LOGIN\r\n250-ENHANCEDSTATUSCODES\r\n250 8BITMIME\r\n"
|
14
14
|
],
|
15
15
|
[
|
16
16
|
"write",
|
@@ -18,13 +18,13 @@
|
|
18
18
|
],
|
19
19
|
[
|
20
20
|
"read",
|
21
|
-
"221 2.0.0
|
21
|
+
"221 2.0.0 Bye\r\n"
|
22
22
|
]
|
23
23
|
],
|
24
24
|
[
|
25
25
|
[
|
26
26
|
"read",
|
27
|
-
"220
|
27
|
+
"220 mail.smtp2go.com ESMTP Exim 4.86 Wed, 02 Mar 2016 02:55:19 +0000\r\n"
|
28
28
|
],
|
29
29
|
[
|
30
30
|
"write",
|
@@ -32,7 +32,7 @@
|
|
32
32
|
],
|
33
33
|
[
|
34
34
|
"read",
|
35
|
-
"250-
|
35
|
+
"250-mail.smtp2go.com Hello localhost [50.160.254.134]\r\n250-SIZE 52428800\r\n250-8BITMIME\r\n250-DSN\r\n250-PIPELINING\r\n250-AUTH CRAM-MD5 PLAIN LOGIN\r\n250-STARTTLS\r\n250-PRDR\r\n250 HELP\r\n"
|
36
36
|
],
|
37
37
|
[
|
38
38
|
"write",
|
@@ -40,7 +40,7 @@
|
|
40
40
|
],
|
41
41
|
[
|
42
42
|
"read",
|
43
|
-
"221
|
43
|
+
"221 mail.smtp2go.com closing connection\r\n"
|
44
44
|
]
|
45
45
|
]
|
46
46
|
]
|
@@ -2,13 +2,13 @@
|
|
2
2
|
[
|
3
3
|
[
|
4
4
|
"read",
|
5
|
-
"220
|
5
|
+
"220 smtp.mandrillapp.com ESMTP\r\n"
|
6
6
|
]
|
7
7
|
],
|
8
8
|
[
|
9
9
|
[
|
10
10
|
"read",
|
11
|
-
"220
|
11
|
+
"220 mail.smtp2go.com ESMTP Exim 4.86 Wed, 02 Mar 2016 02:56:54 +0000\r\n"
|
12
12
|
]
|
13
13
|
]
|
14
14
|
]
|
@@ -0,0 +1,212 @@
|
|
1
|
+
[
|
2
|
+
[
|
3
|
+
[
|
4
|
+
"read",
|
5
|
+
"220 mx.google.com ESMTP s68sm2109275yhp.29 - gsmtp\r\n"
|
6
|
+
],
|
7
|
+
[
|
8
|
+
"write",
|
9
|
+
"EHLO localhost.localdomain\r\n"
|
10
|
+
],
|
11
|
+
[
|
12
|
+
"read",
|
13
|
+
"250-mx.google.com at your service, [72.16.218.22]\r\n250-SIZE 35882577\r\n250-8BITMIME\r\n250-STARTTLS\r\n250-ENHANCEDSTATUSCODES\r\n250-PIPELINING\r\n250-CHUNKING\r\n250 SMTPUTF8\r\n"
|
14
|
+
],
|
15
|
+
[
|
16
|
+
"write",
|
17
|
+
"STARTTLS\r\n"
|
18
|
+
],
|
19
|
+
[
|
20
|
+
"read",
|
21
|
+
"220 2.0.0 Ready to start TLS\r\n"
|
22
|
+
],
|
23
|
+
[
|
24
|
+
"write",
|
25
|
+
"EHLO localhost.localdomain\r\n"
|
26
|
+
],
|
27
|
+
[
|
28
|
+
"read",
|
29
|
+
"250-mx.google.com at your service, [72.16.218.22]\r\n250-SIZE 35882577\r\n250-8BITMIME\r\n250-AUTH LOGIN PLAIN XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER\r\n250-ENHANCEDSTATUSCODES\r\n250-PIPELINING\r\n250-CHUNKING\r\n250 SMTPUTF8\r\n"
|
30
|
+
],
|
31
|
+
[
|
32
|
+
"write",
|
33
|
+
"AUTH LOGIN\r\n"
|
34
|
+
],
|
35
|
+
[
|
36
|
+
"read",
|
37
|
+
"334 VXNlcm5hbWU6\r\n"
|
38
|
+
],
|
39
|
+
[
|
40
|
+
"write",
|
41
|
+
"<username>\r\n"
|
42
|
+
],
|
43
|
+
[
|
44
|
+
"read",
|
45
|
+
"334 UGFzc3dvcmQ6\r\n"
|
46
|
+
],
|
47
|
+
[
|
48
|
+
"write",
|
49
|
+
"<password>\r\n"
|
50
|
+
],
|
51
|
+
[
|
52
|
+
"read",
|
53
|
+
"235 2.7.0 Accepted\r\n"
|
54
|
+
],
|
55
|
+
[
|
56
|
+
"write",
|
57
|
+
"MAIL FROM:<yvonne@lang.name>\r\n"
|
58
|
+
],
|
59
|
+
[
|
60
|
+
"read",
|
61
|
+
"250 2.1.0 OK s68sm2109275yhp.29 - gsmtp\r\n"
|
62
|
+
],
|
63
|
+
[
|
64
|
+
"write",
|
65
|
+
"RCPT TO:<rob.forman@salesloft.com>\r\n"
|
66
|
+
],
|
67
|
+
[
|
68
|
+
"read",
|
69
|
+
"250 2.1.5 OK s68sm2109275yhp.29 - gsmtp\r\n"
|
70
|
+
],
|
71
|
+
[
|
72
|
+
"write",
|
73
|
+
"DATA\r\n"
|
74
|
+
],
|
75
|
+
[
|
76
|
+
"read",
|
77
|
+
"354 Go ahead s68sm2109275yhp.29 - gsmtp\r\n"
|
78
|
+
],
|
79
|
+
[
|
80
|
+
"write",
|
81
|
+
"Date: Wed, 10 Dec 2014 14:29:05 -0500\r\n"
|
82
|
+
],
|
83
|
+
[
|
84
|
+
"write",
|
85
|
+
"From: \"Dr. Antonina Goldner\" <yvonne@lang.name>\r\n"
|
86
|
+
],
|
87
|
+
[
|
88
|
+
"write",
|
89
|
+
"To: \"Rob Forman, Jr.\" <rob.forman@salesloft.com>\r\n"
|
90
|
+
],
|
91
|
+
[
|
92
|
+
"write",
|
93
|
+
"Message-ID: <54889f0114dd6_e0cc3ff785c65be4768ab@porus-2.local.mail>\r\n"
|
94
|
+
],
|
95
|
+
[
|
96
|
+
"write",
|
97
|
+
"Subject: Look at this dog\r\n"
|
98
|
+
],
|
99
|
+
[
|
100
|
+
"write",
|
101
|
+
"Mime-Version: 1.0\r\n"
|
102
|
+
],
|
103
|
+
[
|
104
|
+
"write",
|
105
|
+
"Content-Type: multipart/related;\r\n"
|
106
|
+
],
|
107
|
+
[
|
108
|
+
"write",
|
109
|
+
" boundary=\"--==_mimepart_54889f0114dd6_e0cc3ff785c65be47679c\";\r\n"
|
110
|
+
],
|
111
|
+
[
|
112
|
+
"write",
|
113
|
+
" charset=UTF-8\r\n"
|
114
|
+
],
|
115
|
+
[
|
116
|
+
"write",
|
117
|
+
"Content-Transfer-Encoding: 7bit\r\n"
|
118
|
+
],
|
119
|
+
[
|
120
|
+
"write",
|
121
|
+
"\r\n"
|
122
|
+
],
|
123
|
+
[
|
124
|
+
"write",
|
125
|
+
"\r\n"
|
126
|
+
],
|
127
|
+
[
|
128
|
+
"write",
|
129
|
+
"----==_mimepart_54889f0114dd6_e0cc3ff785c65be47679c\r\n"
|
130
|
+
],
|
131
|
+
[
|
132
|
+
"write",
|
133
|
+
"Content-Type: text/html;\r\n"
|
134
|
+
],
|
135
|
+
[
|
136
|
+
"write",
|
137
|
+
" charset=UTF-8\r\n"
|
138
|
+
],
|
139
|
+
[
|
140
|
+
"write",
|
141
|
+
"Content-Transfer-Encoding: 7bit\r\n"
|
142
|
+
],
|
143
|
+
[
|
144
|
+
"write",
|
145
|
+
"\r\n"
|
146
|
+
],
|
147
|
+
[
|
148
|
+
"write",
|
149
|
+
"because it's awesome! <img src=\"cid:54889f0114dd6_e0cc3ff785c65be476690@porus-2.local.mail\" style=\"width: 1px;\"><img src=\"http://test.host/email_trackers/95c2a5ca-a740-4001-95bc-bdb8eefce914/open.gif\" alt=\"\" width=\"1\" height=\"1\">\r\n"
|
150
|
+
],
|
151
|
+
[
|
152
|
+
"write",
|
153
|
+
"----==_mimepart_54889f0114dd6_e0cc3ff785c65be47679c\r\n"
|
154
|
+
],
|
155
|
+
[
|
156
|
+
"write",
|
157
|
+
"Content-Type: image/gif;\r\n"
|
158
|
+
],
|
159
|
+
[
|
160
|
+
"write",
|
161
|
+
" charset=UTF-8;\r\n"
|
162
|
+
],
|
163
|
+
[
|
164
|
+
"write",
|
165
|
+
" filename=image1.gif\r\n"
|
166
|
+
],
|
167
|
+
[
|
168
|
+
"write",
|
169
|
+
"Content-Transfer-Encoding: base64\r\n"
|
170
|
+
],
|
171
|
+
[
|
172
|
+
"write",
|
173
|
+
"Content-Disposition: inline\r\n"
|
174
|
+
],
|
175
|
+
[
|
176
|
+
"write",
|
177
|
+
"Content-ID: <54889f0114dd6_e0cc3ff785c65be476690@porus-2.local.mail>\r\n"
|
178
|
+
],
|
179
|
+
[
|
180
|
+
"write",
|
181
|
+
"\r\n"
|
182
|
+
],
|
183
|
+
[
|
184
|
+
"write",
|
185
|
+
"R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\r\n"
|
186
|
+
],
|
187
|
+
[
|
188
|
+
"write",
|
189
|
+
"\r\n"
|
190
|
+
],
|
191
|
+
[
|
192
|
+
"write",
|
193
|
+
"----==_mimepart_54889f0114dd6_e0cc3ff785c65be47679c--\r\n"
|
194
|
+
],
|
195
|
+
[
|
196
|
+
"write",
|
197
|
+
".\r\n"
|
198
|
+
],
|
199
|
+
[
|
200
|
+
"read",
|
201
|
+
"250 2.0.0 OK 1418239746 s68sm2109275yhp.29 - gsmtp\r\n"
|
202
|
+
],
|
203
|
+
[
|
204
|
+
"write",
|
205
|
+
"QUIT\r\n"
|
206
|
+
],
|
207
|
+
[
|
208
|
+
"read",
|
209
|
+
"221 2.0.0 closing connection s68sm2109275yhp.29 - gsmtp\r\n"
|
210
|
+
]
|
211
|
+
]
|
212
|
+
]
|
data/spec/tcr_spec.rb
CHANGED
@@ -5,6 +5,7 @@ require "net/http"
|
|
5
5
|
require "net/imap"
|
6
6
|
require "net/smtp"
|
7
7
|
require 'thread'
|
8
|
+
require "mail"
|
8
9
|
|
9
10
|
|
10
11
|
describe TCR do
|
@@ -28,7 +29,7 @@ describe TCR do
|
|
28
29
|
end
|
29
30
|
|
30
31
|
it "defaults to erroring on read/write mismatch access" do
|
31
|
-
TCR.configuration.block_for_reads.should
|
32
|
+
TCR.configuration.block_for_reads.should be_falsey
|
32
33
|
end
|
33
34
|
end
|
34
35
|
|
@@ -41,8 +42,8 @@ describe TCR do
|
|
41
42
|
|
42
43
|
it "configures tcp ports to hook" do
|
43
44
|
expect {
|
44
|
-
TCR.configure { |c| c.hook_tcp_ports = [
|
45
|
-
}.to change{ TCR.configuration.hook_tcp_ports }.from([]).to([
|
45
|
+
TCR.configure { |c| c.hook_tcp_ports = [2525] }
|
46
|
+
}.to change{ TCR.configuration.hook_tcp_ports }.from([]).to([2525])
|
46
47
|
end
|
47
48
|
|
48
49
|
it "configures allowing a blocking read mode" do
|
@@ -53,9 +54,9 @@ describe TCR do
|
|
53
54
|
end
|
54
55
|
|
55
56
|
it "raises an error if you connect to a hooked port without using a cassette" do
|
56
|
-
TCR.configure { |c| c.hook_tcp_ports = [
|
57
|
+
TCR.configure { |c| c.hook_tcp_ports = [2525] }
|
57
58
|
expect {
|
58
|
-
tcp_socket = TCPSocket.open("
|
59
|
+
tcp_socket = TCPSocket.open("smtp.mandrillapp.com", 2525)
|
59
60
|
}.to raise_error(TCR::NoCassetteError)
|
60
61
|
end
|
61
62
|
|
@@ -67,17 +68,17 @@ describe TCR do
|
|
67
68
|
end
|
68
69
|
|
69
70
|
it "disables hooks within the block" do
|
70
|
-
TCR.configure { |c| c.hook_tcp_ports = [
|
71
|
+
TCR.configure { |c| c.hook_tcp_ports = [2525] }
|
71
72
|
TCR.turned_off do
|
72
73
|
TCR.configuration.hook_tcp_ports.should == []
|
73
74
|
end
|
74
75
|
end
|
75
76
|
|
76
77
|
it "makes real TCPSocket.open calls even when hooks are setup" do
|
77
|
-
TCR.configure { |c| c.hook_tcp_ports = [
|
78
|
+
TCR.configure { |c| c.hook_tcp_ports = [2525] }
|
78
79
|
expect(TCPSocket).to receive(:real_open)
|
79
80
|
TCR.turned_off do
|
80
|
-
tcp_socket = TCPSocket.open("
|
81
|
+
tcp_socket = TCPSocket.open("smtp.mandrillapp.com", 2525)
|
81
82
|
end
|
82
83
|
end
|
83
84
|
end
|
@@ -123,7 +124,7 @@ describe TCR do
|
|
123
124
|
describe ".use_cassette" do
|
124
125
|
before(:each) {
|
125
126
|
TCR.configure { |c|
|
126
|
-
c.hook_tcp_ports = [
|
127
|
+
c.hook_tcp_ports = [2525]
|
127
128
|
c.cassette_library_dir = "."
|
128
129
|
}
|
129
130
|
}
|
@@ -143,36 +144,36 @@ describe TCR do
|
|
143
144
|
it "creates a cassette file on use" do
|
144
145
|
expect {
|
145
146
|
TCR.use_cassette("test") do
|
146
|
-
tcp_socket = TCPSocket.open("
|
147
|
+
tcp_socket = TCPSocket.open("smtp.mandrillapp.com", 2525)
|
147
148
|
end
|
148
149
|
}.to change{ File.exists?("./test.json") }.from(false).to(true)
|
149
150
|
end
|
150
151
|
|
151
152
|
it "records the tcp session data into the file" do
|
152
153
|
TCR.use_cassette("test") do
|
153
|
-
tcp_socket = TCPSocket.open("
|
154
|
+
tcp_socket = TCPSocket.open("smtp.mandrillapp.com", 2525)
|
154
155
|
io = Net::InternetMessageIO.new(tcp_socket)
|
155
156
|
line = io.readline
|
156
157
|
tcp_socket.close
|
157
158
|
end
|
158
159
|
cassette_contents = File.open("test.json") { |f| f.read }
|
159
|
-
cassette_contents.include?("220
|
160
|
+
cassette_contents.include?("220 smtp.mandrillapp.com ESMTP").should == true
|
160
161
|
end
|
161
162
|
|
162
163
|
it "plays back tcp sessions without opening a real connection" do
|
163
164
|
expect(TCPSocket).to_not receive(:real_open)
|
164
165
|
|
165
|
-
TCR.use_cassette("spec/fixtures/
|
166
|
-
tcp_socket = TCPSocket.open("
|
166
|
+
TCR.use_cassette("spec/fixtures/mandrill_smtp") do
|
167
|
+
tcp_socket = TCPSocket.open("smtp.mandrillapp.com", 2525)
|
167
168
|
io = Net::InternetMessageIO.new(tcp_socket)
|
168
|
-
line = io.readline.should include("220
|
169
|
+
line = io.readline.should include("220 smtp.mandrillapp.com ESMTP")
|
169
170
|
end
|
170
171
|
end
|
171
172
|
|
172
173
|
it "raises an error if the recording gets out of order (i.e., we went to write but it expected a read)" do
|
173
174
|
expect {
|
174
|
-
TCR.use_cassette("spec/fixtures/
|
175
|
-
tcp_socket = TCPSocket.open("
|
175
|
+
TCR.use_cassette("spec/fixtures/mandrill_smtp") do
|
176
|
+
tcp_socket = TCPSocket.open("smtp.mandrillapp.com", 2525)
|
176
177
|
io = Net::InternetMessageIO.new(tcp_socket)
|
177
178
|
io.write("hi")
|
178
179
|
end
|
@@ -216,28 +217,46 @@ describe TCR do
|
|
216
217
|
}.not_to raise_error
|
217
218
|
end
|
218
219
|
|
220
|
+
it "can stub the full session of a real server accepting a real email over SMTPS with STARTTLS" do
|
221
|
+
TCR.configure { |c|
|
222
|
+
c.hook_tcp_ports = [587]
|
223
|
+
c.block_for_reads = true
|
224
|
+
}
|
225
|
+
|
226
|
+
raw_contents = File.open("spec/fixtures/email_with_image.eml"){ |f| f.read }
|
227
|
+
message = Mail::Message.new(raw_contents)
|
228
|
+
smtp_auth_parameters = { address: "smtp.gmail.com", port: 587, user_name: "dummy", password: "dummy", enable_starttls_auto: true, authentication: :login}
|
229
|
+
message.delivery_method(:smtp, smtp_auth_parameters)
|
230
|
+
|
231
|
+
expect{
|
232
|
+
TCR.use_cassette("spec/fixtures/smtp-success") do
|
233
|
+
message.deliver
|
234
|
+
end
|
235
|
+
}.not_to raise_error
|
236
|
+
end
|
237
|
+
|
219
238
|
context "multiple connections" do
|
220
239
|
it "records multiple sessions per cassette" do
|
221
240
|
TCR.use_cassette("test") do
|
222
|
-
smtp = Net::SMTP.start("
|
241
|
+
smtp = Net::SMTP.start("smtp.mandrillapp.com", 2525)
|
223
242
|
smtp.finish
|
224
|
-
smtp = Net::SMTP.start("
|
243
|
+
smtp = Net::SMTP.start("mail.smtp2go.com", 2525)
|
225
244
|
smtp.finish
|
226
245
|
end
|
227
246
|
cassette_contents = File.open("test.json") { |f| f.read }
|
228
|
-
cassette_contents.include?("
|
229
|
-
cassette_contents.include?("
|
247
|
+
cassette_contents.include?("smtp.mandrillapp.com ESMTP").should == true
|
248
|
+
cassette_contents.include?("mail.smtp2go.com ESMTP").should == true
|
230
249
|
end
|
231
250
|
|
232
251
|
it "plays back multiple sessions per cassette in order" do
|
233
252
|
TCR.use_cassette("spec/fixtures/multitest") do
|
234
|
-
tcp_socket = TCPSocket.open("
|
253
|
+
tcp_socket = TCPSocket.open("smtp.mandrillapp.com", 2525)
|
235
254
|
io = Net::InternetMessageIO.new(tcp_socket)
|
236
|
-
line = io.readline.should include("
|
255
|
+
line = io.readline.should include("smtp.mandrillapp.com ESMTP")
|
237
256
|
|
238
|
-
tcp_socket = TCPSocket.open("
|
257
|
+
tcp_socket = TCPSocket.open("mail.smtp2go.com", 2525)
|
239
258
|
io = Net::InternetMessageIO.new(tcp_socket)
|
240
|
-
line = io.readline.should include("
|
259
|
+
line = io.readline.should include("mail.smtp2go.com ESMTP")
|
241
260
|
end
|
242
261
|
end
|
243
262
|
|
@@ -273,9 +292,9 @@ describe TCR do
|
|
273
292
|
it "raises an error if you try to playback more sessions than you previously recorded" do
|
274
293
|
expect {
|
275
294
|
TCR.use_cassette("spec/fixtures/multitest-smtp") do
|
276
|
-
smtp = Net::SMTP.start("
|
277
|
-
smtp = Net::SMTP.start("
|
278
|
-
smtp = Net::SMTP.start("
|
295
|
+
smtp = Net::SMTP.start("smtp.mandrillapp.com", 2525)
|
296
|
+
smtp = Net::SMTP.start("mail.smtp2go.com", 2525)
|
297
|
+
smtp = Net::SMTP.start("mail.smtp2go.com", 2525)
|
279
298
|
end
|
280
299
|
}.to raise_error(TCR::NoMoreSessionsError)
|
281
300
|
end
|
data/tcr.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tcr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rob Forman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: mail
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: geminabox
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -59,11 +73,13 @@ files:
|
|
59
73
|
- lib/tcr/recordable_tcp_socket.rb
|
60
74
|
- lib/tcr/version.rb
|
61
75
|
- spec/fixtures/block_for_reads.json
|
76
|
+
- spec/fixtures/email_with_image.eml
|
62
77
|
- spec/fixtures/google_https.json
|
63
78
|
- spec/fixtures/google_imap.json
|
64
|
-
- spec/fixtures/
|
79
|
+
- spec/fixtures/mandrill_smtp.json
|
65
80
|
- spec/fixtures/multitest-smtp.json
|
66
81
|
- spec/fixtures/multitest.json
|
82
|
+
- spec/fixtures/smtp-success.json
|
67
83
|
- spec/fixtures/starwars_telnet.json
|
68
84
|
- spec/spec_helper.rb
|
69
85
|
- spec/tcr_spec.rb
|
@@ -87,17 +103,19 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
103
|
version: '0'
|
88
104
|
requirements: []
|
89
105
|
rubyforge_project:
|
90
|
-
rubygems_version: 2.
|
106
|
+
rubygems_version: 2.4.5
|
91
107
|
signing_key:
|
92
108
|
specification_version: 4
|
93
109
|
summary: TCR is a lightweight VCR for TCP sockets.
|
94
110
|
test_files:
|
95
111
|
- spec/fixtures/block_for_reads.json
|
112
|
+
- spec/fixtures/email_with_image.eml
|
96
113
|
- spec/fixtures/google_https.json
|
97
114
|
- spec/fixtures/google_imap.json
|
98
|
-
- spec/fixtures/
|
115
|
+
- spec/fixtures/mandrill_smtp.json
|
99
116
|
- spec/fixtures/multitest-smtp.json
|
100
117
|
- spec/fixtures/multitest.json
|
118
|
+
- spec/fixtures/smtp-success.json
|
101
119
|
- spec/fixtures/starwars_telnet.json
|
102
120
|
- spec/spec_helper.rb
|
103
121
|
- spec/tcr_spec.rb
|