Sha256: e4fc621594dce3ae8096cf2c63a573f9037c3d521c86b7068700192230b83d94

Contents?: true

Size: 1.36 KB

Versions: 12

Compression:

Stored size: 1.36 KB

Contents

# frozen_string_literal: true

RSpec.describe Mutant::World do
  subject do
    Mutant::WORLD
  end

  describe '#inspect' do
    def apply
      subject.inspect
    end

    it 'returns expected value' do
      expect(apply).to eql('#<Mutant::World>')
    end

    it 'is frozen' do
      expect(apply.frozen?).to be(true)
    end

    it 'is idempotent' do
      expect(apply).to be(apply)
    end
  end

  describe '#capture_stdout' do
    def apply
      subject.capture_stdout(command)
    end

    let(:open3)          { class_double(Open3)              }
    let(:stdout)         { instance_double(String, :stdout) }
    let(:subject)        { super().with(open3: open3)       }
    let(:command)        { %w[foo bar baz]                  }

    let(:process_status) do
      instance_double(
        Process::Status,
        success?: success?
      )
    end

    before do
      allow(open3).to receive_messages(capture2: [stdout, process_status])
    end

    context 'when process exists successful' do
      let(:success?) { true }

      it 'returns stdout' do
        expect(apply).to eql(Mutant::Either::Right.new(stdout))
      end
    end

    context 'when process exists unsuccessful' do
      let(:success?) { false }

      it 'returns stdout' do
        expect(apply).to eql(Mutant::Either::Left.new("Command #{command.inspect} failed!"))
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
mutant-0.9.11 spec/unit/mutant/world_spec.rb
mutant-0.9.10 spec/unit/mutant/world_spec.rb
mutant-0.9.9 spec/unit/mutant/world_spec.rb
mutant-0.9.8 spec/unit/mutant/world_spec.rb
mutant-0.9.7 spec/unit/mutant/world_spec.rb
mutant-0.9.6 spec/unit/mutant/world_spec.rb
mutant-0.9.5 spec/unit/mutant/world_spec.rb
mutant-0.9.4 spec/unit/mutant/world_spec.rb
mutant-0.9.3 spec/unit/mutant/world_spec.rb
mutant-0.9.2 spec/unit/mutant/world_spec.rb
mutant-0.9.1 spec/unit/mutant/world_spec.rb
mutant-0.9.0 spec/unit/mutant/world_spec.rb