How do I test helpers in Rails?

后端 未结 5 1492
北海茫月
北海茫月 2021-02-03 18:24

I\'m trying to build some unit tests for testing my Rails helpers, but I can never remember how to access them. Annoying. Suggestions?

5条回答
  •  庸人自扰
    2021-02-03 19:03

    In rails 3 you can do this (and in fact it's what the generator creates):

    require 'test_helper'
    
    class YourHelperTest < ActionView::TestCase
      test "should work" do
        assert_equal "result", your_helper_method
      end
    end
    

    And of course the rspec variant by Matt Darby works in rails 3 too

提交回复
热议问题