diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2017-08-04 21:45:14 +0800 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2017-08-04 21:45:14 +0800 |
commit | b7547ade672fdcb9315ae9821c1eca195d87022a (patch) | |
tree | bfe23e7abaddefd2fc8e9bbd062c0564344a0c06 /spec/support/api | |
parent | 8fff6a3422e07ad45c1e8875476427eb81bb0e2e (diff) | |
download | gitlab-ce-b7547ade672fdcb9315ae9821c1eca195d87022a.tar.gz |
Backport to CE for:2902-standalone-ee-dir-ce
https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/2483
Diffstat (limited to 'spec/support/api')
-rw-r--r-- | spec/support/api/schema_matcher.rb | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/spec/support/api/schema_matcher.rb b/spec/support/api/schema_matcher.rb index 67599f77adb..6591d56e473 100644 --- a/spec/support/api/schema_matcher.rb +++ b/spec/support/api/schema_matcher.rb @@ -1,23 +1,25 @@ -def schema_path(schema) - schema_directory = "#{Dir.pwd}/spec/fixtures/api/schemas" - "#{schema_directory}/#{schema}.json" +module SchemaPath + def self.expand(schema, dir = '') + Rails.root.join('spec', dir, "fixtures/api/schemas/#{schema}.json").to_s + end end -RSpec::Matchers.define :match_response_schema do |schema, **options| +RSpec::Matchers.define :match_response_schema do |schema, dir: '', **options| match do |response| - @errors = JSON::Validator.fully_validate(schema_path(schema), response.body, options) + @errors = JSON::Validator.fully_validate( + SchemaPath.expand(schema, dir), response.body, options) @errors.empty? end failure_message do |response| - "didn't match the schema defined by #{schema_path(schema)}" \ + "didn't match the schema defined by #{SchemaPath.expand(schema, dir)}" \ " The validation errors were:\n#{@errors.join("\n")}" end end -RSpec::Matchers.define :match_schema do |schema, **options| +RSpec::Matchers.define :match_schema do |schema, dir: '', **options| match do |data| - JSON::Validator.validate!(schema_path(schema), data, options) + JSON::Validator.validate!(SchemaPath.expand(schema, dir), data, options) end end |