Created
August 1, 2012 03:04
-
-
Save dyba/3223260 to your computer and use it in GitHub Desktop.
Testing a helper method with a minimalist approach
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module ApplicationHelper | |
| def highlight_tag_if(condition, tag, &block) | |
| if condition | |
| content_tag tag, :class => 'hilite', &block | |
| else | |
| content_tag tag, &block | |
| end | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'minitest/autorun' | |
| require 'minitest/spec' | |
| require_relative '../../app/helpers/application_helper' | |
| class ApplicationHelperSpec < MiniTest::Spec | |
| describe "#highlight_tag_if" do | |
| describe "when the condition is true" do | |
| it "highlights the tag" do | |
| extend ApplicationHelper | |
| highlight_tag_if(true, :th) { }.must_match %r{^<th class='hilite'>.*</th>$} | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment