Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to write Minitest spec for ApplicationHelper?
    primarykey
    data
    text
    <p>I know how to write the following style of test for Minitest...</p> <pre> require "minitest_helper" class ApplicationHelperTest &lt; ActionView::TestCase def test_nav_element_for_current_page self.stub(:current_page?, true) do nav_element('Home', '#').must_equal( '&lt;li class="active">&lt;a href="#">Home&lt;/li&gt;') end end def test_nav_element_for_non_current_page self.stub(:current_page?, false) do nav_element('Home', '#').must_equal( '&lt;li&gt;&lt;a href="#">Home&lt;/li&gt;') end end end </pre> <p>...but I want to write it in spec format. Here is what I have tried, but it does not work:</p> <pre> require "minitest_helper" describe ApplicationHelper do it "nav_element for current page" do self.stub(:current_page?, true) do nav_element('Home', '#').must_equal( '&lt;li class="active">&lt;a href="#">Home&lt;/li&gt;') end end it "nav_element for non-current page" do self.stub(:current_page?, false) do nav_element('Home', '#').must_equal( '&lt;li&gt;&lt;a href="#">Home&lt;/li&gt;') end end end </pre> <p>How do I tell Minitest that <code>ApplicationHelper</code> should automatically include <code>ActionView::TestCase</code>? I've tried several things, with no luck yet.</p> <p>Just for background, <code>application_helper.rb</code> contains:</p> <pre> 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 </pre> <p>I am using these bundled gems:</p> <pre> * rails (3.2.6) * minitest (3.2.0) * minitest-rails (0.1.0.alpha.20120525143907 7733031) </pre> <p>(Please note that this is the head version of <code>minitest_rails</code> (https://github.com/blowmage/minitest-rails).)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload