Skip to content

Commit

Permalink
several fixes
Browse files Browse the repository at this point in the history
  - relase 0.2.0
  - more tests on .travis-ci
  - fix #reject to pass tests on ruby >= 2.2
  - fix Gemfile to work in recent environments
  • Loading branch information
ptomulik committed Jan 27, 2017
1 parent 1fd1d6b commit b8ddcf1
Show file tree
Hide file tree
Showing 9 changed files with 163 additions and 23 deletions.
98 changes: 94 additions & 4 deletions .travis.yml
Expand Up @@ -4,23 +4,43 @@ rvm:
- 1.8.7
- 1.9.3
- 2.0.0
- 2.1
- 2.2
- 2.3
## - 2.4
- ruby-head
script: "bundle exec rake spec SPEC_OPTS='--format documentation'"
branches:
only:
master
env:
matrix:
- PUPPET_GEM_VERSION="~> 2.7.0"
- PUPPET_GEM_VERSION="~> 3.0.0"
- PUPPET_GEM_VERSION="~> 3.1.0"
- PUPPET_GEM_VERSION="~> 3.2.0"
- PUPPET_GEM_VERSION="~> 3.3.0"
- PUPPET_GEM_VERSION="~> 3.4.0"
- PUPPET_GEM_VERSION="~> 3.5.0"
- PUPPET_GEM_VERSION="~> 3.6.0"
- PUPPET_GEM_VERSION="~> 3.7.0"
- PUPPET_GEM_VERSION="~> 3.8.0"
- PUPPET_GEM_VERSION="~> 4.0.0"
- PUPPET_GEM_VERSION="~> 4.1.0"
- PUPPET_GEM_VERSION="~> 4.2.0"
- PUPPET_GEM_VERSION="~> 4.3.0"
- PUPPET_GEM_VERSION="~> 4.4.0"
matrix:
allow_failures:
- rvm: ruby-head
exclude:
- rvm: 1.8.7
env: PUPPET_GEM_VERSION="~> 2.7.0"
env: PUPPET_GEM_VERSION="~> 4.0.0"
- rvm: 1.8.7
env: PUPPET_GEM_VERSION="~> 4.1.0"
- rvm: 1.8.7
env: PUPPET_GEM_VERSION="~> 4.2.0"
- rvm: 1.8.7
env: PUPPET_GEM_VERSION="~> 4.3.0"
- rvm: 1.8.7
env: PUPPET_GEM_VERSION="~> 4.4.0"
- rvm: 1.9.3
env: PUPPET_GEM_VERSION="~> 2.7.0"
- rvm: 2.0.0
Expand All @@ -29,5 +49,75 @@ matrix:
env: PUPPET_GEM_VERSION="~> 3.0.0"
- rvm: 2.0.0
env: PUPPET_GEM_VERSION="~> 3.1.0"
- rvm: 2.1
env: PUPPET_GEM_VERSION="~> 2.7.0"
- rvm: 2.1
env: PUPPET_GEM_VERSION="~> 3.0.0"
- rvm: 2.1
env: PUPPET_GEM_VERSION="~> 3.1.0"
- rvm: 2.1
env: PUPPET_GEM_VERSION="~> 3.2.0"
- rvm: 2.1
env: PUPPET_GEM_VERSION="~> 3.3.0"
- rvm: 2.2
env: PUPPET_GEM_VERSION="~> 2.7.0"
- rvm: 2.2
env: PUPPET_GEM_VERSION="~> 3.0.0"
- rvm: 2.2
env: PUPPET_GEM_VERSION="~> 3.1.0"
- rvm: 2.2
env: PUPPET_GEM_VERSION="~> 3.2.0"
- rvm: 2.2
env: PUPPET_GEM_VERSION="~> 3.3.0"
- rvm: 2.2
env: PUPPET_GEM_VERSION="~> 3.4.0"
- rvm: 2.2
env: PUPPET_GEM_VERSION="~> 3.5.0"
- rvm: 2.2
env: PUPPET_GEM_VERSION="~> 3.6.0"
- rvm: 2.2
env: PUPPET_GEM_VERSION="~> 3.7.0"
- rvm: 2.2
env: PUPPET_GEM_VERSION="~> 3.8.0"
- rvm: 2.3
env: PUPPET_GEM_VERSION="~> 2.7.0"
- rvm: 2.3
env: PUPPET_GEM_VERSION="~> 3.0.0"
- rvm: 2.3
env: PUPPET_GEM_VERSION="~> 3.1.0"
- rvm: 2.3
env: PUPPET_GEM_VERSION="~> 3.2.0"
- rvm: 2.3
env: PUPPET_GEM_VERSION="~> 3.3.0"
- rvm: 2.3
env: PUPPET_GEM_VERSION="~> 3.4.0"
- rvm: 2.3
env: PUPPET_GEM_VERSION="~> 3.5.0"
- rvm: 2.3
env: PUPPET_GEM_VERSION="~> 3.6.0"
- rvm: 2.3
env: PUPPET_GEM_VERSION="~> 3.7.0"
- rvm: 2.3
env: PUPPET_GEM_VERSION="~> 3.8.0"
## - rvm: 2.4
## env: PUPPET_GEM_VERSION="~> 2.7.0"
## - rvm: 2.4
## env: PUPPET_GEM_VERSION="~> 3.0.0"
## - rvm: 2.4
## env: PUPPET_GEM_VERSION="~> 3.1.0"
## - rvm: 2.4
## env: PUPPET_GEM_VERSION="~> 3.2.0"
## - rvm: 2.4
## env: PUPPET_GEM_VERSION="~> 3.3.0"
## - rvm: 2.4
## env: PUPPET_GEM_VERSION="~> 3.4.0"
## - rvm: 2.4
## env: PUPPET_GEM_VERSION="~> 3.5.0"
## - rvm: 2.4
## env: PUPPET_GEM_VERSION="~> 3.6.0"
## - rvm: 2.4
## env: PUPPET_GEM_VERSION="~> 3.7.0"
## - rvm: 2.4
## env: PUPPET_GEM_VERSION="~> 3.8.0"
notifications:
email: false
5 changes: 5 additions & 0 deletions CHANGELOG
@@ -1,3 +1,8 @@
2017-01-27 Pawel Tomulik <ptomulik@meil.pw.edu.pl>
* relase 0.2.0
* more tests on .travis-ci
* fix #reject to pass tests on ruby >= 2.2
* fix Gemfile to work in recent environments
2017-01-26 Pawel Tomulik <ptomulik@meil.pw.edu.pl>
* fix .gitignore to exclude vendor/ dir from puppet module build process
* release 0.1.7
Expand Down
49 changes: 36 additions & 13 deletions Gemfile
@@ -1,19 +1,42 @@
source 'https://rubygems.org'
source ENV['GEM_SOURCE'] || 'https://rubygems.org'
def location_for(place, fake_version = nil)
if place =~ /^(git[:@][^#]*)#(.*)/
[fake_version, { :git => Regexp.last_match(1),
:branch => Regexp.last_match(2),
:require => false }].compact
elsif place =~ %r{^file://(.*)}
['>= 0', { :path => File.expand_path(Regexp.last_match(1)),
:require => false }]
else
[place, { :require => false }]
end
end

group :development, :test do
# http://stackoverflow.com/questions/30928415/how-to-setup-puppet-rspec-correctly
gem 'rspec', '~> 2.0' if RUBY_VERSION >= '1.8.7' && RUBY_VERSION < '1.9'

group :development, :test do
gem 'puppetlabs_spec_helper', :require => false
if RUBY_VERSION >= '1.9'
gem 'rake'
else
gem 'rake', '< 10.0'
gem 'highline', '< 1.7'
end
if RUBY_VERSION >= '1.9'
gem 'coveralls', :require => false
end
gem 'tins', '< 1.7.0' if RUBY_VERSION >= '1.9' && RUBY_VERSION < '2.0'
gem 'json', '< 2.0.0' if RUBY_VERSION < '2.0'
gem 'json_pure', '< 2.0.0' if RUBY_VERSION < '2.0'
gem 'term-ansicolor', '<= 1.3.2' if RUBY_VERSION >= '1.9' && RUBY_VERSION < '2.0'
if RUBY_VERSION.split('.').slice(0,2) == ['1','8']
# for 1.8 we need specific version of mime-types
gem 'mime-types', '~> 1.25'
end
gem 'rake'
gem 'puppetlabs_spec_helper', :require => false
gem 'coveralls', :require => false
end
end


gem 'puppet', *location_for(ENV['PUPPET_GEM_VERSION'])

if puppetversion = ENV['PUPPET_GEM_VERSION']
gem 'puppet', puppetversion, :require => false
else
gem 'puppet', :require => false
end
#
# vim:ft=ruby
# vim:ft=ruby
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -3,7 +3,7 @@ require 'bundler/setup'

Bundler.require :default

require 'puppetlabs_spec_helper/rake_tasks'
require 'puppetlabs_spec_helper/rake_tasks'

task :default do
sh %{rake -T}
Expand Down
15 changes: 15 additions & 0 deletions lib/puppet/util/ptomulik/vash/contained.rb
Expand Up @@ -174,10 +174,25 @@ def merge(other, &block)
end

# Same as {Hash#reject}
# @note On ruby <2.2. the {#reject} returns an instance of Hash subclass (or
# enumerator) and on >= 2.2 returns a Hash (or enumerator). We follow this
# behaviour in Vash::Contained. I'm still in doubt, however, because
# Vash::Contained is used by classes that are not sub-classing Hash. So,
# not sure it's 100% right decision.
#
# Note, that for standard Hash and its subclasses we have
# select{...}.class == Hash on ruby 1.9+.
if ruby_version < 0x020200
def reject(&block)
# note, using original 'reject' is more difficult here.
self.dup.delete_if(&block)
end
else
def reject(&block)
# note, using original 'reject' is more difficult here.
vash_underlying_hash.reject(&block)
end
end

# Same as {Hash#reject!}
def reject!(&block)
Expand Down
2 changes: 1 addition & 1 deletion metadata.json
@@ -1,6 +1,6 @@
{
"name": "ptomulik-vash",
"version": "0.1.7",
"version": "0.2.0",
"author": "ptomulik",
"summary": "Hash with input validation",
"license": "Apache-2",
Expand Down
8 changes: 5 additions & 3 deletions spec/spec_helper.rb
@@ -1,3 +1,5 @@
require 'coveralls'
Coveralls.wear!
require 'puppetlabs_spec_helper/puppetlabs_spec_helper'
if RUBY_VERSION >= '1.9'
require 'coveralls'
Coveralls.wear!
end
require 'puppetlabs_spec_helper/puppetlabs_spec_helper'
5 changes: 5 additions & 0 deletions spec/unit/puppet/shared_behaviours/ptomulik/vash/hash.rb
Expand Up @@ -119,7 +119,12 @@ def merge(other,&block); [@subject_class]; end
def merge!(other,&block); [@subject_class]; end
def rassoc(obj); [Array,NilClass]; end
def rehash; [@subject_class]; end
if (ruby_version >= 0x020200) || (ruby_version == 0x020101)
# https://www.ruby-lang.org/en/news/2014/03/10/regression-of-hash-reject-in-ruby-2-1-1/
def reject(&block); (block ? [Hash] : [enumerator_class]); end
else
def reject(&block); (block ? [@subject_class] : [enumerator_class]); end
end
def reject!(&block); (block ? [@subject_class,NilClass] : [enumerator_class]); end
def replace(other); [@subject_class]; end
if ruby_version >= 0x010901
Expand Down
Expand Up @@ -164,7 +164,7 @@ class Puppet::SharedBehaviours::PTomulik::Vash::Validator
let(:validator) { _params[:validator] }
let(:is_valid) { _is_valid }

[[:valid, :be_true], [:invalid, :be_false]].each do |_state, _return_value|
[[:valid, :be_truthy], [:invalid, :be_falsey]].each do |_state, _return_value|
_samples = _params["#{_state}_samples".intern]
_samples.each do |_sample|
context "with #{_type}=#{_sample.inspect} (#{_state})" do
Expand Down

0 comments on commit b8ddcf1

Please sign in to comment.