Sha256: e73e5241b3cd02941adcd48357c1728b20ae66348384bfb210ecceda4239f5e1

Contents?: true

Size: 1.39 KB

Versions: 4

Compression:

Stored size: 1.39 KB

Contents

require 'spec_helper'

describe Alerty::Command do
  describe 'run!' do
    context 'Frontkick.exec' do
      before do
        Alerty::Config.configure(
          log_path: '/tmp/foo',
          log_level: 'fatal',
          timeout: 20,
          lock_path: '/tmp/lock',
        )
      end

      let(:command) { Alerty::Command.new(command: 'ls') }

      it do
        expect(Frontkick).to receive(:exec).with("ls 2>&1", {
          timeout: 20,
          exclusive: '/tmp/lock',
        }).and_return(Frontkick::Result.new(exit_code: 0))
        expect { command.run! }.to raise_error(SystemExit)
      end
    end

    context 'plugins.alert' do
      before do
        Alerty::Config.instance_variable_set(:@config, Hashie::Mash.new(
          plugins: [{
            type: 'stdout',
          }]
        ))
        Alerty::Config.configure(
          log_path: '/tmp/foo',
          log_level: 'fatal',
          timeout: nil,
          lock_path: nil,
        )
      end

      let(:command) { Alerty::Command.new(command: 'echo foo') }

      it do
        expect(Frontkick).to receive(:exec).with("echo foo 2>&1", {
          timeout: nil,
          exclusive: nil,
        }).and_return(Frontkick::Result.new(stdout: 'foo', exit_code: 1))
        stdout = capture_stdout { expect { command.run! }.to raise_error(SystemExit) }
        expect(JSON.parse(stdout)["output"]).to eql("foo")
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
alerty-0.0.7 spec/command_spec.rb
alerty-0.0.6 spec/command_spec.rb
alerty-0.0.5 spec/command_spec.rb
alerty-0.0.4 spec/command_spec.rb