aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorDavid Chelimsky <dchelimsky@gmail.com>2010-05-25 23:12:09 -0500
committerJosé Valim <jose.valim@gmail.com>2010-05-26 15:58:53 +0200
commit9ae7e93920999511447179f7c44e4654ebfda476 (patch)
tree42ca9a0e1fc78d239af63b74947c48c9f863cc98 /actionpack
parent7bd30b9585ec709cb56d26a54182e438bae00a08 (diff)
downloadrails-9ae7e93920999511447179f7c44e4654ebfda476.tar.gz
rails-9ae7e93920999511447179f7c44e4654ebfda476.tar.bz2
rails-9ae7e93920999511447179f7c44e4654ebfda476.zip
reorganize tests for AV::TC
- decouple tests from the test case class by moving them outside - split out more TestCase subs as cleaner way of avoiding bleed of class level concepts Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/test/template/test_case_test.rb278
1 files changed, 138 insertions, 140 deletions
diff --git a/actionpack/test/template/test_case_test.rb b/actionpack/test/template/test_case_test.rb
index 25dbc04ce1..a34bca8145 100644
--- a/actionpack/test/template/test_case_test.rb
+++ b/actionpack/test/template/test_case_test.rb
@@ -2,21 +2,23 @@ require 'abstract_unit'
require 'controller/fake_controllers'
module ActionView
- class TestCase
- module ATestHelper
- end
- module AnotherTestHelper
- def from_another_helper
- 'Howdy!'
- end
+ module ATestHelper
+ end
+
+ module AnotherTestHelper
+ def from_another_helper
+ 'Howdy!'
end
+ end
- module ASharedTestHelper
- def from_shared_helper
- 'Holla!'
- end
+ module ASharedTestHelper
+ def from_shared_helper
+ 'Holla!'
end
+ end
+
+ class TestCase
helper ASharedTestHelper
module SharedTests
@@ -29,175 +31,171 @@ module ActionView
end
end
end
+ end
- class GeneralViewTest < ActionView::TestCase
- include SharedTests
- test_case = self
+ class GeneralViewTest < ActionView::TestCase
+ include SharedTests
+ test_case = self
- test "works without testing a helper module" do
- assert_equal 'Eloy', render('developers/developer', :developer => stub(:name => 'Eloy'))
- end
+ test "works without testing a helper module" do
+ assert_equal 'Eloy', render('developers/developer', :developer => stub(:name => 'Eloy'))
+ end
- test "can render a layout with block" do
- assert_equal "Before (ChrisCruft)\n!\nAfter",
- render(:layout => "test/layout_for_partial", :locals => {:name => "ChrisCruft"}) {"!"}
- end
+ test "can render a layout with block" do
+ assert_equal "Before (ChrisCruft)\n!\nAfter",
+ render(:layout => "test/layout_for_partial", :locals => {:name => "ChrisCruft"}) {"!"}
+ end
- helper AnotherTestHelper
- test "additional helper classes can be specified as in a controller" do
- assert test_case.ancestors.include?(AnotherTestHelper)
- assert_equal 'Howdy!', from_another_helper
- end
+ helper AnotherTestHelper
+ test "additional helper classes can be specified as in a controller" do
+ assert test_case.ancestors.include?(AnotherTestHelper)
+ assert_equal 'Howdy!', from_another_helper
+ end
- test "determine_default_helper_class returns nil if name.sub(/Test$/, '').constantize resolves to a class" do
- assert_nil self.class.determine_default_helper_class("String")
- end
+ test "determine_default_helper_class returns nil if name.sub(/Test$/, '').constantize resolves to a class" do
+ assert_nil self.class.determine_default_helper_class("String")
+ end
- test "delegates notice to request.flash" do
- _view.request.flash.expects(:notice).with("this message")
- _view.notice("this message")
- end
+ test "delegates notice to request.flash" do
+ _view.request.flash.expects(:notice).with("this message")
+ _view.notice("this message")
+ end
- test "delegates alert to request.flash" do
- _view.request.flash.expects(:alert).with("this message")
- _view.alert("this message")
- end
+ test "delegates alert to request.flash" do
+ _view.request.flash.expects(:alert).with("this message")
+ _view.alert("this message")
end
+ end
- class ClassMethodsTest < ActionView::TestCase
- include SharedTests
- test_case = self
+ class ClassMethodsTest < ActionView::TestCase
+ include SharedTests
+ test_case = self
- tests ATestHelper
- test "tests the specified helper module" do
- assert_equal ATestHelper, test_case.helper_class
- assert test_case.ancestors.include?(ATestHelper)
- end
+ tests ATestHelper
+ test "tests the specified helper module" do
+ assert_equal ATestHelper, test_case.helper_class
+ assert test_case.ancestors.include?(ATestHelper)
+ end
- helper AnotherTestHelper
- test "additional helper classes can be specified as in a controller" do
- assert test_case.ancestors.include?(AnotherTestHelper)
- assert_equal 'Howdy!', from_another_helper
+ helper AnotherTestHelper
+ test "additional helper classes can be specified as in a controller" do
+ assert test_case.ancestors.include?(AnotherTestHelper)
+ assert_equal 'Howdy!', from_another_helper
- test_case.helper_class.module_eval do
- def render_from_helper
- from_another_helper
- end
+ test_case.helper_class.module_eval do
+ def render_from_helper
+ from_another_helper
end
- assert_equal 'Howdy!', render(:partial => 'test/from_helper')
end
+ assert_equal 'Howdy!', render(:partial => 'test/from_helper')
end
+ end
- class ATestHelperTest < ActionView::TestCase
- include SharedTests
- test_case = self
-
- test "inflects the name of the helper module to test from the test case class" do
- assert_equal ATestHelper, test_case.helper_class
- assert test_case.ancestors.include?(ATestHelper)
- end
-
- test "a configured test controller is available" do
- assert_kind_of ActionController::Base, controller
- assert_equal '', controller.controller_path
+ class HelperInclusionTest < ActionView::TestCase
+ module RenderHelper
+ def render_from_helper
+ render :partial => 'customer', :collection => @customers
end
+ end
- test "helper class that is being tested is always included in view instance" do
- # This ensure is a hidious hack to deal with these tests bleeding
- # methods between eachother
- begin
- self.class.helper_class.module_eval do
- def render_from_helper
- render :partial => 'customer', :collection => @customers
- end
- end
-
- @controller.controller_path = 'test'
+ helper RenderHelper
- @customers = [stub(:name => 'Eloy'), stub(:name => 'Manfred')]
- assert_match /Hello: EloyHello: Manfred/, render(:partial => 'test/from_helper')
+ test "helper class that is being tested is always included in view instance" do
+ @controller.controller_path = 'test'
- ensure
- self.class.helper_class.send(:remove_method, :render_from_helper)
- end
- end
+ @customers = [stub(:name => 'Eloy'), stub(:name => 'Manfred')]
+ assert_match /Hello: EloyHello: Manfred/, render(:partial => 'test/from_helper')
+ end
+ end
- test "no additional helpers should shared across test cases" do
- assert !test_case.ancestors.include?(AnotherTestHelper)
- assert_raise(NoMethodError) { send :from_another_helper }
+ class HelperExposureTest < ActionView::TestCase
+ helper(Module.new do
+ def render_from_helper
+ from_test_case
end
+ end)
+ test "is able to make methods available to the view" do
+ assert_equal 'Word!', render(:partial => 'test/from_helper')
+ end
- test "is able to use routes" do
- controller.request.assign_parameters(@routes, 'foo', 'index')
- assert_equal '/foo', url_for
- assert_equal '/bar', url_for(:controller => 'bar')
- end
+ def from_test_case; 'Word!'; end
+ helper_method :from_test_case
+ end
- test "is able to use named routes" do
- with_routing do |set|
- set.draw { |map| resources :contents }
- assert_equal 'http://test.host/contents/new', new_content_url
- assert_equal 'http://test.host/contents/1', content_url(:id => 1)
- end
- end
+ class ATestHelperTest < ActionView::TestCase
+ include SharedTests
+ test_case = self
- test "named routes can be used from helper included in view" do
- with_routing do |set|
- set.draw { |map| resources :contents }
- _helpers.module_eval do
- def render_from_helper
- new_content_url
- end
- end
+ test "inflects the name of the helper module to test from the test case class" do
+ assert_equal ATestHelper, test_case.helper_class
+ assert test_case.ancestors.include?(ATestHelper)
+ end
- assert_equal 'http://test.host/contents/new', render(:partial => 'test/from_helper')
- end
- end
+ test "a configured test controller is available" do
+ assert_kind_of ActionController::Base, controller
+ assert_equal '', controller.controller_path
+ end
- test "is able to render partials with local variables" do
- assert_equal 'Eloy', render('developers/developer', :developer => stub(:name => 'Eloy'))
- assert_equal 'Eloy', render(:partial => 'developers/developer',
- :locals => { :developer => stub(:name => 'Eloy') })
- end
+ test "no additional helpers should shared across test cases" do
+ assert !test_case.ancestors.include?(AnotherTestHelper)
+ assert_raise(NoMethodError) { send :from_another_helper }
+ end
- test "is able to render partials from templates and also use instance variables" do
- @controller.controller_path = "test"
+ test "is able to use routes" do
+ controller.request.assign_parameters(@routes, 'foo', 'index')
+ assert_equal '/foo', url_for
+ assert_equal '/bar', url_for(:controller => 'bar')
+ end
- @customers = [stub(:name => 'Eloy'), stub(:name => 'Manfred')]
- assert_match /Hello: EloyHello: Manfred/, render(:file => 'test/list')
+ test "is able to use named routes" do
+ with_routing do |set|
+ set.draw { |map| resources :contents }
+ assert_equal 'http://test.host/contents/new', new_content_url
+ assert_equal 'http://test.host/contents/1', content_url(:id => 1)
end
+ end
- test "is able to make methods available to the view" do
- # This ensure is a hidious hack to deal with these tests bleeding
- # methods between eachother
- begin
- _helpers.module_eval do
- def render_from_helper; from_test_case end
+ test "named routes can be used from helper included in view" do
+ with_routing do |set|
+ set.draw { |map| resources :contents }
+ _helpers.module_eval do
+ def render_from_helper
+ new_content_url
end
- assert_equal 'Word!', render(:partial => 'test/from_helper')
- ensure
- _helpers.send(:remove_method, :render_from_helper)
end
+
+ assert_equal 'http://test.host/contents/new', render(:partial => 'test/from_helper')
end
+ end
- def from_test_case; 'Word!'; end
- helper_method :from_test_case
+ test "is able to render partials with local variables" do
+ assert_equal 'Eloy', render('developers/developer', :developer => stub(:name => 'Eloy'))
+ assert_equal 'Eloy', render(:partial => 'developers/developer',
+ :locals => { :developer => stub(:name => 'Eloy') })
end
- class AssertionsTest < ActionView::TestCase
- def render_from_helper
- form_tag('/foo') do
- safe_concat render(:text => '<ul><li>foo</li></ul>')
- end
+ test "is able to render partials from templates and also use instance variables" do
+ @controller.controller_path = "test"
+
+ @customers = [stub(:name => 'Eloy'), stub(:name => 'Manfred')]
+ assert_match /Hello: EloyHello: Manfred/, render(:file => 'test/list')
+ end
+
+ end
+
+ class AssertionsTest < ActionView::TestCase
+ def render_from_helper
+ form_tag('/foo') do
+ safe_concat render(:text => '<ul><li>foo</li></ul>')
end
- helper_method :render_from_helper
+ end
+ helper_method :render_from_helper
- test "uses the output_buffer for assert_select" do
- render(:partial => 'test/from_helper')
+ test "uses the output_buffer for assert_select" do
+ render(:partial => 'test/from_helper')
- assert_select 'form' do
- assert_select 'li', :text => 'foo'
- end
+ assert_select 'form' do
+ assert_select 'li', :text => 'foo'
end
end
end