tcr 0.2.2 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 6c3b335b522930e2cda40cc99bacc68109e13189
4
- data.tar.gz: 25d3fe32caf69278fc4753763e1c1ba84640a5c1
2
+ SHA256:
3
+ metadata.gz: '083e01d825d6a7807d3452e11191832b0577b30a334e22c023cd7a7d06e9eec0'
4
+ data.tar.gz: 4086810e2e1bcd060f564ed19f711035ce6e489bbe1fbb520e745428a361bd1c
5
5
  SHA512:
6
- metadata.gz: ee2afda4d4a575fee8d988d12a56b1bfe27f30dac317776232fddc019499addec91348d8c3545fbf0cccdfef0c3153b5016f66a21e8767d9e7b345fe1f7f59f9
7
- data.tar.gz: 7cc411a8feb6d80c3ee2b4541141d90e0d47845853474a69255a6b0773b683d1b2e417dc7539013adb059c5d5abc94464b4825a2e3948b2ebd212747886dfc98
6
+ metadata.gz: 72985071944d541b1623e4593a6766fa4bf5af3a5c137bca88aee527d840c676717535eba2d5baa0727daa85d9dd74eee9040e6ca6b51937935503594aced1b5
7
+ data.tar.gz: 2c7628bd3b89708ab7a55fb937696a9d932e4a4f6b4198e4ab269091d2595fa29d1c3e818457ff868ccae6dce7a52b5fb6ab8a15fa96cff0ee690a2ecba6e0af
@@ -0,0 +1 @@
1
+ * @SalesLoft/tcr-maintainers
@@ -0,0 +1,41 @@
1
+ name: TCR Spec Suite
2
+
3
+ on:
4
+ push:
5
+ branches: [master]
6
+ pull_request:
7
+
8
+ jobs:
9
+ test:
10
+ name: "Test: Ruby ${{ matrix.ruby }}"
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ fail-fast: false
14
+ matrix:
15
+ ruby:
16
+ - "2.7"
17
+ - "3.0"
18
+ - "3.1"
19
+ - "3.2"
20
+ steps:
21
+ - uses: actions/checkout@v2
22
+ - name: Set up Ruby
23
+ uses: ruby/setup-ruby@v1
24
+ with:
25
+ ruby-version: ${{ matrix.ruby }}
26
+ # runs 'bundle install' and caches installed gems automatically
27
+ bundler-cache: true
28
+ - name: Ruby Version
29
+ run: ruby --version
30
+ - name: Run Tests
31
+ run: bundle exec rspec
32
+
33
+ testall:
34
+ if: ${{ always() }}
35
+ runs-on: ubuntu-latest
36
+ name: Test (matrix)
37
+ needs: [test]
38
+ steps:
39
+ - name: Check status of all test runs
40
+ if: ${{ needs.test.result != 'success' }}
41
+ run: exit 1
data/.gitignore CHANGED
@@ -16,3 +16,4 @@ test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
18
  /.idea
19
+ .tool-versions
data/Gemfile CHANGED
@@ -1,4 +1,8 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
- # Specify your gem's dependencies in tcr.gemspec
4
3
  gemspec
4
+
5
+ gem "rspec"
6
+ gem "mail"
7
+ gem "net-ldap"
8
+ gem "mime-types"
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # TCR (TCP + VCR)
2
2
 
3
- [![Build Status](https://travis-ci.org/robforman/tcr.png?branch=master)](https://travis-ci.org/robforman/tcr)
3
+ ![Build Status](https://github.com/SalesLoft/tcr/actions/workflows/tcr.yml/badge.svg)
4
4
 
5
5
 
6
6
 
data/Rakefile CHANGED
@@ -1,4 +1,4 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
- RSpec::Core::RakeTask.new('spec')
3
+ RSpec::Core::RakeTask.new("spec")
4
4
  task :default => :spec
data/lib/tcr/cassette.rb CHANGED
@@ -16,7 +16,7 @@ module TCR
16
16
  end
17
17
 
18
18
  def recording?
19
- @recording ||= !File.exists?(filename)
19
+ @recording ||= !File.exist?(filename)
20
20
  end
21
21
 
22
22
  def next_session
@@ -27,28 +27,33 @@ module TCR
27
27
  end
28
28
  end
29
29
 
30
- def read(bytes)
31
- _read(:read, bytes)
30
+ def read(*args)
31
+ _read(:read, args)
32
32
  end
33
33
 
34
34
  def getc(*args)
35
- _read(:getc, *args)
35
+ _read(:getc, args)
36
36
  end
37
37
 
38
38
  def gets(*args)
39
- _read(:gets, *args)
39
+ _read(:gets, args)
40
40
  end
41
41
 
42
42
  def read_nonblock(*args)
43
- _read(:read_nonblock, *args, blocking: false)
43
+ _read(:read_nonblock, args, blocking: false)
44
44
  end
45
45
 
46
- def print(str)
47
- _write(:print, str)
46
+ def print(str, *args)
47
+ _write(:print, str, args)
48
48
  end
49
49
 
50
- def write(str)
51
- _write(:write, str)
50
+ def write(str, *args)
51
+ _write(:write, str, args)
52
+ str.length
53
+ end
54
+
55
+ def write_nonblock(str, *args)
56
+ _write(:write_nonblock, str, args)
52
57
  str.length
53
58
  end
54
59
 
@@ -99,10 +104,10 @@ module TCR
99
104
  @read_lock << 1
100
105
  end
101
106
 
102
- def _write(method, data)
107
+ def _write(method, data, args)
103
108
  if live
104
109
  payload = data.dup if !data.is_a?(Symbol)
105
- @socket.__send__(method, payload)
110
+ _delegate_call(method, args.unshift(payload))
106
111
  recording << ["write", data.dup]
107
112
  else
108
113
  direction, data = recording.shift
@@ -111,14 +116,11 @@ module TCR
111
116
  end
112
117
  end
113
118
 
114
- def _read(method, *args)
115
- blocking = true
116
- if args.last.is_a?(::Hash)
117
- blocking = args.pop.fetch(:blocking, true)
118
- end
119
+ def _read(method, args, opts = {})
120
+ blocking = opts.fetch(:blocking, true)
119
121
 
120
122
  if live
121
- data = @socket.__send__(method, *args)
123
+ data = _delegate_call(method, args)
122
124
  payload = data.dup if !data.is_a?(Symbol)
123
125
  recording << ["read", payload]
124
126
  else
@@ -130,6 +132,15 @@ module TCR
130
132
  data
131
133
  end
132
134
 
135
+ def _delegate_call(method, args)
136
+ if RUBY_VERSION >= "2.7" && Hash === args.last
137
+ kwargs = args.pop
138
+ @socket.__send__(method, *args, **kwargs)
139
+ else
140
+ @socket.__send__(method, *args)
141
+ end
142
+ end
143
+
133
144
  def _ensure_direction(desired, actual)
134
145
  raise TCR::DirectionMismatchError.new("Expected to '#{desired}' but next in recording was '#{actual}'") unless desired == actual
135
146
  end
@@ -146,6 +157,14 @@ module TCR
146
157
  end
147
158
  end
148
159
 
160
+ def ssl_version
161
+ ""
162
+ end
163
+
164
+ def cipher
165
+ []
166
+ end
167
+
149
168
  def sync_close=(arg)
150
169
  true
151
170
  end
@@ -169,6 +188,9 @@ module TCR
169
188
  def session=(args)
170
189
  end
171
190
 
191
+ def hostname=(args)
192
+ end
193
+
172
194
  def io
173
195
  self
174
196
  end
data/lib/tcr/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module TCR
2
- VERSION = "0.2.2"
2
+ VERSION = "0.4.0"
3
3
  end
data/lib/tcr.rb CHANGED
@@ -40,9 +40,10 @@ module TCR
40
40
  def use_cassette(name, options = {}, &block)
41
41
  raise ArgumentError, "`TCR.use_cassette` requires a block." unless block
42
42
  TCR.cassette = Cassette.new(name)
43
- yield
43
+ ret_val = yield
44
44
  TCR.cassette.save
45
45
  TCR.cassette.check_hits_all_sessions if options[:hit_all] || configuration.hit_all
46
+ ret_val
46
47
  ensure
47
48
  TCR.cassette = nil
48
49
  end
@@ -51,8 +52,9 @@ module TCR
51
52
  raise ArgumentError, "`TCR.turned_off` requires a block." unless block
52
53
  current_hook_tcp_ports = configuration.hook_tcp_ports
53
54
  configuration.hook_tcp_ports = []
54
- yield
55
+ ret_val = yield
55
56
  configuration.hook_tcp_ports = current_hook_tcp_ports
57
+ ret_val
56
58
  end
57
59
  end
58
60
 
data/spec/spec_helper.rb CHANGED
@@ -19,7 +19,6 @@ end
19
19
 
20
20
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
21
21
  RSpec.configure do |config|
22
- config.treat_symbols_as_metadata_keys_with_true_values = true
23
22
  config.run_all_when_everything_filtered = true
24
23
  config.filter_run :focus
25
24
 
data/spec/tcr_spec.rb CHANGED
@@ -15,13 +15,13 @@ RSpec.describe TCR do
15
15
  end
16
16
 
17
17
  around(:each) do |example|
18
- File.unlink("test.json") if File.exists?("test.json")
19
- File.unlink("test.yaml") if File.exists?("test.yaml")
20
- File.unlink("test.marshal") if File.exists?("test.marshal")
18
+ File.unlink("test.json") if File.exist?("test.json")
19
+ File.unlink("test.yaml") if File.exist?("test.yaml")
20
+ File.unlink("test.marshal") if File.exist?("test.marshal")
21
21
  example.run
22
- File.unlink("test.json") if File.exists?("test.json")
23
- File.unlink("test.yaml") if File.exists?("test.yaml")
24
- File.unlink("test.marshal") if File.exists?("test.marshal")
22
+ File.unlink("test.json") if File.exist?("test.json")
23
+ File.unlink("test.yaml") if File.exist?("test.yaml")
24
+ File.unlink("test.marshal") if File.exist?("test.marshal")
25
25
  end
26
26
 
27
27
  describe ".configuration" do
@@ -119,6 +119,10 @@ RSpec.describe TCR do
119
119
  }.to raise_error(ArgumentError)
120
120
  end
121
121
 
122
+ it "returns the value" do
123
+ expect(TCR.turned_off { :foobar }).to eq(:foobar)
124
+ end
125
+
122
126
  it "disables hooks within the block" do
123
127
  TCR.configure { |c| c.hook_tcp_ports = [2525] }
124
128
  TCR.turned_off do
@@ -150,6 +154,10 @@ RSpec.describe TCR do
150
154
  }.to raise_error(TCR::NoCassetteError)
151
155
  end
152
156
 
157
+ it "returns the value" do
158
+ expect(TCR.use_cassette("test") { :foobar }).to eq(:foobar)
159
+ end
160
+
153
161
  it "requires a block to call" do
154
162
  expect {
155
163
  TCR.use_cassette("test")
@@ -214,7 +222,7 @@ RSpec.describe TCR do
214
222
  TCR.use_cassette("test") do
215
223
  tcp_socket = TCPSocket.open("smtp.mandrillapp.com", 2525)
216
224
  end
217
- }.to change{ File.exists?("./test.json") }.from(false).to(true)
225
+ }.to change{ File.exist?("./test.json") }.from(false).to(true)
218
226
  end
219
227
 
220
228
  it "records the tcp session data into the file" do
@@ -237,7 +245,7 @@ RSpec.describe TCR do
237
245
  TCR.use_cassette("test") do
238
246
  tcp_socket = TCPSocket.open("smtp.mandrillapp.com", 2525)
239
247
  end
240
- }.to change{ File.exists?("./test.yaml") }.from(false).to(true)
248
+ }.to change{ File.exist?("./test.yaml") }.from(false).to(true)
241
249
  end
242
250
 
243
251
  it "records the tcp session data into the yaml file" do
@@ -261,7 +269,7 @@ RSpec.describe TCR do
261
269
  TCR.use_cassette("test") do
262
270
  tcp_socket = TCPSocket.open("smtp.mandrillapp.com", 2525)
263
271
  end
264
- }.to change{ File.exists?("./test.marshal") }.from(false).to(true)
272
+ }.to change{ File.exist?("./test.marshal") }.from(false).to(true)
265
273
  end
266
274
 
267
275
  it "records the tcp session data into the marshalled file" do
@@ -422,9 +430,9 @@ RSpec.describe TCR do
422
430
  it "raises an error if you try to playback more sessions than you previously recorded" do
423
431
  expect {
424
432
  TCR.use_cassette("spec/fixtures/multitest-smtp") do
425
- smtp = Net::SMTP.start("smtp.mandrillapp.com", 2525)
426
- smtp = Net::SMTP.start("mail.smtp2go.com", 2525)
427
- smtp = Net::SMTP.start("mail.smtp2go.com", 2525)
433
+ smtp = Net::SMTP.start("smtp.mandrillapp.com", 2525, starttls: false)
434
+ smtp = Net::SMTP.start("mail.smtp2go.com", 2525, starttls: false)
435
+ smtp = Net::SMTP.start("mail.smtp2go.com", 2525, starttls: false)
428
436
  end
429
437
  }.to raise_error(TCR::NoMoreSessionsError)
430
438
  end
@@ -432,7 +440,7 @@ RSpec.describe TCR do
432
440
  it "raises an error if you try to playback less sessions than you previously recorded" do
433
441
  expect {
434
442
  TCR.use_cassette("spec/fixtures/multitest-extra-smtp", hit_all: true) do
435
- smtp = Net::SMTP.start("smtp.mandrillapp.com", 2525)
443
+ smtp = Net::SMTP.start("smtp.mandrillapp.com", 2525, starttls: false)
436
444
  end
437
445
  }.to raise_error(TCR::ExtraSessionsError)
438
446
  end
@@ -467,12 +475,12 @@ RSpec.describe TCR do
467
475
 
468
476
  it "replaces sockets created with Socket.tcp" do
469
477
  TCR.configure { |c|
470
- c.hook_tcp_ports = [23]
478
+ c.hook_tcp_ports = [80]
471
479
  c.cassette_library_dir = "."
472
480
  }
473
481
 
474
482
  TCR.use_cassette("test") do
475
- sock = Socket.tcp("towel.blinkenlights.nl", 23)
483
+ sock = Socket.tcp("google.com", 80)
476
484
  expect(sock).to be_a(TCR::RecordableTCPSocket)
477
485
  end
478
486
  end
data/tcr.gemspec CHANGED
@@ -16,10 +16,4 @@ Gem::Specification.new do |gem|
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ["lib"]
19
-
20
- gem.add_development_dependency "rspec"
21
- gem.add_development_dependency "mail"
22
- gem.add_development_dependency "net-ldap"
23
- gem.add_development_dependency "mime-types", "~>2.0"
24
- gem.add_development_dependency "geminabox"
25
19
  end
metadata CHANGED
@@ -1,85 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tcr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob Forman
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-22 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rspec
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
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'
41
- - !ruby/object:Gem::Dependency
42
- name: net-ldap
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: mime-types
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '2.0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '2.0'
69
- - !ruby/object:Gem::Dependency
70
- name: geminabox
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
11
+ date: 2023-08-29 00:00:00.000000000 Z
12
+ dependencies: []
83
13
  description: TCR is a lightweight VCR for TCP sockets.
84
14
  email:
85
15
  - rob@robforman.com
@@ -87,9 +17,9 @@ executables: []
87
17
  extensions: []
88
18
  extra_rdoc_files: []
89
19
  files:
20
+ - ".github/CODEOWNERS"
21
+ - ".github/workflows/tcr.yml"
90
22
  - ".gitignore"
91
- - ".rvmrc"
92
- - ".travis.yml"
93
23
  - Gemfile
94
24
  - LICENSE.txt
95
25
  - README.md
@@ -118,7 +48,7 @@ files:
118
48
  homepage: ''
119
49
  licenses: []
120
50
  metadata: {}
121
- post_install_message:
51
+ post_install_message:
122
52
  rdoc_options: []
123
53
  require_paths:
124
54
  - lib
@@ -133,9 +63,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
63
  - !ruby/object:Gem::Version
134
64
  version: '0'
135
65
  requirements: []
136
- rubyforge_project:
137
- rubygems_version: 2.4.5
138
- signing_key:
66
+ rubygems_version: 3.4.7
67
+ signing_key:
139
68
  specification_version: 4
140
69
  summary: TCR is a lightweight VCR for TCP sockets.
141
70
  test_files:
data/.rvmrc DELETED
@@ -1 +0,0 @@
1
- rvm use 1.9.3@tcr --create
data/.travis.yml DELETED
@@ -1,11 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - "2.0.0"
4
- - "2.1.10"
5
- - "2.2.10"
6
- - "2.3.7"
7
- - "2.4.4"
8
- - "2.5.1"
9
- before_install:
10
- - gem install bundler
11
- script: bundle exec rspec