Skip to content

Commit 93cad82

Browse files
committed
Include actual exception message with custom exceptions
1 parent d0d7af4 commit 93cad82

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Breaking changes:
66
- [#1662](https://github.com/rails-api/active_model_serializers/pull/1662) Drop support for Rails 4.0 and Ruby 2.0.0. (@remear)
77

88
Features:
9+
- [#1697](https://github.com/rails-api/active_model_serializers/pull/1697) Include actual exception message with custom exceptions;
10+
`Test::Schema` exceptions are now `Minitest::Assertion`s. (@bf4)
911
- [#1699](https://github.com/rails-api/active_model_serializers/pull/1699) String/Lambda support for conditional attributes/associations (@mtsmfm)
1012
- [#1687](https://github.com/rails-api/active_model_serializers/pull/1687) Only calculate `_cache_digest` (in `cache_key`) when `skip_digest` is false. (@bf4)
1113
- [#1647](https://github.com/rails-api/active_model_serializers/pull/1647) Restrict usage of `serializable_hash` options

lib/active_model_serializers/test/schema.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def initialize(schema_path, response, message)
3232
def call
3333
json_schema.expand_references!(store: document_store)
3434
status, errors = json_schema.validate(response_body)
35-
@message ||= errors.map(&:to_s).to_sentence
35+
@message = [message, errors.map(&:to_s).to_sentence].compact.join(': ')
3636
status
3737
end
3838

test/active_model_serializers/test/schema_test.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,15 @@ def test_that_raises_a_minitest_error_with_a_invalid_schema
5454

5555
def test_that_raises_error_with_a_custom_message_with_a_invalid_schema
5656
message = 'oh boy the show is broken'
57+
exception_message = "#/name: failed schema #/properties/name: For 'properties/name', \"Name 1\" is not an integer. and #/description: failed schema #/properties/description: For 'properties/description', \"Description 1\" is not a boolean."
58+
expected_message = "#{message}: #{exception_message}"
5759

5860
get :show
5961

6062
error = assert_raises Minitest::Assertion do
6163
assert_response_schema(nil, message)
6264
end
63-
assert_equal(message, error.message)
65+
assert_equal(expected_message, error.message)
6466
end
6567

6668
def test_that_assert_with_a_custom_schema
@@ -102,14 +104,14 @@ def test_that_assert_with_a_custom_schema_directory
102104
end
103105

104106
def test_with_a_non_existent_file
105-
expected_message = 'No Schema file at test/support/schemas/non-existent.json'
107+
message = 'No Schema file at test/support/schemas/non-existent.json'
106108

107109
get :show
108110

109111
error = assert_raises ActiveModelSerializers::Test::Schema::MissingSchema do
110112
assert_response_schema('non-existent.json')
111113
end
112-
assert_equal(expected_message, error.message)
114+
assert_equal(message, error.message)
113115
end
114116

115117
def test_that_raises_with_a_invalid_json_body

0 commit comments

Comments
 (0)