Sha256: 0cbbb592b06d883b05b5b3a4291aa53df22a61f1596e49c17133e30bef1bebd5

Contents?: true

Size: 1.2 KB

Versions: 3

Compression:

Stored size: 1.2 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
          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(err_out: ::StringIO.new, out_out: ::StringIO.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

3 entries across 3 versions & 2 rubygems

Version Path
avm-tools-0.113.5 sub/eac_cli/lib/eac_cli/rspec/setup.rb
eac_cli-0.25.0 lib/eac_cli/rspec/setup.rb
avm-tools-0.113.4 sub/eac_cli/lib/eac_cli/rspec/setup.rb