here = File.dirname(__FILE__)
require File.expand_path("#{here}/../spec_helper")
$: << File.expand_path("#{here}/../../web/")
require "article"
describe Article do
it "requires a name" do
lambda {
Article.new
}.should raise_error(ArgumentError)
a = Article.new(:name => "Foo")
assert { a.instance_variable_get(:@name) == "Foo" }
end
it "renders a name" do
a = Article.new(:name => "Foo")
a.to_html.should == "
/
end
it "toc contains each section's name and a link to its href" do
@article.to_html(:content_method_name => "table_of_contents", :prettyprint => true).should == <<-HTML
HTML
end
it "shows each section" do
@article.to_html(:content_method_name => "emit_sections", :prettyprint => true).should == <<-HTML
1. Steal Underpants
very important
2. ?
todo
3. Profit!
victory
HTML
end
end
describe "with subsections" do
before do
@article = Article.new(:name => "Food")
@article <<
Section.new(:name => "Breakfast") { p "very important" }.tap do |s|
s << Section.new(:name => "Coffee") { p "french roast" }
s << Section.new(:name => "Eggs") { p "scrambled" }
end
end
it "toc contains each section's name and a link to its href" do
@article.to_html(:content_method_name => "table_of_contents", :prettyprint => true).should == <<-HTML
HTML
end
it "shows each section" do
@article.to_html(:content_method_name => "emit_sections", :prettyprint => true).should == <<-HTML
1. Breakfast
very important
1.1. Coffee
french roast
1.2. Eggs
scrambled
HTML
end
end
it "can be created using nested taps and adds" do
article = Article.new(:name => "food").tap { |a|
a.add(:name => "fruit") {
text "sweet and fibrous"
}.tap { |s|
s.add(:name => "apple") {
text "crunchy"
}.tap { |s|
s.add(:name => "granny smith") {
text "green"
}
s.add(:name => "red delicious") {
text "red"
}
}
s.add(:name => "banana") {
text "yellow"
}
}
a.add(:name => "bread") {
text "chewy and grainy"
}.tap { |s|
s.add(:name => "sourdough") {
text "tangy"
}
}
}
article.to_html(:prettyprint => true).should == <<-HTML
food
1. fruit
sweet and fibrous
1.1. apple
crunchy
1.1.1. granny smith
green
1.1.2. red delicious
red
1.2. banana
yellow
2. bread
chewy and grainy
HTML
end
end