Sha256: 45d1ee8958cc41951f3b22c3fb961dcae079a56ba7955a717cdf09f00a4cfb3d

Contents?: true

Size: 1.14 KB

Versions: 16

Compression:

Stored size: 1.14 KB

Contents

RSpec::Matchers.define :have_version do |version|
  match do |file|
    get_version(file) == version
  end

  failure_message do |file|
    "Expected file '#{file.name}' to have version '#{version}' but it had version '#{get_version}' instead"
  end

  failure_message_when_negated do |file|
    "Expected file '#{file.name}' to not have version '#{version}' but it did"
  end

  private
  def get_version(file)
    version_dll = Fiddle.dlopen('version.dll')

    s=''
    vsize = Fiddle::Function.new(version_dll['GetFileVersionInfoSize'],
                [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP],
                Fiddle::TYPE_LONG).call(file.name, s)

    raise 'Unable to determine the version number' unless vsize > 0

    result = ' '*vsize
    Fiddle::Function.new(version_dll['GetFileVersionInfo'],
                         [Fiddle::TYPE_VOIDP, Fiddle::TYPE_LONG,
                          Fiddle::TYPE_LONG, Fiddle::TYPE_VOIDP],
            Fiddle::TYPE_VOIDP).call(file.name, 0, vsize, result)

    rstring = result.unpack('v*').map{|s| s.chr if s<256}*''
    r = /FileVersion..(.*?)\000/.match(rstring)

    r[1]
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
octopus-serverspec-extensions-0.18.1 lib/octopus_serverspec_extensions/matcher/have_version.rb
octopus-serverspec-extensions-0.18.0 lib/octopus_serverspec_extensions/matcher/have_version.rb
octopus-serverspec-extensions-0.17.3 lib/octopus_serverspec_extensions/matcher/have_version.rb
octopus-serverspec-extensions-0.17.2 lib/octopus_serverspec_extensions/matcher/have_version.rb
octopus-serverspec-extensions-0.17.1 lib/octopus_serverspec_extensions/matcher/have_version.rb
octopus-serverspec-extensions-0.17.0 lib/octopus_serverspec_extensions/matcher/have_version.rb
octopus-serverspec-extensions-0.15.5 lib/octopus_serverspec_extensions/matcher/have_version.rb
octopus-serverspec-extensions-0.15.4 lib/octopus_serverspec_extensions/matcher/have_version.rb
octopus-serverspec-extensions-0.15.3 lib/octopus_serverspec_extensions/matcher/have_version.rb
octopus-serverspec-extensions-0.15.2 lib/octopus_serverspec_extensions/matcher/have_version.rb
octopus-serverspec-extensions-0.15.1 lib/octopus_serverspec_extensions/matcher/have_version.rb
octopus-serverspec-extensions-0.15.0 lib/octopus_serverspec_extensions/matcher/have_version.rb
octopus-serverspec-extensions-0.13.6 lib/octopus_serverspec_extensions/matcher/have_version.rb
octopus-serverspec-extensions-0.13.5 lib/octopus_serverspec_extensions/matcher/have_version.rb
octopus-serverspec-extensions-0.13.4 lib/octopus_serverspec_extensions/matcher/have_version.rb
octopus-serverspec-extensions-0.13.3 lib/octopus_serverspec_extensions/matcher/have_version.rb