diff options
author | Joshua Peek <josh@joshpeek.com> | 2008-04-19 13:06:57 -0500 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2008-04-19 13:08:24 -0500 |
commit | 17d4164a16e5fe7b252375211424a2999a331291 (patch) | |
tree | 772695335b861e70caa15d92cd77ca568406cb7f /actionpack/test/template/test_test.rb | |
parent | ef4c65088fb907fc819e6b5d83d284c38cdaabfc (diff) | |
download | rails-17d4164a16e5fe7b252375211424a2999a331291.tar.gz rails-17d4164a16e5fe7b252375211424a2999a331291.tar.bz2 rails-17d4164a16e5fe7b252375211424a2999a331291.zip |
Introduce ActionView::TestCase for testing view helpers.
Diffstat (limited to 'actionpack/test/template/test_test.rb')
-rw-r--r-- | actionpack/test/template/test_test.rb | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/actionpack/test/template/test_test.rb b/actionpack/test/template/test_test.rb new file mode 100644 index 0000000000..660f51b3be --- /dev/null +++ b/actionpack/test/template/test_test.rb @@ -0,0 +1,56 @@ +require 'abstract_unit' + +module PeopleHelper + def title(text) + content_tag(:h1, text) + end + + def homepage_path + people_path + end + + def homepage_url + people_url + end + + def link_to_person(person) + link_to person.name, person + end +end + +class PeopleHelperTest < ActionView::TestCase + def setup + ActionController::Routing::Routes.draw do |map| + map.people 'people', :controller => 'people', :action => 'index' + map.connect ':controller/:action/:id' + end + end + + def test_title + assert_equal "<h1>Ruby on Rails</h1>", title("Ruby on Rails") + end + + def test_homepage_path + assert_equal "/people", homepage_path + end + + def test_homepage_url + assert_equal "http://test.host/people", homepage_url + end + + uses_mocha "link_to_person" do + def test_link_to_person + person = mock(:name => "David") + expects(:mocha_mock_path).with(person).returns("/people/1") + assert_equal '<a href="/people/1">David</a>', link_to_person(person) + end + end +end + +class CrazyHelperTest < ActionView::TestCase + tests PeopleHelper + + def test_helper_class_can_be_set_manually_not_just_inferred + assert_equal PeopleHelper, self.class.helper_class + end +end |