Sha256: ba2b8e31d17d208a3731301eb7570e21eca92a1c6a770b75fd49316ee6c9be1d

Contents?: true

Size: 1.46 KB

Versions: 8

Compression:

Stored size: 1.46 KB

Contents

require 'rspec'
require 'hyperion/aux/util'

class Hyperion
  describe Util do
    describe '::nil_if_error' do
      it 'catches StandardErrors in the block' do
        expect(Util.nil_if_error { raise 'oops' }).to be_nil
      end
      it 'does not catch Exceptions in the block' do
        expect{Util.nil_if_error { raise Exception }}.to raise_error Exception
      end
    end

    describe '::guard' do
      it 'raises a BugException if the value is invalid' do
        expect{Util.guard_param(7, 'a string', String)}.to report 'You passed me 7, which is not a string'
        expect{Util.guard_param('foo', 'any old number', Numeric)}.to report 'You passed me "foo", which is not any old number'
        expect{Util.guard_param(:zero, 'callable') { |x| x.respond_to?(:call) }}.to report 'You passed me :zero, which is not callable'
      end

      def report(msg)
        raise_error BugError, msg
      end
    end

    describe '::callcc' do
      it 'returns the value of the block if the continuation is not invoked' do
        v = Util.callcc { |_ret| 42 }
        expect(v).to eql 42
      end
      it 'returns the argument if the continuation is invoked' do
        v = Util.callcc { |ret| ret.call(99); 42 }
        expect(v).to eql 99
      end
      it 'raises an error if the continuation is invoked outside of the block' do
        cont = nil
        Util.callcc { |ret| cont = ret }
        expect { cont.call(99) }.to raise_error /continuation/
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
hyperion_http-0.6.0 spec/lib/hyperion/aux/util_spec.rb
hyperion_http-0.5.0 spec/lib/hyperion/aux/util_spec.rb
hyperion_http-0.3.0 spec/lib/hyperion/aux/util_spec.rb
hyperion_http-0.2.4 spec/lib/hyperion/aux/util_spec.rb
hyperion_http-0.2.3 spec/lib/hyperion/aux/util_spec.rb
hyperion_http-0.2.2 spec/lib/hyperion/aux/util_spec.rb
hyperion_http-0.2.1 spec/lib/hyperion/aux/util_spec.rb
hyperion_http-0.1.9 spec/lib/hyperion/aux/util_spec.rb