breadkit-rspec 0.1.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 +7 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +56 -0
- data/lib/breadkit/rspec/version.rb +7 -0
- data/lib/breadkit/rspec.rb +42 -0
- data/sig/breadkit/rspec.rbs +5 -0
- metadata +81 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 17012e9c7a478381843b2a2e507146f76694f5b90682e0703d9065f69cdf9edb
|
|
4
|
+
data.tar.gz: 84fef55083fec4a4d28f978fa284c56962e5889b82f5e76b8246fe1b618c1aec
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 2e33ab84993a87a1befdb285abf3bbbc7f8b44659b91e81ad8db018917b17fd567aca35667e7a9f96ee29c9d87106a28b0387c87e5d6e31a825b827f29739459
|
|
7
|
+
data.tar.gz: 8a5db88e462b1468a9e54bf73bf53c5625d1e637e93909cbc77701c27f853849d57a14558caff7fc1779af7afb0e66f83a9777d3407e355c7f5d8278a21bc6d6
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ydah
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# breadkit-rspec
|
|
2
|
+
|
|
3
|
+
RSpec matchers for resolved [Breadkit](https://github.com/breadkit/breadkit) circuits.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
Requires Ruby 3.3 or newer and Breadkit core 0.2.x:
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
gem install breadkit-rspec
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
If the required releases are not yet on RubyGems, add both main checkouts to
|
|
14
|
+
your Gemfile:
|
|
15
|
+
|
|
16
|
+
```ruby
|
|
17
|
+
gem "breadkit", git: "https://github.com/breadkit/breadkit.git", branch: "main"
|
|
18
|
+
gem "breadkit-rspec", git: "https://github.com/breadkit/breadkit-rspec.git", branch: "main"
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Require the matchers in `spec/spec_helper.rb`:
|
|
22
|
+
|
|
23
|
+
```ruby
|
|
24
|
+
require "breadkit/rspec"
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Test a circuit
|
|
28
|
+
|
|
29
|
+
```ruby
|
|
30
|
+
RSpec.describe "LED circuit" do
|
|
31
|
+
let(:circuit) { Breadkit.load("circuits/led.bk.rb") }
|
|
32
|
+
|
|
33
|
+
it "connects the LED through the resistor" do
|
|
34
|
+
expect(circuit).to connect("R1.2", "D1.anode")
|
|
35
|
+
expect(circuit).not_to connect("D1.cathode", :VCC)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "connects the switched input when pressed" do
|
|
39
|
+
expect(circuit).to connect("R1.1", :VCC).in_state("SW1")
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
`connect` resolves pin aliases, named nets, and hole IDs through
|
|
45
|
+
`Breadkit::Circuit#net_of`. It fails when either reference is unknown. Use
|
|
46
|
+
`.in_state("SW1")` for a switch state; an unknown state raises an error.
|
|
47
|
+
Use `.in_state("SW1,SW2")` to close both named switches while leaving the
|
|
48
|
+
others open. Named states do not require enumerating every switch combination.
|
|
49
|
+
|
|
50
|
+
## Development
|
|
51
|
+
|
|
52
|
+
Clone `breadkit` and `breadkit-rspec` as sibling directories, then run
|
|
53
|
+
`bundle install` and `bundle exec rake` here. The gem is independent of
|
|
54
|
+
`breadkit-lint` and `breadkit-render`.
|
|
55
|
+
|
|
56
|
+
MIT licensed. See [LICENSE.txt](LICENSE.txt).
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "breadkit"
|
|
4
|
+
require "rspec/expectations"
|
|
5
|
+
require_relative "rspec/version"
|
|
6
|
+
|
|
7
|
+
RSpec::Matchers.define :connect do |left, right|
|
|
8
|
+
chain :in_state do |name|
|
|
9
|
+
@state_name = name.to_s
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
match do |circuit|
|
|
13
|
+
raise ArgumentError, "expected a Breadkit::Circuit" unless circuit.is_a?(Breadkit::Circuit)
|
|
14
|
+
|
|
15
|
+
if @state_name
|
|
16
|
+
names = @state_name.split(",", -1)
|
|
17
|
+
switches = names.map { |name| circuit.components[name] }
|
|
18
|
+
valid = names.uniq.length == names.length &&
|
|
19
|
+
switches.all? { |component| component && Array(component.part.data["switch"]).any? }
|
|
20
|
+
raise ArgumentError, "unknown circuit state: #{@state_name}" unless valid
|
|
21
|
+
|
|
22
|
+
closed = switches.flat_map { |component| Array(component.part.data["switch"]).map { |pair| [component, pair] } }
|
|
23
|
+
state = Breadkit::State.new(name: @state_name, closed_switches: closed)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
@left_net = circuit.net_of(left, state)
|
|
27
|
+
@right_net = circuit.net_of(right, state)
|
|
28
|
+
raise ArgumentError, "unknown circuit reference: #{left}" unless @left_net
|
|
29
|
+
raise ArgumentError, "unknown circuit reference: #{right}" unless @right_net
|
|
30
|
+
|
|
31
|
+
@left_net.equal?(@right_net)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
failure_message do
|
|
35
|
+
"expected #{left.inspect} and #{right.inspect} to share a net; separate nets " \
|
|
36
|
+
"(#{@left_net&.name || "unknown"} and #{@right_net&.name || "unknown"})"
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
failure_message_when_negated do
|
|
40
|
+
"expected #{left.inspect} and #{right.inspect} to be isolated, but both resolve to #{@left_net.name}"
|
|
41
|
+
end
|
|
42
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: breadkit-rspec
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Yudai Takada
|
|
8
|
+
bindir: exe
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: breadkit
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - "~>"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: 0.2.0
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - "~>"
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: 0.2.0
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: rspec-expectations
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - "~>"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '3.0'
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '3.0'
|
|
40
|
+
description: Test resolved Breadkit circuit connections and switch states with RSpec
|
|
41
|
+
expectations.
|
|
42
|
+
email:
|
|
43
|
+
- t.yudai92@gmail.com
|
|
44
|
+
executables: []
|
|
45
|
+
extensions: []
|
|
46
|
+
extra_rdoc_files: []
|
|
47
|
+
files:
|
|
48
|
+
- CHANGELOG.md
|
|
49
|
+
- LICENSE.txt
|
|
50
|
+
- README.md
|
|
51
|
+
- lib/breadkit/rspec.rb
|
|
52
|
+
- lib/breadkit/rspec/version.rb
|
|
53
|
+
- sig/breadkit/rspec.rbs
|
|
54
|
+
homepage: https://github.com/breadkit/breadkit-rspec
|
|
55
|
+
licenses:
|
|
56
|
+
- MIT
|
|
57
|
+
metadata:
|
|
58
|
+
homepage_uri: https://github.com/breadkit/breadkit-rspec
|
|
59
|
+
source_code_uri: https://github.com/breadkit/breadkit-rspec/tree/main
|
|
60
|
+
documentation_uri: https://github.com/breadkit/breadkit-rspec#readme
|
|
61
|
+
bug_tracker_uri: https://github.com/breadkit/breadkit-rspec/issues
|
|
62
|
+
changelog_uri: https://github.com/breadkit/breadkit-rspec/blob/main/CHANGELOG.md
|
|
63
|
+
rubygems_mfa_required: 'true'
|
|
64
|
+
rdoc_options: []
|
|
65
|
+
require_paths:
|
|
66
|
+
- lib
|
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
68
|
+
requirements:
|
|
69
|
+
- - ">="
|
|
70
|
+
- !ruby/object:Gem::Version
|
|
71
|
+
version: '3.3'
|
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
|
+
requirements:
|
|
74
|
+
- - ">="
|
|
75
|
+
- !ruby/object:Gem::Version
|
|
76
|
+
version: '0'
|
|
77
|
+
requirements: []
|
|
78
|
+
rubygems_version: 4.0.16
|
|
79
|
+
specification_version: 4
|
|
80
|
+
summary: RSpec matchers for Breadkit circuits.
|
|
81
|
+
test_files: []
|