Sha256: 3ccd3bd9bc6726bc12292081a0db80469173e9520dd941acab2493a5ae704663

Contents?: true

Size: 1.28 KB

Versions: 14

Compression:

Stored size: 1.28 KB

Contents

require 'spec_helper'

RSpec.describe Yaks::Util do
  include Yaks::Util

  describe '#Resolve' do
    it 'should return non-proc-values' do
      expect(Resolve('foo')).to eql 'foo'
    end

    it 'should resolve a proc' do
      expect(Resolve(->{ 123 })).to eql 123
    end

    it 'should resolve the proc in the given context' do
      expect(Resolve(->{ upcase }, 'foo')).to eql 'FOO'
    end

    it 'should resolve a proc without context in the context it was lexically defined' do
      expect(Resolve(->{ self })).to be_a RSpec::Core::ExampleGroup
    end

    it 'should receive the context as an argument when it has an arity > 0' do
      expect(Resolve(->(s){ s.upcase }, 'foo')).to eql 'FOO'
    end

    it 'should work with method objects' do
      expect(Resolve('foo'.method(:upcase))).to eql 'FOO'
    end
  end

  describe '#camelize' do
    it 'should camelize' do
      expect(camelize('foo_bar_moo/baz/booz')).to eql 'FooBarMoo::Baz::Booz'
    end
  end

  describe '#underscore' do
    it 'should underscorize' do
      expect(underscore('FooBar::Baz-Quz::Quux')).to eql 'foo_bar/baz__quz/quux'
    end
  end

  describe '#slice_hash' do
    it '#should retain the given keys from a hash' do
      expect(slice_hash({a: 1, b:2, c:3}, :a, :c, :d)).to eql(a: 1, c:3)
    end
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
yaks-0.7.6 spec/unit/yaks/util_spec.rb
yaks-0.7.5 spec/unit/yaks/util_spec.rb
yaks-0.7.4 spec/unit/yaks/util_spec.rb
yaks-0.7.3 spec/unit/yaks/util_spec.rb
yaks-0.7.2 spec/unit/yaks/util_spec.rb
yaks-0.7.1 spec/unit/yaks/util_spec.rb
yaks-0.7.0 spec/unit/yaks/util_spec.rb
yaks-0.6.2 spec/unit/yaks/util_spec.rb
yaks-0.6.1 spec/unit/yaks/util_spec.rb
yaks-0.6.0 spec/unit/yaks/util_spec.rb
yaks-0.6.0.alpha.1 spec/unit/yaks/util_spec.rb
yaks-html-0.6.0.alpha yaks/spec/unit/yaks/util_spec.rb
yaks-0.6.0.alpha yaks/spec/unit/yaks/util_spec.rb
yaks-0.5.0 spec/unit/yaks/util_spec.rb