Sha256: 89ae98633cd50d8da03a2f4ed054af6b6f6cfc7d4b274674a2145dc9f323de6c

Contents?: true

Size: 1.56 KB

Versions: 36

Compression:

Stored size: 1.56 KB

Contents

require 'spec_helper'

class NoMethodClass < ExplicitDelegator
end

class OneMethodClass < ExplicitDelegator
  enforce_definitions :one
end

class TwoMethodClass < ExplicitDelegator
  enforce_definitions :one, :two
end

class Parent < ExplicitDelegator
  enforce_definitions :parent_method, :shared_method
end

class Child < Parent
  enforce_definitions :child_method, :shared_method
end

describe ExplicitDelegator do
  obj_none = OpenStruct.new({})
  obj_one = OpenStruct.new({one: 1})
  obj_two = OpenStruct.new({one: 1, two: 2})

  describe NoMethodClass do
    it "should not raise any exceptions" do
      NoMethodClass.new(obj_none)
      NoMethodClass.new(obj_one)
      NoMethodClass.new(obj_two)
    end
  end

  describe OneMethodClass do
    it "should only raise an exeption when the :one method is not defined" do
      expect { OneMethodClass.new(obj_none) }.to raise_error
      OneMethodClass.new(obj_one)
      OneMethodClass.new(obj_two)
    end
  end

  describe TwoMethodClass do
    it "should only raise an exception when either the :one or :two methods are not defined" do
      expect { TwoMethodClass.new(obj_none) }.to raise_error
      expect { TwoMethodClass.new(obj_one) }.to raise_error
      OneMethodClass.new(obj_two)
    end
  end

  describe '::enforce_definitions' do
    it 'should raise a runtime error with a list of required methods (including inherited methods, unduplicated)' do
      expect { Child.new(OpenStruct.new) }.to raise_error(RuntimeError, 'Methods required to use Child: [:parent_method, :shared_method, :child_method]')
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
woople-theme-0.10.0 spec/lib/explicit_delegator_spec.rb
woople-theme-0.9.0 spec/lib/explicit_delegator_spec.rb
woople-theme-0.8.19 spec/lib/explicit_delegator_spec.rb
woople-theme-0.8.18 spec/lib/explicit_delegator_spec.rb
woople-theme-0.8.17 spec/lib/explicit_delegator_spec.rb
woople-theme-0.8.16 spec/lib/explicit_delegator_spec.rb
woople-theme-0.8.15 spec/lib/explicit_delegator_spec.rb
woople-theme-0.8.14 spec/lib/explicit_delegator_spec.rb
woople-theme-0.8.13 spec/lib/explicit_delegator_spec.rb
woople-theme-0.8.12 spec/lib/explicit_delegator_spec.rb
woople-theme-0.8.11 spec/lib/explicit_delegator_spec.rb
woople-theme-0.8.10 spec/lib/explicit_delegator_spec.rb
woople-theme-0.8.9 spec/lib/explicit_delegator_spec.rb
woople-theme-0.8.8 spec/lib/explicit_delegator_spec.rb
woople-theme-0.8.7 spec/lib/explicit_delegator_spec.rb
woople-theme-0.8.6 spec/lib/explicit_delegator_spec.rb
woople-theme-0.8.5 spec/lib/explicit_delegator_spec.rb
woople-theme-0.8.4 spec/lib/explicit_delegator_spec.rb
woople-theme-0.8.3 spec/lib/explicit_delegator_spec.rb
woople-theme-0.8.2 spec/lib/explicit_delegator_spec.rb