Class: LoweredExpectations
- Inherits:
-
Object
- Object
- LoweredExpectations
show all
- Defined in:
- lib/lowered/expectations.rb
Defined Under Namespace
Classes: CommandExecutionError, IncompatibleVersionError, MissingExecutableError, VersionPatternError
Class Method Summary
collapse
Class Method Details
.expect(executable, version, vopt: '--version', vpattern: '(\d+\.\d+\.\d+)') ⇒ Object
33
34
35
36
37
|
# File 'lib/lowered/expectations.rb', line 33
def self.expect(executable, version, vopt: '--version', vpattern: '(\d+\.\d+\.\d+)')
vstring = run! which(executable), vopt, quiet: true
vmatch = /#{vpattern}/.match(vstring)
verify_version(vmatch[0], version) || raise(VersionPatternError.new("unable to match #{vpattern} in version output #{vstring} from #{executable}"))
end
|
.verify_version(version, pattern) ⇒ Object
50
51
52
|
# File 'lib/lowered/expectations.rb', line 50
def self.verify_version(version, pattern)
Gem::Dependency.new('', pattern).match?('', version) || raise(IncompatibleVersionError.new("#{version} does not match version pattern #{pattern}"))
end
|
.which(cmd) ⇒ Object
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/lowered/expectations.rb', line 39
def self.which(cmd)
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
exts.each do |ext|
exe = File.join(path, "#{cmd}#{ext}")
return exe if File.executable?(exe) && !File.directory?(exe)
end
end
raise MissingExecutableError.new("#{executable} not found in #{ENV['PATH']}")
end
|