I'm trying to build some unit tests for testing my Rails helpers, but I can never remember how to access them. Annoying. Suggestions?
2.7 The Rails Test Runner Or we can run a single test file by passing the bin/rails test command the filename containing the test cases. This will run all test methods from the test case. You can also run a particular test method from the test case by providing the -n or --name flag and the test's method name.
The currently accepted way to test rails controllers is by sending http requests to your application and writing assertions about the response. Rails has ActionDispatch::IntegrationTest which provides integration tests for Minitest which is the Ruby standard library testing framework.
A helper is a method that is (mostly) used in your Rails views to share reusable code. Rails comes with a set of built-in helper methods. One of these built-in helpers is time_ago_in_words . This method is helpful whenever you want to display time in this specific format.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With