我知道如何为 Minitest 编写以下测试风格...
需要“minitest_helper”
类 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="#">首页</li>')
结尾
结尾
def test_nav_element_for_non_current_page
self.stub(:current_page?, false) 做
nav_element('Home', '#').must_equal(
'<li><a href="#">首页</li>')
结尾
结尾
结尾
...但我想以规范格式编写它。这是我尝试过的,但它不起作用:
需要“minitest_helper”
描述 ApplicationHelper 做
它“当前页面的导航元素”做
self.stub(:current_page?, true) 做
nav_element('Home', '#').must_equal(
'<li class="active"><a href="#">首页</li>')
结尾
结尾
它“用于非当前页面的导航元素”做
self.stub(:current_page?, false) 做
nav_element('Home', '#').must_equal(
'<li><a href="#">首页</li>')
结尾
结尾
结尾
我如何告诉 MinitestApplicationHelper应该自动包含ActionView::TestCase?我已经尝试了几件事,但还没有运气。
仅作为背景,application_helper.rb包含:
模块 ApplicationHelper
def nav_element(文本,路径)
选项 = {}
options[:class] = 'active' if current_page?(path)
link_tag = content_tag(:a, text, href: 路径)
content_tag(:li, link_tag, 选项)
结尾
结尾
我正在使用这些捆绑的宝石:
* 导轨 (3.2.6) * 迷你测试 (3.2.0) * minitest-rails (0.1.0.alpha.20120525143907 7733031)
(请注意,这是minitest_rails(https://github.com/blowmage/minitest-rails) 的头部版本。)