Sha256: 6f6a4be1830aa54abd56e79d884e845d8c177653eee715e819dd5a6d0fe5da8e

Contents?: true

Size: 1.85 KB

Versions: 11

Compression:

Stored size: 1.85 KB

Contents

require 'test/unit'
require 'rscm/annotations'

module RSCM
  class Whatever
    attr_accessor :no_annotation

    ann :boo => "huba luba", :pip => "pip pip"
    attr_accessor :foo
  
    ann :desc => "bang bang"
    ann :tip => "a top tip"
    attr_accessor :bar, :zap, :titi
  end

  class Other
    attr_accessor :no_annotation

    ann :boo => "boo"
    ann :pip => "pip"
    attr_accessor :foo
  
    ann :desc => "desc", :tip => "tip"
    attr_accessor :bar, :zap
  end
  
  class Subclass < Other
    ann :desc => "desc", :tip => "tip"
    attr_accessor :other
  end

  class AnnotationsTest < Test::Unit::TestCase
    def test_should_handle_annotations_really_well
      assert_equal("huba luba", Whatever.foo[:boo])
      assert_equal("pip pip", Whatever.foo[:pip])

      assert_nil(Whatever.bar[:pip])
      assert_equal("bang bang", Whatever.bar[:desc])
      assert_equal("a top tip", Whatever.bar[:tip])

      assert_equal("bang bang", Whatever.zap[:desc])
      assert_equal("a top tip", Whatever.zap[:tip])

      assert_equal("boo", Other.foo[:boo])
      assert_equal("pip", Other.foo[:pip])

      assert_nil(Whatever.bar[:pip])
      assert_equal("desc", Other.bar[:desc])
      assert_equal("tip", Other.bar[:tip])

      assert_equal("desc", Other.zap[:desc])
      assert_equal("tip", Other.zap[:tip])
    end

    def test_should_inherit_attribute_annotations
      assert_equal("boo", Subclass.foo[:boo])
      assert_equal({:boo => "boo", :pip => "pip"}, Subclass.send("foo"))
      assert_equal({}, Whatever.send("no_annotation"))
    end
    
    def test_should_get_annotations_from_object
      assert_equal({:boo => "huba luba", :pip => "pip pip"}, Whatever.new.anns("foo"))
    end
    
    def test_should_get_annotations_from_class
      assert_equal(["@bar", "@foo", "@no_annotation", "@other", "@zap"], Subclass.new.__attr_accessors)
    end
    
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
rscm-0.3.5 test/rscm/annotations_test.rb
rscm-0.3.3 test/rscm/annotations_test.rb
rscm-0.3.2 test/rscm/annotations_test.rb
rscm-0.3.0 test/rscm/annotations_test.rb
rscm-0.3.4 test/rscm/annotations_test.rb
rscm-0.3.1 test/rscm/annotations_test.rb
rscm-0.3.10 test/rscm/annotations_test.rb
rscm-0.3.9 test/rscm/annotations_test.rb
rscm-0.3.6 test/rscm/annotations_test.rb
rscm-0.3.7 test/rscm/annotations_test.rb
rscm-0.3.8 test/rscm/annotations_test.rb