Sha256: 4cf9f88759a6c7add2d4f959d6878f85d1f790cc8a322eddd34e216f73c8ae53

Contents?: true

Size: 1.27 KB

Versions: 2

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

require 'eac_cli/config/entry'
require 'eac_cli/speaker'
require 'eac_ruby_utils/core_ext'
require 'eac_ruby_utils/speaker'

module EacCli
  module Rspec
    module Setup
      def disable_input_request
        disable_config_input_request
        disable_speaker_input_request
      end

      def disable_config_input_request
        rspec_config.before do
          # Fixes EacCli::Config::Entry does not implement #input_value error
          ::EacCli::Config::Entry.define_method(:input_value) do
            super
          end
          allow_any_instance_of(::EacCli::Config::Entry).to receive(:input_value) do |obj|
            raise "Console input requested for entry (Path: #{obj.path})"
          end
        end
      end

      def disable_speaker_input_request
        ::RSpec.configure do |config|
          config.around do |example|
            ::EacRubyUtils::Speaker
              .context.on(::EacCli::Speaker.new(in_in: FailIfRequestInput.new)) { example.run }
          end
        end
      end

      class FailIfRequestInput
        %w[gets noecho].each do |method|
          define_method(method) do
            raise "Input method requested: #{method}. Should not request input on RSpec."
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
eac_cli-0.42.0 lib/eac_cli/rspec/setup.rb
eac_cli-0.40.1 lib/eac_cli/rspec/setup.rb