Skip to content

[Feature Idea] Record & Replay #44

@albertalef

Description

@albertalef

Problem: Manually writing mock outputs is tedious and may not accurately reflect real command behavior. Tests need real output format but shouldn't execute commands every time.

Solution: Record actual command outputs to fixture files during development, then replay them in tests for fast, deterministic execution with real data.

# Record mode - executes real commands and saves output
RubyShell.record("fixtures/git_commands.yml") do
  sh do
    git("status")
    git("log", "-5", oneline: true)
  end
end

# Replay mode - returns recorded output without executing
RubyShell.replay("fixtures/git_commands.yml") do
  sh do
    status = git("status")  # returns recorded output
  end
end

# In RSpec
RSpec.describe "Git operations" do
  around do |example|
    RubyShell.replay("fixtures/git_commands.yml") { example.run }
  end

  it "parses git status" do
    expect(sh { git("status") }).to include("On branch main")
  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