aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/assertions/response_assertions_test.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2012-01-06 11:20:26 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2012-01-06 11:20:26 -0800
commit01d17943ec27e762141209bdbcaf73446a272fcc (patch)
tree8e5cfe51a33ee20b2af1a72499d334660a5806c9 /actionpack/test/assertions/response_assertions_test.rb
parent180eb8ff31d679e6b0ddd55c610139c38ec52f18 (diff)
downloadrails-01d17943ec27e762141209bdbcaf73446a272fcc.tar.gz
rails-01d17943ec27e762141209bdbcaf73446a272fcc.tar.bz2
rails-01d17943ec27e762141209bdbcaf73446a272fcc.zip
test response assertions
Diffstat (limited to 'actionpack/test/assertions/response_assertions_test.rb')
-rw-r--r--actionpack/test/assertions/response_assertions_test.rb55
1 files changed, 55 insertions, 0 deletions
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