jeff @ dallien.net
April 25, 2010 15:35
I wrote this post quite a while ago but never published it, I guess because I was planning to add more details. Development on Elementor seems to have stalled so maybe there are better ways out there now, but I still like how it works.
During a recent project to learn about the Sinatra framework, I needed a way to test the generated RSS feed. While looking into a Sinatra equivalent of has_tag from RSpec on Rails, I came across Elementor. This turned out to work well for both the view and RSS feed testing.
Instead of describing the CSS selectors in each test, with Elementor one can give them meaningful names in a before :each block and the tests can just refer to the names. Here is an example:
@page = elements(:from => :do_get, :as => :xml) do |tag|
tag.items 'item'
tag.guids 'guid'
tag.links 'item/link'
end
end
def do_get
get "/feed", 'feeds' => ["http://feed1.test/posts.xml",
"http://feed2.test/posts.xml"]
response.body
end
With the descriptions of each tag out of the way, the tests can be written very clearly:
it "should repeat the items' link field in the combined feed" do
@page.links.size.should == 3
@page.links[0].inner_text.should == "LINK"
end