Minitestの次のスタイルのテストの書き方を知っています...
「minitest_helper」が必要
クラスApplicationHelperTest<ActionView:: TestCase
def test_nav_element_for_current_page
self.stub(:current_page ?, true)do
nav_element('Home'、'#')。must_equal(
'<li class = "active"> <ahref = "#">ホーム</ li>')
終わり
終わり
def test_nav_element_for_non_current_page
self.stub(:current_page ?, false)do
nav_element('Home'、'#')。must_equal(
'<li> <ahref = "#">ホーム</ li>')
終わり
終わり
終わり
...でもスペック形式で書きたいです。これが私が試したものですが、機能しません:
「minitest_helper」が必要
ApplicationHelperの説明
それは「現在のページのnav_element」を実行します
self.stub(:current_page ?, true)do
nav_element('Home'、'#')。must_equal(
'<li class = "active"> <ahref = "#">ホーム</ li>')
終わり
終わり
それは「非現在のページのnav_element」を実行します
self.stub(:current_page ?, false)do
nav_element('Home'、'#')。must_equal(
'<li> <ahref = "#">ホーム</ li>')
終わり
終わり
終わり
ApplicationHelper自動的に含める必要があるMinitestにどのように伝えますActionView::TestCaseか?私はまだ運がないのに、いくつかのことを試しました。
背景として、application_helper.rb以下が含まれます。
モジュールApplicationHelper
def nav_element(text、path)
オプション={}
options [:class] ='active' if current_page?(path)
link_tag = content_tag(:a、text、href:path)
content_tag(:li、link_tag、options)
終わり
終わり
私はこれらのバンドルされた宝石を使用しています:
*レール(3.2.6) *ミニテスト(3.2.0) *ミニテストレール(0.1.0.alpha.20120525143907 7733031)
(これは(https://github.com/blowmage/minitest-rails)のヘッドバージョンであることに注意してくださいminitest_rails。)