Sha256: 6682f61660904c0ce463da9bc0e6297b33d31dd4b674717b465518c799a7569a

Contents?: true

Size: 1.38 KB

Versions: 3

Compression:

Stored size: 1.38 KB

Contents

require 'rspec_syntax'
require 'pathname'

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

3 entries across 3 versions & 1 rubygems

Version Path
wyrm-0.4.2 spec/core_extensions_spec.rb
wyrm-0.4.1 spec/core_extensions_spec.rb
wyrm-0.4.0 spec/core_extensions_spec.rb