Testing flash message method in application_helper.rb code in Rails -
i'm bit new test driven development, , want learn how cover code possible when make more complex apps in rails, i'll able prevent bugs introduced.
i have code in application_helper.rb
styles flash messages twitter bootstrap classes , want write test code have written if changes i'll know before becomes bit issue.
#application_helper.rb module applicationhelper def flash_class(type) case type when :alert "alert-error" when :notice "alert-info" else "" end end end
my application.html.erb
view has following code show flash message using helper method above.
#application.html.erb <% flash.each |type, message| %> <div class="alert <%= flash_class type %>"> <button type="button" class="close" data-dismiss="alert">×</button> <%= message %> </div> <% end %>
what type of test write test code in application_helper.rb
works, , how go writing test? i'm using shoulda-context gem test writing, don't care if tests written in standard rails test_with_lots_of_underscores
style.
i using cloud9 write application ruby 1.9.3 (patch level 327) , rails 3.2.13. repoosiroty app i'm working on in github repository
how this:
class applicationhelpertest < test::unit::testcase context "flash_class" should "map :alert symbol 'alert-error' string" assert_equal 'alert-error', flash_class(:alert) end should "map :notice symbol 'alert-info' string" assert_equal 'alert-info', flash_class(:notice) end should "map else empty string" assert_equal '', flash_class(:blah) end end end
Comments
Post a Comment