Moving on to the next Cucumber feature, I need to implement RSS feeds. First up is the RSS feed for the meals:
It is nice that, once a project has reached a certain point, one or two steps are already defined when starting on a new feature or scenario. The "Given" step of 20 yummy meals is already working, so I am able to get right down to business of accessing the RSS feed. Since I have yet to define that action in the Sinatra application, I am done with my outside, Cucumber work and am ready to dive into the inside, driven by RSpec work.
In the legacy Rails app (and the legacy baked-from-XML version before it), the RSS feed was named
main.rss
. To keep disruption to a minimum, I will keep that name, which means that I first drive RSS implementation with this example:describe "GET /main.rss" doImplementation of this simple example is predictably simple:
it "should respond OK" do
get "/main.rss"
last_response.should be_ok
end
end
get '/main.rss' doBefore switching to a RSS builder library, I implement a simple string bare bones RSS feed. This is a simpler step than going straight for the RSS builder. Simpler, smaller steps make for fewer things that can go wrong moving to subsequent steps, making for a smoother overall development process.
""
end
The example that I use to drive the bare bones RSS feed is:
it "should be the meals rss feed" doAnd the bare bones RSS feed that implements this example is:
get "/main.rss"
last_response.
should have_selector("channel title",
:content => "EEE Cooks: Meals")
end
get '/main.rss' doWith that example passing, I will give the built-in ruby library
"<channel><title>EEE Cooks: Title</title></channel>"
end
RSS:Maker
a try for building the real RSS feed. I convert the bare bones string version to:get '/main.rss' doWhen I run the spec, however, I get this failure:
content_type "application/rss+xml"
rss = RSS::Maker.make("2.0") do |maker|
maker.channel.title = "EEE Cooks: Title"
end
rss.to_s
end
2)OK, I guess I can understand that those two attributes are needed, so I add them:
RSS::NotSetError in 'eee GET /main.rss should be the meals rss feed'
required variables of maker.channel are not set: link, description
./eee.rb:40:in `GET /main.rss'
get '/main.rss' doWhich makes the spec pass again.
content_type "application/rss+xml"
rss = RSS::Maker.make("2.0") do |maker|
maker.channel.title = "EEE Cooks: Title"
maker.channel.link = "http://www.eeecooks.com/"
maker.channel.description = "Meals from a Family Cookbook"
end
rss.to_s
end
That is a good stopping point for today. Tomorrow I will build up the items in the RSS feed by pulling them from CouchDB.
No comments:
Post a Comment