Problem: Verifying that a script executed the right commands with correct arguments requires manual tracking or complex mock setups.
Solution: Provide RSpec matchers to expressively assert command execution, arguments, order, and count.
require "rubyshell/testing"
RSpec.describe "Deployment" do
include RubyShell::TestHelpers
it "executes git pull" do
run_deploy
expect(sh).to have_executed("git pull")
end
it "runs bundle with correct flags" do
run_deploy
expect(sh).to have_executed(:bundle).with("install", "--deployment")
end
it "executes in order" do
run_deploy
expect(sh).to have_executed(
"git pull",
"bundle install --deployment",
"systemctl restart myapp"
).in_order
end
it "calls curl twice" do
run_health_check
expect(sh).to have_executed(:curl).exactly(2).times
end
end
Problem: Verifying that a script executed the right commands with correct arguments requires manual tracking or complex mock setups.
Solution: Provide RSpec matchers to expressively assert command execution, arguments, order, and count.