tcr 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +20 -0
- data/lib/tcr/cassette.rb +6 -0
- data/lib/tcr/configuration.rb +2 -1
- data/lib/tcr/errors.rb +1 -0
- data/lib/tcr/recordable_tcp_socket.rb +2 -2
- data/lib/tcr/version.rb +1 -1
- data/lib/tcr.rb +1 -0
- data/spec/fixtures/multitest-extra-smtp.json +46 -0
- data/spec/tcr_spec.rb +18 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a28e8b95a4b4ab94f8ecd81e18b8b137c08c553e
|
4
|
+
data.tar.gz: 90533c5bfc680269ddbe4c0d5a13f0f832c8dff2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8bcf3b85f896c8d82de587c95e7b3af669f8a298ca774ad0c74714168d79e9309af624253e545d4d46fdc2be976f9b21f7544db215087ccc27f1ea1afec1f96d
|
7
|
+
data.tar.gz: 808b5ea5528e599b4f6729c1992a002d4dc15b78e0a712d3d455db2e85b93c30d9bba9b96364c2d5e087cb631d204fee59405569f92cad361bdb013d38f1371a
|
data/README.md
CHANGED
@@ -67,6 +67,26 @@ TCR.turned_off do
|
|
67
67
|
end
|
68
68
|
```
|
69
69
|
|
70
|
+
To make sure all external calls really happened use `hit_all` option:
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
class TCRTest < Test::Unit::TestCase
|
74
|
+
def test_example_dot_com
|
75
|
+
TCR.use_cassette('mandrill_smtp', hit_all: true) do
|
76
|
+
# There are previously recorded external calls.
|
77
|
+
# ExtraSessionsError will be raised as a result.
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
```
|
82
|
+
|
83
|
+
You can also use the configuration option:
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
TCR.configure do |c|
|
87
|
+
c.hit_all = true
|
88
|
+
end
|
89
|
+
```
|
70
90
|
## Contributing
|
71
91
|
|
72
92
|
1. Fork it
|
data/lib/tcr/cassette.rb
CHANGED
data/lib/tcr/configuration.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module TCR
|
2
2
|
class Configuration
|
3
|
-
attr_accessor :cassette_library_dir, :hook_tcp_ports, :block_for_reads, :format
|
3
|
+
attr_accessor :cassette_library_dir, :hook_tcp_ports, :block_for_reads, :format, :hit_all
|
4
4
|
|
5
5
|
def initialize
|
6
6
|
reset_defaults!
|
@@ -11,6 +11,7 @@ module TCR
|
|
11
11
|
@hook_tcp_ports = []
|
12
12
|
@block_for_reads = false
|
13
13
|
@format = "json"
|
14
|
+
@hit_all = false
|
14
15
|
end
|
15
16
|
end
|
16
17
|
end
|
data/lib/tcr/errors.rb
CHANGED
@@ -87,7 +87,7 @@ module TCR
|
|
87
87
|
def _write(method, data)
|
88
88
|
if live
|
89
89
|
@socket.__send__(method, data)
|
90
|
-
recording << ["write", data]
|
90
|
+
recording << ["write", data.to_s.force_encoding("UTF-8")]
|
91
91
|
else
|
92
92
|
direction, data = recording.shift
|
93
93
|
_ensure_direction("write", direction)
|
@@ -103,7 +103,7 @@ module TCR
|
|
103
103
|
|
104
104
|
if live
|
105
105
|
data = @socket.__send__(method, *args)
|
106
|
-
recording << ["read", data]
|
106
|
+
recording << ["read", data.to_s.force_encoding("UTF-8")]
|
107
107
|
else
|
108
108
|
_block_for_read_data if blocking && TCR.configuration.block_for_reads
|
109
109
|
raise EOFError if recording.empty?
|
data/lib/tcr/version.rb
CHANGED
data/lib/tcr.rb
CHANGED
@@ -0,0 +1,46 @@
|
|
1
|
+
[
|
2
|
+
[
|
3
|
+
[
|
4
|
+
"read",
|
5
|
+
"220 smtp.mandrillapp.com ESMTP\r\n"
|
6
|
+
],
|
7
|
+
[
|
8
|
+
"write",
|
9
|
+
"EHLO localhost\r\n"
|
10
|
+
],
|
11
|
+
[
|
12
|
+
"read",
|
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
|
+
],
|
15
|
+
[
|
16
|
+
"write",
|
17
|
+
"QUIT\r\n"
|
18
|
+
],
|
19
|
+
[
|
20
|
+
"read",
|
21
|
+
"221 2.0.0 Bye\r\n"
|
22
|
+
]
|
23
|
+
],
|
24
|
+
[
|
25
|
+
[
|
26
|
+
"read",
|
27
|
+
"220 mail.smtp2go.com ESMTP Exim 4.86 Wed, 02 Mar 2016 02:55:19 +0000\r\n"
|
28
|
+
],
|
29
|
+
[
|
30
|
+
"write",
|
31
|
+
"EHLO localhost\r\n"
|
32
|
+
],
|
33
|
+
[
|
34
|
+
"read",
|
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
|
+
],
|
37
|
+
[
|
38
|
+
"write",
|
39
|
+
"QUIT\r\n"
|
40
|
+
],
|
41
|
+
[
|
42
|
+
"read",
|
43
|
+
"221 mail.smtp2go.com closing connection\r\n"
|
44
|
+
]
|
45
|
+
]
|
46
|
+
]
|
data/spec/tcr_spec.rb
CHANGED
@@ -33,6 +33,10 @@ describe TCR do
|
|
33
33
|
it "defaults to erroring on read/write mismatch access" do
|
34
34
|
TCR.configuration.block_for_reads.should be_falsey
|
35
35
|
end
|
36
|
+
|
37
|
+
it "defaults to hit all to false" do
|
38
|
+
TCR.configuration.hit_all.should be_falsey
|
39
|
+
end
|
36
40
|
end
|
37
41
|
|
38
42
|
describe ".configure" do
|
@@ -53,6 +57,12 @@ describe TCR do
|
|
53
57
|
TCR.configure { |c| c.block_for_reads = true }
|
54
58
|
}.to change{ TCR.configuration.block_for_reads }.from(false).to(true)
|
55
59
|
end
|
60
|
+
|
61
|
+
it "configures to check if all sesstions was hit" do
|
62
|
+
expect {
|
63
|
+
TCR.configure { |c| c.hit_all = true }
|
64
|
+
}.to change{ TCR.configuration.hit_all }.from(false).to(true)
|
65
|
+
end
|
56
66
|
end
|
57
67
|
|
58
68
|
it "raises an error if you connect to a hooked port without using a cassette" do
|
@@ -332,6 +342,14 @@ describe TCR do
|
|
332
342
|
end
|
333
343
|
}.to raise_error(TCR::NoMoreSessionsError)
|
334
344
|
end
|
345
|
+
|
346
|
+
it "raises an error if you try to playback less sessions than you previously recorded" do
|
347
|
+
expect {
|
348
|
+
TCR.use_cassette("spec/fixtures/multitest-extra-smtp", hit_all: true) do
|
349
|
+
smtp = Net::SMTP.start("smtp.mandrillapp.com", 2525)
|
350
|
+
end
|
351
|
+
}.to raise_error(TCR::ExtraSessionsError)
|
352
|
+
end
|
335
353
|
end
|
336
354
|
end
|
337
355
|
|
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.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rob Forman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -91,6 +91,7 @@ files:
|
|
91
91
|
- spec/fixtures/google_https.json
|
92
92
|
- spec/fixtures/google_imap.json
|
93
93
|
- spec/fixtures/mandrill_smtp.json
|
94
|
+
- spec/fixtures/multitest-extra-smtp.json
|
94
95
|
- spec/fixtures/multitest-smtp.json
|
95
96
|
- spec/fixtures/multitest.json
|
96
97
|
- spec/fixtures/smtp-success.json
|
@@ -127,6 +128,7 @@ test_files:
|
|
127
128
|
- spec/fixtures/google_https.json
|
128
129
|
- spec/fixtures/google_imap.json
|
129
130
|
- spec/fixtures/mandrill_smtp.json
|
131
|
+
- spec/fixtures/multitest-extra-smtp.json
|
130
132
|
- spec/fixtures/multitest-smtp.json
|
131
133
|
- spec/fixtures/multitest.json
|
132
134
|
- spec/fixtures/smtp-success.json
|