1 require File.dirname(__FILE__) + "/../../spec_helper"
4 describe Radiant::Taggable, "when included in a class or module" do
7 include Radiant::Taggable
11 include Radiant::Taggable
14 it "should add tag definition methods to the class" do
15 [TaggedClass, TaggedModule].each do |c|
16 c.should respond_to(:tag)
17 c.should respond_to(:desc)
21 it "should turn tag definitions into methods" do
22 [TaggedClass, TaggedModule].each do |c|
26 c.instance_methods.should include("tag:hello")
28 TaggedClass.new.send("tag:hello").should == "hello world"
31 it "should store tag descriptions filtered with Textile" do
32 [TaggedClass, TaggedModule].each do |c|
33 c.desc "A simple tag."
34 Radiant::Taggable.last_description.should == "<p>A simple tag.</p>"
38 it "should associate a tag description with the tag definition that follows it" do
39 [TaggedClass, TaggedModule].each do |c|
44 c.tag_descriptions['hello'].should =~ /Bonjour!/
45 Radiant::Taggable.last_description.should be_nil
49 it "should normalize leading whitespace in a tag description" do
50 Radiant::Taggable::Util.should_receive(:strip_leading_whitespace).twice.with(" Blah blah\n blah blah").and_return("blah")
51 [TaggedClass, TaggedModule].each do |c|
52 c.desc " Blah blah\n blah blah"
57 describe Radiant::Taggable, "when included in a module with defined tags" do
60 include Radiant::Taggable
62 desc %{This tag renders the text "just a test".}
67 desc %{This tag implements "Hello, world!".}
69 "Hello, #{ tag.attr['name'] || 'world' }!"
74 include Radiant::Taggable
76 desc %{Yet another test}
85 @object = TestObject.new
86 @tag_binding = OpenStruct.new('attr' => {"name" => "John"})
89 it "should have a collection of defined tags" do
90 MyTags.should respond_to(:tags)
91 MyTags.tags.should == ['hello', 'test']
94 it "should add tags to an included class" do
95 TestObject.should respond_to(:tags)
96 TestObject.tags.should == ['hello', 'test']
99 it "should merge tag descriptions with an included class" do
100 TestObject.tag_descriptions["test"].should == MyTags.tag_descriptions["test"]
103 it "should render a defined tag on an instance of an included class" do
104 @object.should respond_to(:render_tag)
105 @object.render_tag(:test, {}).should == "My new test"
108 it "should render a defined tag on an instance of an included class with a given tag binding" do
109 @object.render_tag(:hello, @tag_binding).should == "Hello, John!"
114 describe Radiant::Taggable::Util do
115 it "should normalize leading whitespace" do
118 I'm a really small paragraph that
119 happens to span two lines.
125 Let's try a small code example:
129 Nice job! It really, really, really
135 I'm a really small paragraph that
136 happens to span two lines.
142 Let's try a small code example:
146 Nice job! It really, really, really
148 Radiant::Taggable::Util.strip_leading_whitespace(markup).should == result