File: system_command_handler_spec.rb

package info (click to toggle)
pry 0.15.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,772 kB
  • sloc: ruby: 21,692; sh: 17; makefile: 11
file content (36 lines) | stat: -rw-r--r-- 1,011 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# frozen_string_literal: true

require 'stringio'

RSpec.describe Pry::SystemCommandHandler do
  describe ".default" do
    let(:output) { StringIO.new }
    let(:pry_instance) { Pry.new }

    before { allow(Kernel).to receive(:system) }

    context "when command exists" do
      before do
        expect(Kernel).to receive(:system).with('test-command').and_return(true)
      end

      it "executes the command without printing the warning" do
        described_class.default(output, 'test-command', pry_instance)
        expect(output.string).to be_empty
      end
    end

    context "when doesn't exist" do
      before do
        allow(Kernel).to receive(:system).with('test-command').and_return(nil)
      end

      it "executes the command without printing the warning" do
        described_class.default(output, 'test-command', pry_instance)
        expect(output.string).to eq(
          "Error: there was a problem executing system command: test-command\n"
        )
      end
    end
  end
end