tcr 0.0.3 → 0.0.4
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.
- data/README.md +14 -1
- data/lib/tcr/version.rb +1 -1
- data/lib/tcr.rb +16 -0
- data/spec/tcr_spec.rb +24 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -40,7 +40,20 @@ class TCRTest < Test::Unit::TestCase
|
|
40
40
|
end
|
41
41
|
```
|
42
42
|
|
43
|
-
Run this test once, and TCR will record the tcp interactions to fixtures/tcr_cassettes/google_smtp.json.
|
43
|
+
Run this test once, and TCR will record the tcp interactions to fixtures/tcr_cassettes/google_smtp.json.
|
44
|
+
|
45
|
+
```json
|
46
|
+
[
|
47
|
+
[
|
48
|
+
[
|
49
|
+
"read",
|
50
|
+
"220 mx.google.com ESMTP x3si2474860qas.18 - gsmtp\r\n"
|
51
|
+
]
|
52
|
+
]
|
53
|
+
]
|
54
|
+
```
|
55
|
+
|
56
|
+
Run it again, and TCR will replay the interactions from json when the tcp request is made. This test is now fast (no real TCP requests are made anymore), deterministic and accurate.
|
44
57
|
|
45
58
|
## Contributing
|
46
59
|
|
data/lib/tcr/version.rb
CHANGED
data/lib/tcr.rb
CHANGED
@@ -26,6 +26,14 @@ module TCR
|
|
26
26
|
@cassette = v
|
27
27
|
end
|
28
28
|
|
29
|
+
def disabled
|
30
|
+
@disabled || false
|
31
|
+
end
|
32
|
+
|
33
|
+
def disabled=(v)
|
34
|
+
@disabled = v
|
35
|
+
end
|
36
|
+
|
29
37
|
def save_session
|
30
38
|
end
|
31
39
|
|
@@ -35,6 +43,14 @@ module TCR
|
|
35
43
|
yield
|
36
44
|
TCR.cassette = nil
|
37
45
|
end
|
46
|
+
|
47
|
+
def turned_off(&block)
|
48
|
+
raise ArgumentError, "`TCR.turned_off` requires a block." unless block
|
49
|
+
current_hook_tcp_ports = configuration.hook_tcp_ports
|
50
|
+
configuration.hook_tcp_ports = []
|
51
|
+
yield
|
52
|
+
configuration.hook_tcp_ports = current_hook_tcp_ports
|
53
|
+
end
|
38
54
|
end
|
39
55
|
|
40
56
|
|
data/spec/tcr_spec.rb
CHANGED
@@ -18,7 +18,7 @@ describe TCR do
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
describe ".
|
21
|
+
describe ".configure" do
|
22
22
|
it "configures cassette location" do
|
23
23
|
expect {
|
24
24
|
TCR.configure { |c| c.cassette_library_dir = "some/dir" }
|
@@ -39,6 +39,29 @@ describe TCR do
|
|
39
39
|
}.to raise_error(TCR::NoCassetteError)
|
40
40
|
end
|
41
41
|
|
42
|
+
describe ".turned_off" do
|
43
|
+
it "requires a block to call" do
|
44
|
+
expect {
|
45
|
+
TCR.turned_off
|
46
|
+
}.to raise_error(ArgumentError)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "disables hooks within the block" do
|
50
|
+
TCR.configure { |c| c.hook_tcp_ports = [25] }
|
51
|
+
TCR.turned_off do
|
52
|
+
TCR.configuration.hook_tcp_ports.should == []
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
it "makes real TCPSocket.open calls even when hooks are setup" do
|
57
|
+
TCR.configure { |c| c.hook_tcp_ports = [25] }
|
58
|
+
expect(TCPSocket).to receive(:real_open)
|
59
|
+
TCR.turned_off do
|
60
|
+
tcp_socket = TCPSocket.open("aspmx.l.google.com", 25)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
42
65
|
describe ".use_cassette" do
|
43
66
|
before(:each) {
|
44
67
|
TCR.configure { |c|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tcr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-09-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|