Sha256: ad43b1379416d82eaa5eb838d996fa00fa946c7c0df2240ec7dd9bdb5dbe1599

Contents?: true

Size: 1.54 KB

Versions: 2

Compression:

Stored size: 1.54 KB

Contents

# frozen_string_literal: true

require 'spec_helper'
require './lib/fusuma/plugin/executors/command_executor'
require './lib/fusuma/plugin/events/event'

module Fusuma
  module Plugin
    module Executors
      RSpec.describe CommandExecutor do
        before do
          index = Config::Index.new([:dummy, 1, :direction])
          record = Events::Records::IndexRecord.new(index: index)
          @event = Events::Event.new(tag: 'dummy_detector', record: record)
          @executor = CommandExecutor.new
        end

        around do |example|
          ConfigHelper.load_config_yml = <<~CONFIG
            dummy:
              1:
                direction:
                  command: 'echo dummy'
                  interval: 1
          CONFIG

          example.run

          Config.custom_path = nil
        end

        describe '#execute' do
          it 'spawn' do
            command = 'echo dummy'
            env = {}
            expect(POSIX::Spawn).to receive(:spawn).with(env, command)
            expect(Process).to receive(:detach).with(anything)
            @executor.execute(@event)
          end
        end

        describe '#executable?' do
          context 'detector is matched with config file' do
            it { expect(@executor.executable?(@event)).to be_truthy }
          end

          context 'detector is NOT matched with config file' do
            before do
              @event.tag = 'invalid'
            end
            it { expect(@executor.executable?(@event)).to be_falsey }
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fusuma-2.0.2 spec/lib/plugin/executors/command_executor_spec.rb
fusuma-2.0.1 spec/lib/plugin/executors/command_executor_spec.rb