I’m starting to learn Rails. I’m using Rails 3.
In my simple App, I have the following code:
<% @tasks.each do |task| %>
...
<td><%= friendly_estimate task.estimate, { :compact => true } %></td>
...
<% end %>
The mission for me is that I would like to test if the view really sends the :compact option to my method to ensure that the estimate is shown currently.
So the spec kinda is:
Estimates must be shown in compact view, on lists pages
I’m new to testing in Ruby, and totally new to View testing, so I hope someone can help out, or point me in the right direction.
Thanks 🙂
Although you can test for the use of the compact option being sent to the
friendly_estimatehelper method using a variety of techniques, the primary purpose of a functional test is not to verify the implementation, but the output.If you examine the output you should be able to determine if the proper formatting was used. The easiest way to do this is to insert some kind of CSS class that can be identified in the functional test. For instance, wrap your compact format in
<span class="compact">and then test for it using a CSS selector using assert_select:The functional tests should be ignorant of the implementation details to avoid binding them too strongly. This way you can refactor your models and helpers at will, yet still verify they are producing the correct output.