RSpec
From RuHL’s point, testing views should be done raw. There’s no point in rendering the view in an automated test. All the automated tests won’t tell you if it doesn’t look right in Internet Explorer versus Firefox versus Safari so why bother wasting the time to render the views? What you simply need to do is to test that the appropriate attributes are on the appropriate tags. Your presenter tests should cover the various outcomes of those methods based on the current system state. Your presenters handle the more complicated tests in a simpler environment.
Back to why you’re here: to make testing the views easier. In version 0.19.0, RuHL introduces the Ruhl::Rspec::Rails and Ruhl::Rspec::Sinatra modules. What they do is provide you with a simple way to test your data-ruhl attributes:
Here’s some HTML from (GoGoPlot), sprinkled with RuHL:
<div class="single_box">
<h2>Topic: <span data-ruhl="_swap: name"/></h2>
<div id="chart">
<img data-ruhl="src: chart_period"/>
</div>
</div>
require 'spec_helper'
describe "/topics/show.html.ruhl" do
include Ruhl::Rspec::Rails
it "calls to replace name" do
data_ruhl('div.single_box > h2 > span').should == "_swap: name"
end
it "calls chart_period" do
data_ruhl('div#chart > img').should == "src: chart_period"
end
end
As you can see the data_ruhl method will find the tag based on the css selector and return the value of the data-ruhl attribute.
