Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
deprecated assertions tests
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4976 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
jeremy committed Sep 4, 2006
1 parent 653bfe9 commit e04a6e8
Showing 1 changed file with 51 additions and 33 deletions.
84 changes: 51 additions & 33 deletions actionpack/test/controller/action_pack_assertions_test.rb
Expand Up @@ -169,8 +169,8 @@ def test_assert_tag_and_url_for
# test the session assertion to make sure something is there.
def test_assert_session_has
process :session_stuffing
assert_session_has 'xmas'
assert_session_has_no 'halloween'
assert_deprecated_assertion { assert_session_has 'xmas' }
assert_deprecated_assertion { assert_session_has_no 'halloween' }
end

# test the get method, make sure the request really was a get
Expand Down Expand Up @@ -203,38 +203,44 @@ def test_post
# test the assertion of goodies in the template
def test_assert_template_has
process :assign_this
assert_template_has 'howdy'
assert_deprecated_assertion { assert_template_has 'howdy' }
end

# test the assertion for goodies that shouldn't exist in the template
def test_assert_template_has_no
process :nothing
assert_template_has_no 'maple syrup'
assert_template_has_no 'howdy'
assert_deprecated_assertion { assert_template_has_no 'maple syrup' }
assert_deprecated_assertion { assert_template_has_no 'howdy' }
end

# test the redirection assertions
def test_assert_redirect
process :redirect_internal
assert_redirect
assert_deprecated_assertion { assert_redirect }
end

# test the redirect url string
def test_assert_redirect_url
process :redirect_external
assert_redirect_url 'http://www.rubyonrails.org'
assert_deprecated_assertion do
assert_redirect_url 'http://www.rubyonrails.org'
end
end

# test the redirection pattern matching on a string
def test_assert_redirect_url_match_string
process :redirect_external
assert_redirect_url_match 'rails.org'
assert_deprecated_assertion do
assert_redirect_url_match 'rails.org'
end
end

# test the redirection pattern matching on a pattern
def test_assert_redirect_url_match_pattern
process :redirect_external
assert_redirect_url_match /ruby/
assert_deprecated_assertion do
assert_redirect_url_match /ruby/
end
end

# test the redirection to a named route
Expand Down Expand Up @@ -293,32 +299,31 @@ def test_assert_redirect_to_nested_named_route
def test_flash_assertions_full
process :flash_me
assert @response.has_flash_with_contents?
assert_flash_exists
assert_flash_not_empty
assert_flash_has 'hello'
assert_flash_has_no 'stds'
assert_deprecated_assertion { assert_flash_exists }
assert_deprecated_assertion { assert_flash_not_empty }
assert_deprecated_assertion { assert_flash_has 'hello' }
assert_deprecated_assertion { assert_flash_has_no 'stds' }
end

# test the flash-based assertions with no flash at all
def test_flash_assertions_negative
process :nothing
assert_flash_empty
assert_flash_has_no 'hello'
assert_flash_has_no 'qwerty'
assert_deprecated_assertion { assert_flash_empty }
assert_deprecated_assertion { assert_flash_has_no 'hello' }
assert_deprecated_assertion { assert_flash_has_no 'qwerty' }
end

# test the assert_rendered_file
def test_assert_rendered_file
process :hello_world
assert_rendered_file 'test/hello_world'
assert_rendered_file 'hello_world'
assert_deprecated(/render/) { process :hello_world }
assert_deprecated_assertion { assert_rendered_file 'test/hello_world' }
assert_deprecated_assertion { assert_rendered_file 'hello_world' }
end

# test the assert_success assertion
def test_assert_success
process :nothing
assert_success
assert_rendered_file
assert_deprecated_assertion { assert_success }
end

# -- standard request/response object testing --------------------------------
Expand All @@ -327,7 +332,7 @@ def test_assert_success
def test_session_objects
process :session_stuffing
assert @response.has_session_object?('xmas')
assert_session_equal 'turkey', 'xmas'
assert_deprecated_assertion { assert_session_equal 'turkey', 'xmas' }
assert !@response.has_session_object?('easter')
end

Expand All @@ -346,7 +351,7 @@ def test_template_object_missing

def test_assigned_equal
process :assign_this
assert_assigned_equal "ho", :howdy
assert_deprecated_assertion { assert_assigned_equal "ho", :howdy }
end

# check the empty flashing
Expand Down Expand Up @@ -375,15 +380,17 @@ def test_flash_have_nots
# examine that the flash objects are what we expect
def test_flash_equals
process :flash_me
assert_flash_equal 'my name is inigo montoya...', 'hello'
assert_deprecated_assertion do
assert_flash_equal 'my name is inigo montoya...', 'hello'
end
end

# check if we were rendered by a file-based template?
def test_rendered_action
process :nothing
assert !@response.rendered_with_file?

process :hello_world
assert_deprecated(/render/) { process :hello_world }
assert @response.rendered_with_file?
assert 'hello_world', @response.rendered_file
end
Expand Down Expand Up @@ -459,20 +466,26 @@ def test_render_based_on_parameters
end

def test_assert_template_xpath_match_no_matches
process :hello_xml_world
assert_deprecated(/render/) { process :hello_xml_world }
assert_raises Test::Unit::AssertionFailedError do
assert_template_xpath_match('/no/such/node/in/document')
assert_deprecated_assertion do
assert_template_xpath_match('/no/such/node/in/document')
end
end
end

def test_simple_one_element_xpath_match
process :hello_xml_world
assert_template_xpath_match('//title', "Hello World")
assert_deprecated(/render/) { process :hello_xml_world }
assert_deprecated_assertion do
assert_template_xpath_match('//title', "Hello World")
end
end

def test_array_of_elements_in_xpath_match
process :hello_xml_world
assert_template_xpath_match('//p', %w( abes monks wiseguys ))
assert_deprecated(/render/) { process :hello_xml_world }
assert_deprecated_assertion do
assert_template_xpath_match('//p', %w( abes monks wiseguys ))
end
end

def test_follow_redirect
Expand Down Expand Up @@ -540,6 +553,11 @@ def test_assert_valid_failing
rescue Test::Unit::AssertionFailedError => e
end
end

protected
def assert_deprecated_assertion(&block)
assert_deprecated(/assert/, &block)
end
end

class ActionPackHeaderTest < Test::Unit::TestCase
Expand All @@ -549,13 +567,13 @@ def setup
end

def test_rendering_xml_sets_content_type
process :hello_xml_world
assert_deprecated(/render/) { process :hello_xml_world }
assert_equal('application/xml', @controller.headers['Content-Type'])
end

def test_rendering_xml_respects_content_type
@response.headers['Content-Type'] = 'application/pdf'
process :hello_xml_world
assert_deprecated(/render/) { process :hello_xml_world }
assert_equal('application/pdf', @controller.headers['Content-Type'])
end

Expand Down

0 comments on commit e04a6e8

Please sign in to comment.