Sha256: 995d75c4523de5be2f2ca2383c2b2a0c03535f472f47199ec902db5388a194c2

Contents?: true

Size: 1.44 KB

Versions: 58

Compression:

Stored size: 1.44 KB

Contents

require 'spec_helper'
require 'r10k/util/setopts'

describe R10K::Util::Setopts do
  let(:klass) do
    Class.new do
      include R10K::Util::Setopts

      attr_reader :valid, :alsovalid, :truthyvalid

      def initialize(opts = {})
        setopts(opts, {
          :valid => :self, :alsovalid => :self, :truthyvalid => true,
          :validalias => :valid,
          :ignoreme => nil
        })
      end
    end
  end

  it "can handle an empty hash of options" do
    o = klass.new()
    expect(o.valid).to be_nil
    expect(o.alsovalid).to be_nil
  end

  it "can handle a single valid option" do
    o = klass.new(:valid => 'yep')
    expect(o.valid).to eq 'yep'
    expect(o.alsovalid).to be_nil
  end

  it "can handle multiple valid options" do
    o = klass.new(:valid => 'yep', :alsovalid => 'yarp')
    expect(o.valid).to eq 'yep'
    expect(o.alsovalid).to eq 'yarp'
  end

  it "can handle options marked with TrueClass" do
    o = klass.new(:truthyvalid => 'so truthy')
    expect(o.truthyvalid).to eq 'so truthy'
  end

  it "can handle aliases marked with :self" do
    o = klass.new(:validalias => 'yuuup')
    expect(o.valid).to eq 'yuuup'
  end


  it "raises an error when given an unhandled option" do
    expect {
      klass.new(:valid => 'yep', :notvalid => 'newp')
    }.to raise_error(ArgumentError, /cannot handle option 'notvalid'/)
  end

  it "ignores values that are marked as unhandled" do
    klass.new(:ignoreme => "IGNORE ME!")
  end
end

Version data entries

58 entries across 58 versions & 1 rubygems

Version Path
r10k-3.8.0 spec/unit/util/setopts_spec.rb
r10k-3.7.0 spec/unit/util/setopts_spec.rb
r10k-3.6.0 spec/unit/util/setopts_spec.rb
r10k-2.6.9 spec/unit/util/setopts_spec.rb
r10k-3.5.2 spec/unit/util/setopts_spec.rb
r10k-3.5.1 spec/unit/util/setopts_spec.rb
r10k-3.5.0 spec/unit/util/setopts_spec.rb
r10k-3.4.1 spec/unit/util/setopts_spec.rb
r10k-2.6.8 spec/unit/util/setopts_spec.rb
r10k-3.4.0 spec/unit/util/setopts_spec.rb
r10k-3.3.3 spec/unit/util/setopts_spec.rb
r10k-3.2.3 spec/unit/util/setopts_spec.rb
r10k-2.6.7 spec/unit/util/setopts_spec.rb
r10k-3.3.2 spec/unit/util/setopts_spec.rb
r10k-3.3.1 spec/unit/util/setopts_spec.rb
r10k-3.2.1 spec/unit/util/setopts_spec.rb
r10k-3.0.4 spec/unit/util/setopts_spec.rb
r10k-2.6.6 spec/unit/util/setopts_spec.rb
r10k-3.3.0 spec/unit/util/setopts_spec.rb
r10k-3.2.0 spec/unit/util/setopts_spec.rb