Skip to content

Instantly share code, notes, and snippets.

@dyba
Created August 1, 2012 03:04
Show Gist options
  • Select an option

  • Save dyba/3223260 to your computer and use it in GitHub Desktop.

Select an option

Save dyba/3223260 to your computer and use it in GitHub Desktop.
Testing a helper method with a minimalist approach
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
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