From: dezawa Date: 2015-06-12T19:22:29+09:00 Subject: [ruby-list:50169] helperのテスト(ActionView::TestCase) 出沢です rails(4)の話なのですが。。。。。 View用に作ったHelperのリファクタリングをすることになり、 作られていなかったHelper用のtestを書こうとして嵌っています。 Controlleのテストの説明は至る所で見つかるのですが、 ActionView::TestCase や ActionView::Base を使ってのテストの 情報がhitしてくれません。 http://qiita.com/t_oginogin/items/7654190749dc6fcce732 や http://ruby.studio-kingdom.com/rails/guides/testing#10 を 参考に下の様なコードを書いてみたのですがいずれも NoMethodError: undefined method `host' for nil:NilClass controller の指定が無いからだろうと思うのですが、form_tag の 引数に :controller => FooController.new を追加しても同じエラーと なります。 どのようにすれば ViewのHelperのtestが書けるのかご指導ください。 <<<<< 1 # -*- coding: utf-8 -*- require 'test_helper' class ActionButtomHelperTest < ActionView::TestCase include ActionButtonHelper must "form_buttom option なし" do assert_equal "", form_tag(:action => :index) end end >>>> <<<<< 2 class ActionButtomHelperTest < ActionView::TestCase include ActionButtonHelper class TestHelper < ActionView::Base include ActionButtonHelper end def setup @helper = TestHelper.new end must "form_buttom option なし" do assert_equal "", @helper.form_tag(:action => :index) end end