ruby on rails - How to write Minitest spec for ApplicationHelper? -


i know how write following style of test minitest...

 require "minitest_helper" class applicationhelpertest < actionview::testcase def test_nav_element_for_current_page self.stub(:current_page?, true) 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) nav_element('home', '#').must_equal( '<li><a href="#">home</li>') end end end 

...but want write in spec format. here have tried, not work:

 require "minitest_helper" describe applicationhelper "nav_element current page" self.stub(:current_page?, true) nav_element('home', '#').must_equal( '<li class="active"><a href="#">home</li>') end end "nav_element non-current page" self.stub(:current_page?, false) nav_element('home', '#').must_equal( '<li><a href="#">home</li>') end end end 

how tell minitest applicationhelper should automatically include actionview::testcase? i've tried several things, no luck yet.

just 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 using these bundled gems:

 * rails (3.2.6) * minitest (3.2.0) * minitest-rails (0.1.0.alpha.20120525143907 7733031) 

(please note head version of minitest_rails (https://github.com/blowmage/minitest-rails).)

minitest::rails didn't implement actionview::testcase until morning. bringing attention! :)

this fix in 0.1 release. now, change gemfile , link minitest-rails against git repo:

gem "minitest-rails", :git => "git://github.com/blowmage/minitest-rails.git" 

edit: works now. code should following:

require "minitest_helper" describe applicationhelper "nav_element current page" # stub ruby! def self.current_page?(path); true; end nav_element('home', '#').must_equal( '<li class="active"><a href="#">home</a></li>') end "nav_element non-current page" def self.current_page?(path); false; end nav_element('home', '#').must_equal( '<li><a href="#">home</a></li>') end end 

that should need do. if have other problems please start discussion on mailing list. https://groups.google.com/group/minitest-rails


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -