diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2012-01-06 11:20:26 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2012-01-06 11:20:26 -0800 |
commit | 01d17943ec27e762141209bdbcaf73446a272fcc (patch) | |
tree | 8e5cfe51a33ee20b2af1a72499d334660a5806c9 | |
parent | 180eb8ff31d679e6b0ddd55c610139c38ec52f18 (diff) | |
download | rails-01d17943ec27e762141209bdbcaf73446a272fcc.tar.gz rails-01d17943ec27e762141209bdbcaf73446a272fcc.tar.bz2 rails-01d17943ec27e762141209bdbcaf73446a272fcc.zip |
test response assertions
-rwxr-xr-x | actionpack/Rakefile | 2 | ||||
-rw-r--r-- | actionpack/lib/action_controller/test_case.rb | 2 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/testing/assertions/response.rb | 8 | ||||
-rw-r--r-- | actionpack/test/assertions/response_assertions_test.rb | 55 |
4 files changed, 56 insertions, 11 deletions
diff --git a/actionpack/Rakefile b/actionpack/Rakefile index d9e3e56fcc..effb6badfc 100755 --- a/actionpack/Rakefile +++ b/actionpack/Rakefile @@ -16,7 +16,7 @@ Rake::TestTask.new(:test_action_pack) do |t| # make sure we include the tests in alphabetical order as on some systems # this will not happen automatically and the tests (as a whole) will error - t.test_files = Dir.glob('test/{abstract,controller,dispatch,template}/**/*_test.rb').sort + t.test_files = Dir.glob('test/{abstract,controller,dispatch,template,assertions}/**/*_test.rb').sort t.warning = true t.verbose = true diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index 17f978d52e..45e4805ff4 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -69,8 +69,6 @@ module ActionController # assert_template :partial => '_customer', :locals => { :customer => @customer } # def assert_template(options = {}, message = nil) - validate_request! - case options when NilClass, String, Symbol options = options.to_s if Symbol === options diff --git a/actionpack/lib/action_dispatch/testing/assertions/response.rb b/actionpack/lib/action_dispatch/testing/assertions/response.rb index b3d34faf9c..84c2ae716c 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/response.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/response.rb @@ -26,8 +26,6 @@ module ActionDispatch # assert_response 401 # def assert_response(type, message = nil) - validate_request! - if type.in?([:success, :missing, :redirect, :error]) && @response.send("#{type}?") assert true # to count the assertion elsif type.is_a?(Fixnum) && @response.response_code == type @@ -85,12 +83,6 @@ module ActionDispatch @controller.url_for(fragment) end.gsub(/[\r\n]/, '') end - - def validate_request! - unless @request.is_a?(ActionDispatch::Request) - raise ArgumentError, "@request must be an ActionDispatch::Request" - end - end end end end diff --git a/actionpack/test/assertions/response_assertions_test.rb b/actionpack/test/assertions/response_assertions_test.rb new file mode 100644 index 0000000000..ca1d58765d --- /dev/null +++ b/actionpack/test/assertions/response_assertions_test.rb @@ -0,0 +1,55 @@ +require 'abstract_unit' +require 'action_dispatch/testing/assertions/response' + +module ActionDispatch + module Assertions + class ResponseAssertionsTest < ActiveSupport::TestCase + include ResponseAssertions + + FakeResponse = Struct.new(:response_code) do + [:success, :missing, :redirect, :error].each do |sym| + define_method("#{sym}?") do + sym == response_code + end + end + end + + def test_assert_response_predicate_methods + [:success, :missing, :redirect, :error].each do |sym| + @response = FakeResponse.new sym + assert_response sym + + assert_raises(MiniTest::Assertion) { + assert_response :unauthorized + } + end + end + + def test_assert_response_fixnum + @response = FakeResponse.new 400 + assert_response 400 + + assert_raises(MiniTest::Assertion) { + assert_response :unauthorized + } + + assert_raises(MiniTest::Assertion) { + assert_response 500 + } + end + + def test_assert_response_sym_status + @response = FakeResponse.new 401 + assert_response :unauthorized + + assert_raises(MiniTest::Assertion) { + assert_response :ok + } + + assert_raises(MiniTest::Assertion) { + assert_response :success + } + end + end + end +end |