Sha256: 6c7361e17d314eb41bd2bb35a2d2376ee30ff8f5edd99a76d6688ddce3bef959

Contents?: true

Size: 953 Bytes

Versions: 8

Compression:

Stored size: 953 Bytes

Contents

require 'rspec/expectations/version'

# @!method be_a_command_found_in_path
#   This matchers checks if <command> can be found in path
#
#   @return [Boolean] The result
#
#     false:
#     * if command was not found in PATH
#     true:
#     * if command can be found in PATH
#
#   @example Use matcher
#
#     RSpec.describe do
#       it { expect(cmd).to be_a_command_found_in_path }
#     end
RSpec::Matchers.define :be_a_command_found_in_path do
  match do |actual|
    @actual = Shellwords.split(actual.commandline).first if actual.respond_to? :commandline

    !which(@actual).nil?
  end

  failure_message do |actual|
    format(%(expected that command "%s" can be found in PATH "#{ENV['PATH']}".), actual)
  end

  failure_message_when_negated do |actual|
    format(%(expected that command "%s" cannot be found in PATH "#{ENV['PATH']}".), actual)
  end
end

RSpec::Matchers.alias_matcher :a_command_found_in_path, :be_a_command_found_in_path

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
aruba-1.0.4 lib/aruba/matchers/file/be_a_command_found_in_path.rb
aruba-1.0.3 lib/aruba/matchers/file/be_a_command_found_in_path.rb
aruba-1.0.2 lib/aruba/matchers/file/be_a_command_found_in_path.rb
aruba-1.0.1 lib/aruba/matchers/file/be_a_command_found_in_path.rb
aruba-1.0.0 lib/aruba/matchers/file/be_a_command_found_in_path.rb
aruba-1.0.0.pre.alpha.5 lib/aruba/matchers/file/be_a_command_found_in_path.rb
aruba-1.0.0.pre.alpha.4 lib/aruba/matchers/file/be_a_command_found_in_path.rb
aruba-1.0.0.pre.alpha.3 lib/aruba/matchers/file/be_a_command_found_in_path.rb