Fix matcher `match_response_schema`

This commit is contained in:
Douglas Barbosa Alexandre 2016-08-16 11:13:21 -03:00
parent f77c47a51c
commit 29a91c5bc6
5 changed files with 13 additions and 6 deletions

View File

@ -26,7 +26,7 @@ describe Projects::Boards::IssuesController do
parsed_response = JSON.parse(response.body)
expect(response).to match_response_schema('issue', array: true)
expect(response).to match_response_schema('issues')
expect(parsed_response.length).to eq 2
end
end

View File

@ -29,7 +29,7 @@ describe Projects::Boards::ListsController do
parsed_response = JSON.parse(response.body)
expect(response).to match_response_schema('list', array: true)
expect(response).to match_response_schema('lists')
expect(parsed_response.length).to eq 3
end
@ -204,7 +204,7 @@ describe Projects::Boards::ListsController do
it 'returns the defaults lists' do
generate_default_board_lists user: user
expect(response).to match_response_schema('list', array: true)
expect(response).to match_response_schema('lists')
end
end

4
spec/fixtures/api/schemas/issues.json vendored Normal file
View File

@ -0,0 +1,4 @@
{
"type": "array",
"items": { "$ref": "issue.json" }
}

4
spec/fixtures/api/schemas/lists.json vendored Normal file
View File

@ -0,0 +1,4 @@
{
"type": "array",
"items": { "$ref": "list.json" }
}

View File

@ -1,9 +1,8 @@
RSpec::Matchers.define :match_response_schema do |schema, options = {}|
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"
list = options.fetch(:array, false)
JSON::Validator.validate!(schema_path, response.body, list: list)
JSON::Validator.validate!(schema_path, response.body, options)
end
end