tcr 0.3.0 → 0.4.1

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
2
  SHA256:
3
- metadata.gz: ab0a471bccd0a80a5d75bec6909dc521072b2ad666af34935f1d6ab596d9f2b4
4
- data.tar.gz: eb6d9817d928173edd5354dc206fe7dd3e35a0f38ffde356e0e6e233e0a58431
3
+ metadata.gz: 2218fe9a2c9cb0c2c5c9d92f1e22c0a537985d45a37ca97b25e75b132984225c
4
+ data.tar.gz: d6db4c0a7d82b531f3517f2fa47a3e12cd2f530d3442dda6cbfca0fd2b9ba50f
5
5
  SHA512:
6
- metadata.gz: cedcebdd9373876a73534581ef013945ab20912ba86b71375b14de26043c135420f5140a2c1cf9d920afc9eacaa9b2f567d173c5d2525aa60db19ac97f43f606
7
- data.tar.gz: d41afdda3c2d24c85e461db3247fed88ed5c9019e0929251c03b199b37dc3dc7a261796c3266041aea90ffbdf9b0c6053a2e627a9e7b7258382430db85df66a9
6
+ metadata.gz: c274ad83970a61cb4c15e27d399a8d2efd099463fa2fa85b69c6b193b77f64f95d60effedb01f7c88641ac49ad24c5e3039317aec19ec874a7641f4173d8a208
7
+ data.tar.gz: 19d781dacbba3de87fe11e94d3d0598f94ee47976eef94dacb37688dfa45c3375329397076fa3ef2be327c22fdd985a29e1a5f37a245439b68be69d25d41055d
@@ -0,0 +1 @@
1
+ * @SalesLoft/tcr-maintainers
@@ -0,0 +1,10 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: "github-actions"
4
+ directory: "/"
5
+ schedule:
6
+ interval: "weekly"
7
+ - package-ecosystem: "bundler"
8
+ directory: "/"
9
+ schedule:
10
+ interval: "weekly"
@@ -7,33 +7,27 @@ on:
7
7
 
8
8
  jobs:
9
9
  test:
10
- name: Test
10
+ name: "Test: Ruby ${{ matrix.ruby }}"
11
11
  runs-on: ubuntu-latest
12
-
13
12
  strategy:
13
+ fail-fast: false
14
14
  matrix:
15
15
  ruby:
16
- - "2.0.0"
17
- - "2.1.9"
18
- - "2.2.10"
19
- - "2.3.7"
20
- - "2.4.4"
21
- - "2.5.1"
22
- - "2.7.3"
23
- - "3.0.1"
24
-
16
+ - "2.7"
17
+ - "3.0"
18
+ - "3.1"
19
+ - "3.2"
25
20
  steps:
26
- - uses: actions/checkout@v2
27
-
28
- - name: Initial setup
21
+ - uses: actions/checkout@v4
22
+ - name: Set up Ruby
29
23
  uses: ruby/setup-ruby@v1
30
24
  with:
31
25
  ruby-version: ${{ matrix.ruby }}
32
-
33
- - name: Install dependencies
34
- run: bundle install
35
-
36
- - name: Run tests
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
37
31
  run: bundle exec rspec
38
32
 
39
33
  testall:
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,9 @@
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-imap", "0.2.2"
8
+ gem "net-ldap"
9
+ 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
data/lib/tcr/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module TCR
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.1"
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
 
@@ -88,11 +90,11 @@ class Socket
88
90
  class << self
89
91
  alias_method :real_tcp, :tcp
90
92
 
91
- def tcp(host, port, *socket_opts)
93
+ def tcp(host, port, *local_args, **timeout_opts)
92
94
  if TCR.configuration.hook_tcp_ports.include?(port)
93
95
  TCR::RecordableTCPSocket.new(host, port, TCR.cassette)
94
96
  else
95
- real_tcp(host, port, *socket_opts)
97
+ real_tcp(host, port, *local_args, **timeout_opts)
96
98
  end
97
99
  end
98
100
  end
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
@@ -515,4 +523,18 @@ RSpec.describe TCR do
515
523
  end
516
524
  }.not_to raise_error
517
525
  end
526
+
527
+ context "when port is not in hook_tcp_ports" do
528
+ it "it honors Socket.tcp keyword arguments" do
529
+ TCR.configure { |c|
530
+ c.hook_tcp_ports = [8080]
531
+ c.cassette_library_dir = "."
532
+ }
533
+
534
+ TCR.use_cassette("test") do
535
+ sock = Socket.tcp("google.com", 80, connect_timeout: 1, resolv_timeout: 1)
536
+ expect(sock).to be_a(Socket)
537
+ end
538
+ end
539
+ end
518
540
  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.3.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob Forman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-28 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: 2024-11-27 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,10 @@ executables: []
87
17
  extensions: []
88
18
  extra_rdoc_files: []
89
19
  files:
20
+ - ".github/CODEOWNERS"
21
+ - ".github/dependabot.yml"
90
22
  - ".github/workflows/tcr.yml"
91
23
  - ".gitignore"
92
- - ".rvmrc"
93
24
  - Gemfile
94
25
  - LICENSE.txt
95
26
  - README.md
@@ -133,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
64
  - !ruby/object:Gem::Version
134
65
  version: '0'
135
66
  requirements: []
136
- rubygems_version: 3.4.7
67
+ rubygems_version: 3.4.19
137
68
  signing_key:
138
69
  specification_version: 4
139
70
  summary: TCR is a lightweight VCR for TCP sockets.
data/.rvmrc DELETED
@@ -1 +0,0 @@
1
- rvm use 1.9.3@tcr --create