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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 565fc7b37f7758c3b70c3edba26a8dace04d4ced
4
- data.tar.gz: 6ddd25facb69f62f6c4756b6d18d0d133dea3dd6
3
+ metadata.gz: a28e8b95a4b4ab94f8ecd81e18b8b137c08c553e
4
+ data.tar.gz: 90533c5bfc680269ddbe4c0d5a13f0f832c8dff2
5
5
  SHA512:
6
- metadata.gz: cd8fec962f5fc58784118afd0801c60789b47aef67953f34bf7a9c42c5ffc1614de7633f11a59353ced13ca18347315a1cf7eac081e11cc862117fe27d8a2581
7
- data.tar.gz: fa8cd68d5104df3fa8aa7490c6f3f52ebae1440efd39390597989c5ead538bf6203d9da1d605696d8d3530b50c77d07017d7912e9e6ebf44712cab4492639ac2
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
@@ -35,6 +35,12 @@ module TCR
35
35
  end
36
36
  end
37
37
 
38
+ def check_hits_all_sessions
39
+ if !recording?
40
+ raise ExtraSessionsError if !@sessions.empty?
41
+ end
42
+ end
43
+
38
44
  protected
39
45
 
40
46
  def unmarshal(content)
@@ -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
@@ -2,5 +2,6 @@ module TCR
2
2
  class TCRError < StandardError; end
3
3
  class NoCassetteError < TCRError; end
4
4
  class NoMoreSessionsError < TCRError; end
5
+ class ExtraSessionsError < TCRError; end
5
6
  class DirectionMismatchError < TCRError; end
6
7
  end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module TCR
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
data/lib/tcr.rb CHANGED
@@ -42,6 +42,7 @@ module TCR
42
42
  TCR.cassette = Cassette.new(name)
43
43
  yield
44
44
  TCR.cassette.save
45
+ TCR.cassette.check_hits_all_sessions if options[:hit_all] || configuration.hit_all
45
46
  ensure
46
47
  TCR.cassette = nil
47
48
  end
@@ -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.2
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-17 00:00:00.000000000 Z
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