aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/assertions/response_assertions_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/test/assertions/response_assertions_test.rb')
-rw-r--r--actionpack/test/assertions/response_assertions_test.rb38
1 files changed, 31 insertions, 7 deletions
diff --git a/actionpack/test/assertions/response_assertions_test.rb b/actionpack/test/assertions/response_assertions_test.rb
index 579ce0ed29..261579dce5 100644
--- a/actionpack/test/assertions/response_assertions_test.rb
+++ b/actionpack/test/assertions/response_assertions_test.rb
@@ -1,15 +1,18 @@
-require 'abstract_unit'
-require 'action_dispatch/testing/assertions/response'
+# frozen_string_literal: true
+
+require "abstract_unit"
+require "action_dispatch/testing/assertions/response"
module ActionDispatch
module Assertions
class ResponseAssertionsTest < ActiveSupport::TestCase
include ResponseAssertions
- FakeResponse = Struct.new(:response_code, :location) do
+ FakeResponse = Struct.new(:response_code, :location, :body) do
def initialize(*)
super
self.location ||= "http://test.example.com/posts"
+ self.body ||= ""
end
[:successful, :not_found, :redirection, :server_error].each do |sym|
@@ -26,7 +29,7 @@ module ActionDispatch
def test_assert_response_predicate_methods
[:success, :missing, :redirect, :error].each do |sym|
- @response = FakeResponse.new RESPONSE_PREDICATES[sym].to_s.sub(/\?/, '').to_sym
+ @response = FakeResponse.new RESPONSE_PREDICATES[sym].to_s.sub(/\?/, "").to_sym
assert_response sym
assert_raises(Minitest::Assertion) {
@@ -35,7 +38,7 @@ module ActionDispatch
end
end
- def test_assert_response_fixnum
+ def test_assert_response_integer
@response = FakeResponse.new 400
assert_response 400
@@ -92,7 +95,7 @@ module ActionDispatch
def test_error_message_shows_302_redirect_when_302_asserted_for_success
@response = ActionDispatch::Response.new
@response.status = 302
- @response.location = 'http://test.host/posts/redirect/1'
+ @response.location = "http://test.host/posts/redirect/1"
error = assert_raises(Minitest::Assertion) { assert_response :success }
expected = "Expected response to be a <2XX: success>,"\
@@ -104,7 +107,7 @@ module ActionDispatch
def test_error_message_shows_302_redirect_when_302_asserted_for_301
@response = ActionDispatch::Response.new
@response.status = 302
- @response.location = 'http://test.host/posts/redirect/2'
+ @response.location = "http://test.host/posts/redirect/2"
error = assert_raises(Minitest::Assertion) { assert_response 301 }
expected = "Expected response to be a <301: Moved Permanently>,"\
@@ -112,6 +115,27 @@ module ActionDispatch
" redirect to <http://test.host/posts/redirect/2>"
assert_match expected, error.message
end
+
+ def test_error_message_shows_short_response_body
+ @response = ActionDispatch::Response.new
+ @response.status = 400
+ @response.body = "not too long"
+ error = assert_raises(Minitest::Assertion) { assert_response 200 }
+ expected = "Expected response to be a <200: OK>,"\
+ " but was a <400: Bad Request>" \
+ "\nResponse body: not too long"
+ assert_match expected, error.message
+ end
+
+ def test_error_message_does_not_show_long_response_body
+ @response = ActionDispatch::Response.new
+ @response.status = 400
+ @response.body = "not too long" * 50
+ error = assert_raises(Minitest::Assertion) { assert_response 200 }
+ expected = "Expected response to be a <200: OK>,"\
+ " but was a <400: Bad Request>"
+ assert_match expected, error.message
+ end
end
end
end