diff options
author | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-06-06 20:35:28 +0300 |
---|---|---|
committer | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-06-06 20:35:28 +0300 |
commit | 969b812433b6030b15b591ec5862daae1b707025 (patch) | |
tree | 478affbb74c02b08ff97cc9e94b00038c9b89a0c /spec/support/api | |
parent | ccf89acc7145bb129f5666108854daa71a022827 (diff) |
Add schema matcher for non response objects + use schema to test additional metrics compliance
Diffstat (limited to 'spec/support/api')
-rw-r--r-- | spec/support/api/schema_matcher.rb | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/spec/support/api/schema_matcher.rb b/spec/support/api/schema_matcher.rb index e42d727672b..dff0dfba675 100644 --- a/spec/support/api/schema_matcher.rb +++ b/spec/support/api/schema_matcher.rb @@ -1,8 +1,16 @@ +def schema_path(schema) + schema_directory = "#{Dir.pwd}/spec/fixtures/api/schemas" + "#{schema_directory}/#{schema}.json" +end + RSpec::Matchers.define :match_response_schema do |schema, **options| match do |response| - schema_directory = "#{Dir.pwd}/spec/fixtures/api/schemas" - schema_path = "#{schema_directory}/#{schema}.json" + JSON::Validator.validate!(schema_path(schema), response.body, options) + end +end - JSON::Validator.validate!(schema_path, response.body, options) +RSpec::Matchers.define :match_schema do |schema, **options| + match do |data| + JSON::Validator.validate!(schema_path(schema), data, options) end end |