Test Breadkit circuit connections and switch states with RSpec.
Assert that pins, board holes, and named nets share a connection in a resolved Breadkit circuit. Check connections in named switch states with the same matcher.
Install in an RSpec project with Ruby 3.3 or newer. breadkit-rspec depends on
Breadkit 0.2.x:
gem install breadkit-rspecWith Bundler, add gem "breadkit-rspec", "~> 0.1" to your Gemfile instead.
Load the matcher in spec/spec_helper.rb:
require "breadkit/rspec"With Breadkit's LED and button example
saved as circuits/led.bk.rb, add a spec:
RSpec.describe "LED circuit" do
let(:circuit) { Breadkit.load("circuits/led.bk.rb") }
it "connects the LED through the resistor" do
expect(circuit).to connect("R1.2", "D1.anode")
expect(circuit).not_to connect("D1.cathode", :VCC)
end
it "connects the input when the button is pressed" do
expect(circuit).to connect("R1.1", :VCC).in_state("SW1")
end
endconnect accepts pin aliases, hole IDs, and named nets. An unknown reference
raises ArgumentError; a failed connection expectation reports the resolved
nets.
Use .in_state("SW1") to close one switch or .in_state("SW1,SW2") to close
several. Other switches stay open, so you do not need to enumerate every switch
combination. Unknown or repeated switch names raise ArgumentError.
Clone Breadkit and this gem as sibling directories, then run:
git clone https://github.com/breadkit/breadkit.git
git clone https://github.com/breadkit/breadkit-rspec.git
cd breadkit-rspec
bundle install
bundle exec rakeMIT.