Sha256: 0c853a24b9f8deb9efebf1f2a2c4ee3fc76f71f0247d71686dc960a65dbec472

Contents?: true

Size: 1.36 KB

Versions: 2

Compression:

Stored size: 1.36 KB

Contents

require 'rspec_syntax'

require Pathname(__dir__) + '../lib/wyrm/core_extensions.rb'

describe Method do
  describe '#kwargs_as_hash' do
    it 'empty for no keywords' do
      inst = Class.new do
        def without_kwargs( one, two )
          @kwargs = method(__method__).kwargs_as_hash(binding)
        end
      end.new
      inst.without_kwargs :one, :two
      inst.instance_variable_get('@kwargs').should == {}
    end

    it 'gives back hash of keywords' do
      inst = Class.new do
        def with_kwargs( one: 'one', two: 'two')
          @kwargs = method(__method__).kwargs_as_hash(binding)
        end
      end.new

      inst.with_kwargs
      inst.instance_variable_get('@kwargs').should == {one: 'one', two: 'two'}
    end

    it 'has correct values' do
      inst = Class.new do
        def with_kwargs( one: 'one', two: 'two')
          @kwargs = method(__method__).kwargs_as_hash(binding)
        end
      end.new

      inst.with_kwargs( one: 1, two: 2 )
      inst.instance_variable_get('@kwargs').should == {one: 1, two: 2}
    end

    it 'gets some default values' do
      inst = Class.new do
        def with_kwargs( one: 'one', two: 'two')
          @kwargs = method(__method__).kwargs_as_hash(binding)
        end
      end.new

      inst.with_kwargs( one: 1 )
      inst.instance_variable_get('@kwargs').should == {one: 1, two: 'two'}
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
wyrm-0.3.3 spec/core_extensions_spec.rb
wyrm-0.3.2 spec/core_extensions_spec.rb