Sha256: e7b22641f54491d386d193ae1466e970145fcb719500d0f886518b2014fbfea6

Contents?: true

Size: 1.4 KB

Versions: 1

Compression:

Stored size: 1.4 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

{:must_be_kind_of => false, :must_be_a => false, :must_be_nil_or_kind_of => true}.each do |method, nil_allowed|
  describe TypeSafe, ".#{method}" do
    it "should be included in Object class" do
      Object.new.should respond_to(method)
    end
    it "should recognize a simple type" do
      lambda{1.send method, Fixnum}.should_not raise_error(TypeCheckError)
    end
    it "should recognize parent classes" do
      lambda{self.send method, Object}.should_not raise_error(TypeCheckError)
    end
    it "should raise a TypeCheckError for mismatching types" do
      lambda{"1".send method, Fixnum}.should raise_error(TypeCheckError)
    end
    it "should raise a RuntimeError if the given match is not a Class" do
      lambda{"1".send method, "Fixnum"}.should raise_error(RuntimeError)
      lambda{"1".send method, "Fixnum"}.should_not raise_error(TypeCheckError)
    end
    
    it "should #{nil_allowed ? 'not ' : ''}raise a TypeCheckError for mismatching types on nil" do
      lambda{nil.send method, Fixnum}.send nil_allowed ? :should_not : :should, raise_error(TypeCheckError)
    end
    
    it "should recognize included modules" do
      module TestModule ; end
      class TestClass
        include TestModule
      end
      o = TestClass.new
      lambda{o.send method, TestModule}.should_not raise_error(TypeCheckError)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tsalzer-typesafe-0.0.0 spec/typesafe_spec.rb