I know how to write the following style of test for Minitest...
require "minitest_helper" class ApplicationHelperTest < ActionView::TestCase def test_nav_element_for_current_page self.stub(:current_page?, true) do nav_element('Home', '#').must_equal( '<li class="active"><a href="#">Home</li>') end end def test_nav_element_for_non_current_page self.stub(:current_page?, false) do nav_element('Home', '#').must_equal( '<li><a href="#">Home</li>') end end end
...but I want to write it in spec format. Here is what I have tried, but it does not work:
require "minitest_helper" describe ApplicationHelper do it "nav_element for current page" do self.stub(:current_page?, true) do nav_element('Home', '#').must_equal( '<li class="active"><a href="#">Home</li>') end end it "nav_element for non-current page" do self.stub(:current_page?, false) do nav_element('Home', '#').must_equal( '<li><a href="#">Home</li>') end end end
How do I tell Minitest that ApplicationHelper
should automatically include ActionView::TestCase
? I've tried several things, with no luck yet.
Just for background, application_helper.rb
contains:
module ApplicationHelper def nav_element(text, path) options = {} options[:class] = 'active' if current_page?(path) link_tag = content_tag(:a, text, href: path) content_tag(:li, link_tag, options) end end
I am using these bundled gems:
* rails (3.2.6) * minitest (3.2.0) * minitest-rails (0.1.0.alpha.20120525143907 7733031)
(Please note that this is the head version of minitest_rails
(https://github.com/blowmage/minitest-rails).)