Sha256: 52e5e0de6803c2c8b9b9e59665b8fe8310b197bb2c2a996519205abc25c61945

Contents?: true

Size: 1.47 KB

Versions: 3

Compression:

Stored size: 1.47 KB

Contents

# frozen_string_literal: true

RSpec::Matchers.define :have_version_constant do
  match do |version_mod|
    version_mod.const_defined?(:VERSION, false)
  end
end

RSpec::Matchers.define :have_version_as_string do
  match do |version_mod|
    !version_mod::VERSION.nil? && version_mod::VERSION.is_a?(String)
  end
end

RSpec::Matchers.define :have_major_as_integer do
  match do |version_mod|
    version_mod.major.is_a?(Integer)
  end
end

RSpec::Matchers.define :have_minor_as_integer do
  match do |version_mod|
    version_mod.minor.is_a?(Integer)
  end
end

RSpec::Matchers.define :have_patch_as_integer do
  match do |version_mod|
    version_mod.patch.is_a?(Integer)
  end
end

RSpec::Matchers.define :have_pre_as_nil_or_string do
  match do |version_mod|
    version_mod.pre.nil? || version_mod.pre.is_a?(String)
  end
end

RSpec.shared_examples_for 'a Version module' do |version_mod|
  it 'is introspectable' do
    aggregate_failures 'introspectable api' do
      expect(version_mod).is_a?(Module)
      expect(version_mod).to have_version_constant
      expect(version_mod).to have_version_as_string
      expect(version_mod.to_s).to be_a(String)
      expect(version_mod).to have_major_as_integer
      expect(version_mod).to have_minor_as_integer
      expect(version_mod).to have_patch_as_integer
      expect(version_mod).to have_pre_as_nil_or_string
      expect(version_mod.to_h.keys).to match_array(%i[major minor patch pre])
      expect(version_mod.to_a).to be_a(Array)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
version_gem-1.1.2 lib/version_gem/rspec.rb
version_gem-1.1.1 lib/version_gem/rspec.rb
version_gem-1.1.0 lib/version_gem/rspec.rb