Rails control block - helper with content_for

module ApplicationHelper

  def title(page_title, show_title = true)
    content_for(:title) do 
      page_title.to_s
    end
    @show_title = show_title
  end

end

Does anyone know how to test this helper using a test module?

+3
source share
1 answer

For any auxiliary testing in rails, you always start in tests / units / helpers.

Since this is ApplicationHelper, use a file named application_helper_test.rb

In this file you can have something like

 
 test "displays page title" do
    assert_equal "April 2010", title("April 2010", false)
  end

You can test everything that returns in the helper by simply calling the method as usual, and the statement of something is sent back.

Not knowing what you are doing, personally, there are too many in this method, but it can only be me.

, page_title, "show_title", . , " "?

0

Source: https://habr.com/ru/post/1773030/


All Articles