betamax 0.1.0 → 0.2.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 +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +53 -9
- data/Rakefile +9 -4
- data/UNLICENSE +24 -0
- data/lib/betamax/errors.rb +2 -2
- data/lib/betamax/minitest.rb +27 -0
- data/lib/betamax/player.rb +2 -0
- data/lib/betamax/rspec.rb +1 -1
- data/lib/betamax/tape.rb +8 -8
- data/lib/betamax/version.rb +1 -1
- data/lib/betamax.rb +14 -13
- metadata +5 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b13224e3fa5f820802a68dc000dbabab4a023eff18250e3b0af5e9fb36f98092
|
|
4
|
+
data.tar.gz: 70fb0889db8f8b4df8b7b60527895f27d806bda46164990670cec559e5e0b29c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '0698af118ee8b4a7900e8fa490548b9967e4c91c5fa1cb7d7543b5f55aaf71ab1993a8b6efdfa80467c830e86f24227be5f42e3b0509bb628657914c49f01003'
|
|
7
|
+
data.tar.gz: ea48915b0269d20c9810d7a65a8519c0b9a6b84cdab6dd918822ba92da084fbd427b0d2145ce7f27757a5bacf39d9476a7646e0fcf2fbbbcbff2a26d64db51e6
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
- Add Minitest support via `Betamax::Minitest#with_betamax`.
|
|
6
|
+
- Clear the active player when a test raises, so a later test cannot record onto a stale player.
|
|
7
|
+
|
|
8
|
+
## 0.1.1 - 2026-06-15
|
|
9
|
+
|
|
10
|
+
- Add UNLICENSE
|
|
11
|
+
|
|
3
12
|
## [0.1.0] - 2026-06-15
|
|
4
13
|
|
|
5
14
|
- Initial release
|
data/README.md
CHANGED
|
@@ -1,32 +1,76 @@
|
|
|
1
1
|
# Betamax
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/betamax`. To experiment with that code, run `bin/console` for an interactive prompt.
|
|
3
|
+
Betamax allows for the recording and playback of arbitrary Ruby objects to simplify testing external dependencies. Think of it like the [VCR](https://github.com/vcr/vcr) gem, but for any complicated object, not just HTTP interactions. This gem was originally developed to write a test suite for a MiniDisc NetMD Walkman library, where the recording and playback of real USB traffic was desired.
|
|
6
4
|
|
|
7
5
|
## Installation
|
|
8
6
|
|
|
9
|
-
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
|
10
|
-
|
|
11
7
|
Install the gem and add to the application's Gemfile by executing:
|
|
12
8
|
|
|
13
9
|
```bash
|
|
14
|
-
bundle add
|
|
10
|
+
bundle add betamax
|
|
15
11
|
```
|
|
16
12
|
|
|
17
13
|
If bundler is not being used to manage dependencies, install the gem by executing:
|
|
18
14
|
|
|
19
15
|
```bash
|
|
20
|
-
gem install
|
|
16
|
+
gem install betamax
|
|
21
17
|
```
|
|
22
18
|
|
|
23
19
|
## Usage
|
|
24
20
|
|
|
25
|
-
|
|
21
|
+
Currently this gem supports testing with RSpec. First, require the gem in your spec helper:
|
|
22
|
+
|
|
23
|
+
```ruby
|
|
24
|
+
# File: spec/spec_helper.rb
|
|
25
|
+
|
|
26
|
+
require 'betamax'
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Then, record an object. The first time you run your test, a recording will be created in `spec/betamax_tapes/`. Subsequent test runs will playback from your recording. Make sure to tag your example as `:betamax` to enable recording and playback.
|
|
30
|
+
|
|
31
|
+
```ruby
|
|
32
|
+
RSpec.describe 'a MiniDisc device' do
|
|
33
|
+
let(:walkman) do
|
|
34
|
+
usb_device = LibUSB::Context.devices(idProduct: 0x0084).first
|
|
35
|
+
|
|
36
|
+
MiniDisc::Device.new usb_device: Betamax.record(usb_device)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it 'has a tracklist', :betamax do
|
|
40
|
+
walkman.open do |disc|
|
|
41
|
+
disc.tracks.first.title.should == 'Song of the Highwire Shrimper'
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
In the above example, the test will continue to work even if the USB device is no longer present. If for some reason changes to your code change the interaction with your recorded object, your test will fail. This could be because methods were called in a different order, block arguments changed, method calls were expected but did not take place, etc.
|
|
49
|
+
|
|
50
|
+
### Minitest
|
|
51
|
+
|
|
52
|
+
Include `Betamax::Minitest` in your test class and surround the recorded interaction with `with_betamax`. Tapes are named after the test class and method and stored in `test/betamax_tapes/` (override with `tapes_folder:`).
|
|
53
|
+
|
|
54
|
+
```ruby
|
|
55
|
+
class WalkmanTest < Minitest::Test
|
|
56
|
+
include Betamax::Minitest
|
|
57
|
+
|
|
58
|
+
def test_tracklist
|
|
59
|
+
with_betamax do
|
|
60
|
+
usb_device = LibUSB::Context.devices(idProduct: 0x0084).first
|
|
61
|
+
walkman = MiniDisc::Device.new usb_device: Betamax.record(usb_device)
|
|
62
|
+
|
|
63
|
+
walkman.open do |disc|
|
|
64
|
+
assert_equal 'Song of the Highwire Shrimper', disc.tracks.first.title
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
```
|
|
26
70
|
|
|
27
71
|
## Development
|
|
28
72
|
|
|
29
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake
|
|
73
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rake` to run the RSpec and Minitest suites and RuboCop. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
30
74
|
|
|
31
75
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
32
76
|
|
data/Rakefile
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
require
|
|
2
|
-
require
|
|
1
|
+
require 'bundler/gem_tasks'
|
|
2
|
+
require 'rake/testtask'
|
|
3
|
+
require 'rspec/core/rake_task'
|
|
4
|
+
require 'rubocop/rake_task'
|
|
3
5
|
|
|
4
6
|
RSpec::Core::RakeTask.new :spec
|
|
5
7
|
|
|
6
|
-
|
|
8
|
+
Rake::TestTask.new :test do |task|
|
|
9
|
+
task.libs << 'lib'
|
|
10
|
+
task.pattern = 'test/**/*_test.rb'
|
|
11
|
+
end
|
|
7
12
|
|
|
8
13
|
RuboCop::RakeTask.new
|
|
9
14
|
|
|
10
|
-
task default: %i[spec rubocop]
|
|
15
|
+
task default: %i[spec test rubocop]
|
data/UNLICENSE
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
This is free and unencumbered software released into the public domain.
|
|
2
|
+
|
|
3
|
+
Anyone is free to copy, modify, publish, use, compile, sell, or
|
|
4
|
+
distribute this software, either in source code form or as a compiled
|
|
5
|
+
binary, for any purpose, commercial or non-commercial, and by any
|
|
6
|
+
means.
|
|
7
|
+
|
|
8
|
+
In jurisdictions that recognize copyright laws, the author or authors
|
|
9
|
+
of this software dedicate any and all copyright interest in the
|
|
10
|
+
software to the public domain. We make this dedication for the benefit
|
|
11
|
+
of the public at large and to the detriment of our heirs and
|
|
12
|
+
successors. We intend this dedication to be an overt act of
|
|
13
|
+
relinquishment in perpetuity of all present and future rights to this
|
|
14
|
+
software under copyright law.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
20
|
+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
21
|
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
+
|
|
24
|
+
For more information, please refer to <http://unlicense.org/>
|
data/lib/betamax/errors.rb
CHANGED
|
@@ -3,7 +3,7 @@ module Betamax
|
|
|
3
3
|
class Error < StandardError; end
|
|
4
4
|
|
|
5
5
|
class NoTapeInserted < Error
|
|
6
|
-
def initialize message =
|
|
6
|
+
def initialize message = 'No tape inserted'
|
|
7
7
|
super
|
|
8
8
|
end
|
|
9
9
|
end
|
|
@@ -51,7 +51,7 @@ module Betamax
|
|
|
51
51
|
|
|
52
52
|
class UnusedRecordings < PlaybackError
|
|
53
53
|
def initialize unused_methods
|
|
54
|
-
method_names = unused_methods.map(&:method_name).join(
|
|
54
|
+
method_names = unused_methods.map(&:method_name).join(', ')
|
|
55
55
|
super "Recording has #{unused_methods.size} unused method(s): #{method_names}"
|
|
56
56
|
end
|
|
57
57
|
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module Betamax
|
|
2
|
+
module Minitest
|
|
3
|
+
DEFAULT_TAPES_FOLDER = Pathname.new 'test/betamax_tapes/'
|
|
4
|
+
|
|
5
|
+
# Adapts a Minitest test and block to the example interface Player expects.
|
|
6
|
+
class Example
|
|
7
|
+
attr_reader :metadata
|
|
8
|
+
|
|
9
|
+
def initialize test, &block
|
|
10
|
+
@metadata = { description: test.name, example_group: { description: test.class.name } }
|
|
11
|
+
@block = block
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def run
|
|
15
|
+
@block.call
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def exception
|
|
19
|
+
nil
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def with_betamax(tapes_folder: DEFAULT_TAPES_FOLDER, &)
|
|
24
|
+
Player.new(Example.new(self, &), tapes_folder: Pathname.new(tapes_folder)).play
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
data/lib/betamax/player.rb
CHANGED
data/lib/betamax/rspec.rb
CHANGED
data/lib/betamax/tape.rb
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
require
|
|
2
|
-
require
|
|
1
|
+
require 'fileutils'
|
|
2
|
+
require 'yaml'
|
|
3
3
|
|
|
4
4
|
module Betamax
|
|
5
5
|
class Tape
|
|
@@ -20,11 +20,11 @@ module Betamax
|
|
|
20
20
|
|
|
21
21
|
def self.from_rspec_example example, tapes_folder:
|
|
22
22
|
name = cassette_name_for example.metadata
|
|
23
|
-
name.gsub!
|
|
24
|
-
name.gsub!(/[\s-]+/,
|
|
25
|
-
name.gsub! %r{[^a-zA-Z0-9_/]},
|
|
23
|
+
name.gsub! '::', '_'
|
|
24
|
+
name.gsub!(/[\s-]+/, '_')
|
|
25
|
+
name.gsub! %r{[^a-zA-Z0-9_/]}, ''
|
|
26
26
|
|
|
27
|
-
filename = Pathname.new(name).sub_ext
|
|
27
|
+
filename = Pathname.new(name).sub_ext '.yaml'
|
|
28
28
|
full_path = tapes_folder / filename
|
|
29
29
|
|
|
30
30
|
new full_path
|
|
@@ -44,7 +44,7 @@ module Betamax
|
|
|
44
44
|
current = current[:parent_example_group]
|
|
45
45
|
end
|
|
46
46
|
|
|
47
|
-
description_parts.join
|
|
47
|
+
description_parts.join '/'
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
def load
|
|
@@ -66,7 +66,7 @@ module Betamax
|
|
|
66
66
|
version: Recording::VERSION,
|
|
67
67
|
objects: { default: proxy }
|
|
68
68
|
|
|
69
|
-
File.open @path,
|
|
69
|
+
File.open @path, 'w' do |file|
|
|
70
70
|
file.puts recording.to_yaml
|
|
71
71
|
end
|
|
72
72
|
end
|
data/lib/betamax/version.rb
CHANGED
data/lib/betamax.rb
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
require
|
|
2
|
-
|
|
3
|
-
require_relative
|
|
4
|
-
require_relative
|
|
5
|
-
require_relative
|
|
6
|
-
require_relative
|
|
7
|
-
require_relative
|
|
8
|
-
require_relative
|
|
9
|
-
require_relative
|
|
10
|
-
require_relative
|
|
11
|
-
require_relative
|
|
12
|
-
require_relative
|
|
13
|
-
require_relative
|
|
1
|
+
require 'pathname'
|
|
2
|
+
|
|
3
|
+
require_relative 'betamax/errors'
|
|
4
|
+
require_relative 'betamax/method_player'
|
|
5
|
+
require_relative 'betamax/method_recorder'
|
|
6
|
+
require_relative 'betamax/minitest'
|
|
7
|
+
require_relative 'betamax/player'
|
|
8
|
+
require_relative 'betamax/recorded_method'
|
|
9
|
+
require_relative 'betamax/recorded_object'
|
|
10
|
+
require_relative 'betamax/recorded_yielding'
|
|
11
|
+
require_relative 'betamax/recording'
|
|
12
|
+
require_relative 'betamax/rspec'
|
|
13
|
+
require_relative 'betamax/tape'
|
|
14
|
+
require_relative 'betamax/version'
|
|
14
15
|
|
|
15
16
|
module Betamax
|
|
16
17
|
extend RSpec
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: betamax
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- John DeSilva
|
|
@@ -20,10 +20,12 @@ files:
|
|
|
20
20
|
- CHANGELOG.md
|
|
21
21
|
- README.md
|
|
22
22
|
- Rakefile
|
|
23
|
+
- UNLICENSE
|
|
23
24
|
- lib/betamax.rb
|
|
24
25
|
- lib/betamax/errors.rb
|
|
25
26
|
- lib/betamax/method_player.rb
|
|
26
27
|
- lib/betamax/method_recorder.rb
|
|
28
|
+
- lib/betamax/minitest.rb
|
|
27
29
|
- lib/betamax/player.rb
|
|
28
30
|
- lib/betamax/recorded_method.rb
|
|
29
31
|
- lib/betamax/recorded_object.rb
|
|
@@ -47,14 +49,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
47
49
|
requirements:
|
|
48
50
|
- - ">="
|
|
49
51
|
- !ruby/object:Gem::Version
|
|
50
|
-
version: 3.
|
|
52
|
+
version: '3.3'
|
|
51
53
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
52
54
|
requirements:
|
|
53
55
|
- - ">="
|
|
54
56
|
- !ruby/object:Gem::Version
|
|
55
57
|
version: '0'
|
|
56
58
|
requirements: []
|
|
57
|
-
rubygems_version: 4.0.
|
|
59
|
+
rubygems_version: 4.0.16
|
|
58
60
|
specification_version: 4
|
|
59
61
|
summary: Record and playback of arbitrary Ruby objects
|
|
60
62
|
test_files: []
|