Skip to content

Commit

Permalink
Merge pull request #9721 from dmarcoux/do-not-assert_match-error-mess…
Browse files Browse the repository at this point in the history
…ages

Do not assert_match for specific error messages
  • Loading branch information
dmarcoux committed Jun 10, 2020
2 parents c5df2e7 + 9bd3828 commit b18adcb
Showing 1 changed file with 11 additions and 22 deletions.
33 changes: 11 additions & 22 deletions src/api/test/unit/validator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,70 +4,59 @@

class ValidatorTest < ActiveSupport::TestCase
def test_validator
exception = assert_raise ArgumentError do
assert_raise ArgumentError do
Suse::Validator.validate 'notthere'
end
assert_match('wrong number of arguments (given 1, expected 2)', exception.message)

exception = assert_raise RuntimeError do
assert_raise RuntimeError do
# passing garbage
Suse::Validator.validate [], ''
end
assert_match(/illegal option/, exception.message)

exception = assert_raise ArgumentError do
assert_raise ArgumentError do
# no action, no schema
Suse::Validator.validate controller: :project
end
assert_match('wrong number of arguments (given 1, expected 2)', exception.message)

request = ActionController::TestRequest.create({})
exception = assert_raise Suse::ValidationError do
assert_raise Suse::ValidationError do
Suse::Validator.validate 'link', request.raw_post.to_s
end
assert_match(/Document is empty/, exception.message)

request.env['RAW_POST_DATA'] = '<link test="invalid"/>'
exception = assert_raise Suse::ValidationError do
assert_raise Suse::ValidationError do
Suse::Validator.validate 'link', request.raw_post.to_s
end
assert_match(/Invalid attribute test for element link/, exception.message)

request.env['RAW_POST_DATA'] = '<link test"invalid"/>'
exception = assert_raise Suse::ValidationError do
assert_raise Suse::ValidationError do
Suse::Validator.validate 'link', request.raw_post.to_s
end
assert_match(/Extra content at the end of the document/, exception.message)

request.env['RAW_POST_DATA'] = '<link test="invalid">'
exception = assert_raise Suse::ValidationError do
assert_raise Suse::ValidationError do
Suse::Validator.validate 'link', request.raw_post.to_s
end
assert_match(/EndTag: '<\/' not found/, exception.message)

request.env['RAW_POST_DATA'] = '<link test="invalid"></ink>'
exception = assert_raise Suse::ValidationError do
assert_raise Suse::ValidationError do
Suse::Validator.validate 'link', request.raw_post.to_s
end
assert_match(/Opening and ending tag mismatch/, exception.message)

request.env['RAW_POST_DATA'] = '<link test="invalid" fun="foo"/>'
exception = assert_raise Suse::ValidationError do
assert_raise Suse::ValidationError do
Suse::Validator.validate 'link', request.raw_post.to_s
end
assert_match(/Invalid attribute test for element link/, exception.message)

request.env['RAW_POST_DATA'] = '<link test="invalid">foo</link>'
exception = assert_raise Suse::ValidationError do
assert_raise Suse::ValidationError do
Suse::Validator.validate 'link', request.raw_post.to_s
end
assert_match(/Did not expect text in element link content/, exception.message)

request.env['RAW_POST_DATA'] = '<link test="invalid"><foo/></link>'
exception = assert_raise Suse::ValidationError do
assert_raise Suse::ValidationError do
Suse::Validator.validate 'link', request.raw_post.to_s
end
assert_match(/Did not expect element foo there/, exception.message)

# projects can be anything
request.env['RAW_POST_DATA'] = '<link project="invalid"/>'
Expand Down

0 comments on commit b18adcb

Please sign in to comment.