Skip to content

[Feature Idea] Assertions #45

Description

@albertalef

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions