1 require File.dirname(__FILE__) + "/../spec_helper"
3 describe Annotatable, "when included in a class" do
8 it "should add the annotate method to a class" do
9 BasicAnnotation.should respond_to(:annotate)
13 describe Annotatable, "with an annotation added to a class" do
14 class AnnotationsAdded
19 it "should add class accessor methods of the given name for the annotation" do
20 AnnotationsAdded.should respond_to(:description)
21 AnnotationsAdded.should respond_to(:description=)
24 it "should add instance accessor methods of the given name for the annotation" do
25 @a = AnnotationsAdded.new
26 @a.should respond_to(:description)
27 @a.should respond_to(:description=)
30 it "should set the value of the annotation when called with a parameter" do
31 AnnotationsAdded.description "test"
32 AnnotationsAdded.description.should == "test"
35 it "should set the value of the annotation when assigned directly" do
36 AnnotationsAdded.description = "test"
37 AnnotationsAdded.description.should == "test"
40 it "should set the value of the annotation when called with a parameter on an instance" do
41 AnnotationsAdded.new.description "test"
42 AnnotationsAdded.description.should == "test"
45 it "should set the value of the annotation when assigned directly on an instance" do
46 AnnotationsAdded.new.description = "test"
47 AnnotationsAdded.description.should == "test"
51 describe Annotatable, "with annotations defined on a parent class" do
54 annotate :description, :url
55 annotate :another, :inherit => true
56 description "A parent class"
57 url "http://test.host"
58 another "I'm inherited!"
61 class ChildClass < ParentClass
64 class OverridingClass < ParentClass
65 another "I'm not inherited!"
68 it "should receive all parent annotations" do
69 [:description, :url, :another].each do |method|
70 ChildClass.should respond_to(method)
74 it "should inherit the parent class' values for inherit annotations" do
75 ChildClass.another.should == "I'm inherited!"
78 it "should not inherit values for non-inherited annotations" do
79 ChildClass.description.should be_nil
80 ChildClass.url.should be_nil
83 it "should override inherited values when annotated in a child class" do
84 OverridingClass.another.should == "I'm not inherited!"