Skip to content

Instantly share code, notes, and snippets.

@bttf
Created March 29, 2013 19:44
Show Gist options
  • Save bttf/5273122 to your computer and use it in GitHub Desktop.
Save bttf/5273122 to your computer and use it in GitHub Desktop.

Revisions

  1. bttf created this gist Mar 29, 2013.
    39 changes: 39 additions & 0 deletions file_join_patch.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    class File
    class << self
    alias_method :original_join, :join
    end

    def self.join(*args)
    new_args = args.collect { |questionableEncoding|
    join_encoding_fix(questionableEncoding)
    }
    self.send(:original_join, new_args)
    end

    def self.join_encoding_fix(value)
    if (value.instance_of?(String))
    value = self.convert(value)
    elsif (value.instance_of?(Array))
    value = value.collect { |subValue|
    join_encoding_fix(subValue)
    }
    end
    value
    end

    #
    # Ruby 1.8.7 requires the iconv library for string encoding
    # Ruby 1.9.3 uses the default encode method on string.
    #
    def self.convert(value)
    if value.respond_to? :encode
    value.encode("UTF-8")
    else
    require 'iconv'
    iconv = Iconv.new('ISO-8859-1', 'utf-8')
    iconv.iconv(value)
    end
    end
    end


    17 changes: 17 additions & 0 deletions output.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    F

    Failures:

    1) puppetmaster when applied to any old node
    Failure/Error: })
    Puppet::Error:
    Could not find class puppetmaster for 88nn7w1.mustard.com on node 88nn7w1.mustard.com
    # ./spec/classes/puppetmaster_spec.rb:9:in `block (3 levels) in <top (required)>'

    Finished in 0.083 seconds
    1 example, 1 failure

    Failed examples:

    rspec ./spec/classes/puppetmaster_spec.rb:6 # puppetmaster when applied to any old node
    C:/ruby193/bin/ruby.exe -S rspec spec/classes/puppetmaster_spec.rb
    36 changes: 36 additions & 0 deletions puppetmaster_rspec.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    require 'spec_helper'
    require 'file_join_patch.rb'

    describe 'puppetmaster', :type => :class do
    describe 'when applied to any old node' do
    it {
    should contain_package('puppetmaster').with({
    'ensure' => 'present',
    })
    should contain_service('puppetmaster').with({
    'ensure' => 'running',
    })

    should contain_file('site_pp').with({
    'ensure' => 'file',
    'path' => '/etc/puppet/manifests/site.pp',
    'owner' => 'puppet',
    'group' => 'puppet',
    })

    should contain_file('puppet_conf').with({
    'ensure' => 'file',
    'path' => '/etc/puppet/puppet.conf',
    'owner' => 'puppet',
    'group' => 'puppet',
    })

    should contain_file('autosign_conf').with({
    'ensure' => 'file',
    'path' => '/etc/puppet/autosign.conf',
    'owner' => 'puppet',
    'group' => 'puppet',
    })
    }
    end
    end