api_matchers 0.6.2 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ci.yml +30 -0
  3. data/.gitignore +1 -0
  4. data/Gemfile +1 -1
  5. data/History.markdown +62 -50
  6. data/README.markdown +1070 -114
  7. data/TODO.markdown +39 -3
  8. data/api_matchers.gemspec +13 -6
  9. data/lib/api_matchers/collection/base.rb +65 -0
  10. data/lib/api_matchers/collection/be_sorted_by.rb +97 -0
  11. data/lib/api_matchers/collection/have_json_size.rb +54 -0
  12. data/lib/api_matchers/core/exceptions.rb +5 -0
  13. data/lib/api_matchers/core/find_in_json.rb +57 -28
  14. data/lib/api_matchers/core/http_status_codes.rb +118 -0
  15. data/lib/api_matchers/core/json_path_finder.rb +87 -0
  16. data/lib/api_matchers/core/parser.rb +4 -2
  17. data/lib/api_matchers/core/rspec_matchers.rb +130 -37
  18. data/lib/api_matchers/core/setup.rb +49 -23
  19. data/lib/api_matchers/core/value_normalizer.rb +26 -0
  20. data/lib/api_matchers/error_response/base.rb +77 -0
  21. data/lib/api_matchers/error_response/have_error.rb +69 -0
  22. data/lib/api_matchers/error_response/have_error_on.rb +173 -0
  23. data/lib/api_matchers/hateoas/base.rb +77 -0
  24. data/lib/api_matchers/hateoas/have_link.rb +102 -0
  25. data/lib/api_matchers/headers/base.rb +7 -7
  26. data/lib/api_matchers/headers/be_json.rb +2 -4
  27. data/lib/api_matchers/headers/be_xml.rb +2 -4
  28. data/lib/api_matchers/headers/have_cache_control.rb +90 -0
  29. data/lib/api_matchers/headers/have_cors_headers.rb +102 -0
  30. data/lib/api_matchers/headers/have_header.rb +102 -0
  31. data/lib/api_matchers/http_status/base.rb +48 -0
  32. data/lib/api_matchers/http_status/be_client_error.rb +17 -0
  33. data/lib/api_matchers/http_status/be_forbidden.rb +17 -0
  34. data/lib/api_matchers/http_status/be_no_content.rb +17 -0
  35. data/lib/api_matchers/http_status/be_not_found.rb +17 -0
  36. data/lib/api_matchers/http_status/be_redirect.rb +17 -0
  37. data/lib/api_matchers/http_status/be_server_error.rb +17 -0
  38. data/lib/api_matchers/http_status/be_successful.rb +17 -0
  39. data/lib/api_matchers/http_status/be_unauthorized.rb +17 -0
  40. data/lib/api_matchers/http_status/be_unprocessable.rb +17 -0
  41. data/lib/api_matchers/http_status/have_http_status.rb +39 -0
  42. data/lib/api_matchers/json_api/base.rb +83 -0
  43. data/lib/api_matchers/json_api/be_json_api_compliant.rb +158 -0
  44. data/lib/api_matchers/json_api/have_json_api_attributes.rb +62 -0
  45. data/lib/api_matchers/json_api/have_json_api_data.rb +110 -0
  46. data/lib/api_matchers/json_api/have_json_api_relationships.rb +62 -0
  47. data/lib/api_matchers/json_structure/base.rb +65 -0
  48. data/lib/api_matchers/json_structure/have_json_keys.rb +55 -0
  49. data/lib/api_matchers/json_structure/have_json_type.rb +72 -0
  50. data/lib/api_matchers/pagination/base.rb +73 -0
  51. data/lib/api_matchers/pagination/be_paginated.rb +73 -0
  52. data/lib/api_matchers/pagination/have_pagination_links.rb +74 -0
  53. data/lib/api_matchers/pagination/have_total_count.rb +77 -0
  54. data/lib/api_matchers/response_body/base.rb +10 -9
  55. data/lib/api_matchers/response_body/have_json.rb +2 -4
  56. data/lib/api_matchers/response_body/have_json_node.rb +45 -1
  57. data/lib/api_matchers/response_body/have_node.rb +2 -0
  58. data/lib/api_matchers/response_body/have_xml_node.rb +13 -14
  59. data/lib/api_matchers/response_body/match_json_schema.rb +89 -0
  60. data/lib/api_matchers/version.rb +3 -1
  61. data/lib/api_matchers.rb +75 -14
  62. data/spec/api_matchers/collection/be_sorted_by_spec.rb +110 -0
  63. data/spec/api_matchers/collection/have_json_size_spec.rb +101 -0
  64. data/spec/api_matchers/error_response/have_error_on_spec.rb +123 -0
  65. data/spec/api_matchers/error_response/have_error_spec.rb +108 -0
  66. data/spec/api_matchers/hateoas/have_link_spec.rb +105 -0
  67. data/spec/api_matchers/headers/base_spec.rb +8 -3
  68. data/spec/api_matchers/headers/be_json_spec.rb +1 -1
  69. data/spec/api_matchers/headers/be_xml_spec.rb +1 -1
  70. data/spec/api_matchers/headers/have_cache_control_spec.rb +102 -0
  71. data/spec/api_matchers/headers/have_cors_headers_spec.rb +74 -0
  72. data/spec/api_matchers/headers/have_header_spec.rb +88 -0
  73. data/spec/api_matchers/http_status/be_client_error_spec.rb +53 -0
  74. data/spec/api_matchers/http_status/be_forbidden_spec.rb +33 -0
  75. data/spec/api_matchers/http_status/be_no_content_spec.rb +33 -0
  76. data/spec/api_matchers/http_status/be_not_found_spec.rb +39 -0
  77. data/spec/api_matchers/http_status/be_redirect_spec.rb +55 -0
  78. data/spec/api_matchers/http_status/be_server_error_spec.rb +49 -0
  79. data/spec/api_matchers/http_status/be_successful_spec.rb +78 -0
  80. data/spec/api_matchers/http_status/be_unauthorized_spec.rb +33 -0
  81. data/spec/api_matchers/http_status/be_unprocessable_spec.rb +39 -0
  82. data/spec/api_matchers/http_status/have_http_status_spec.rb +81 -0
  83. data/spec/api_matchers/json_api/be_json_api_compliant_spec.rb +109 -0
  84. data/spec/api_matchers/json_api/have_json_api_attributes_spec.rb +61 -0
  85. data/spec/api_matchers/json_api/have_json_api_data_spec.rb +95 -0
  86. data/spec/api_matchers/json_api/have_json_api_relationships_spec.rb +61 -0
  87. data/spec/api_matchers/json_structure/have_json_keys_spec.rb +81 -0
  88. data/spec/api_matchers/json_structure/have_json_type_spec.rb +134 -0
  89. data/spec/api_matchers/pagination/be_paginated_spec.rb +95 -0
  90. data/spec/api_matchers/pagination/have_pagination_links_spec.rb +80 -0
  91. data/spec/api_matchers/pagination/have_total_count_spec.rb +85 -0
  92. data/spec/api_matchers/response_body/base_spec.rb +15 -7
  93. data/spec/api_matchers/response_body/have_json_node_spec.rb +57 -0
  94. data/spec/api_matchers/response_body/match_json_schema_spec.rb +86 -0
  95. metadata +152 -47
  96. data/.rvmrc.example +0 -1
  97. data/.travis.yml +0 -12
  98. data/Gemfile.lock +0 -46
  99. data/lib/api_matchers/http_status_code/base.rb +0 -32
  100. data/lib/api_matchers/http_status_code/be_bad_request.rb +0 -25
  101. data/lib/api_matchers/http_status_code/be_forbidden.rb +0 -21
  102. data/lib/api_matchers/http_status_code/be_internal_server_error.rb +0 -25
  103. data/lib/api_matchers/http_status_code/be_not_found.rb +0 -25
  104. data/lib/api_matchers/http_status_code/be_ok.rb +0 -25
  105. data/lib/api_matchers/http_status_code/be_unauthorized.rb +0 -25
  106. data/lib/api_matchers/http_status_code/be_unprocessable_entity.rb +0 -25
  107. data/lib/api_matchers/http_status_code/create_resource.rb +0 -25
  108. data/spec/api_matchers/http_status_code/base_spec.rb +0 -12
  109. data/spec/api_matchers/http_status_code/be_bad_request_spec.rb +0 -49
  110. data/spec/api_matchers/http_status_code/be_forbidden_spec.rb +0 -49
  111. data/spec/api_matchers/http_status_code/be_internal_server_error_spec.rb +0 -49
  112. data/spec/api_matchers/http_status_code/be_not_found_spec.rb +0 -49
  113. data/spec/api_matchers/http_status_code/be_ok_spec.rb +0 -49
  114. data/spec/api_matchers/http_status_code/be_unauthorized_spec.rb +0 -49
  115. data/spec/api_matchers/http_status_code/be_unprocessable_entity_spec.rb +0 -27
  116. data/spec/api_matchers/http_status_code/create_resource_spec.rb +0 -49
@@ -1,49 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe APIMatchers::HTTPStatusCode::BeForbidden do
4
- describe "should be_forbidden" do
5
- it "should passes if the actual is equal to 403" do
6
- expect(403).to be_forbidden
7
- end
8
-
9
- it "should fails if the actual is not equal to 403" do
10
- expect {
11
- expect(400).to be_forbidden
12
- }.to fail_with(%Q{expected that '400' to be Forbidden with the status '403'.})
13
- end
14
- end
15
-
16
- describe "should_not be_forbidden" do
17
- it "should pass if the actual is not equal to 403" do
18
- expect(201).not_to be_forbidden
19
- end
20
-
21
- it "should fail if the actual is equal to 403" do
22
- expect {
23
- expect(403).not_to be_forbidden
24
- }.to fail_with(%Q{expected that '403' to NOT be Forbidden.})
25
- end
26
- end
27
-
28
- describe "with change configuration" do
29
- before do
30
- APIMatchers.setup { |config| config.http_status_method = :http_status }
31
- end
32
-
33
- after do
34
- APIMatchers.setup { |config| config.http_status_method = nil }
35
- end
36
-
37
- it "should pass if the actual.http_status is equal to 403" do
38
- response = OpenStruct.new(:http_status => 403)
39
- expect(response).to be_forbidden
40
- end
41
-
42
- it "should fail if the actual.http_status is not equal to 403" do
43
- response = OpenStruct.new(:http_status => 402)
44
- expect {
45
- expect(response).to be_forbidden
46
- }.to fail_with(%Q{expected that '402' to be Forbidden with the status '403'.})
47
- end
48
- end
49
- end
@@ -1,49 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe APIMatchers::HTTPStatusCode::BeInternalServerError do
4
- describe "should be_internal_server_error" do
5
- it "should passes if the actual is equal to 500" do
6
- expect(500).to be_internal_server_error
7
- end
8
-
9
- it "should fails if the actual is not equal to 500" do
10
- expect {
11
- expect(401).to be_internal_server_error
12
- }.to fail_with(%Q{expected that '401' to be Internal Server Error with the status '500'.})
13
- end
14
- end
15
-
16
- describe "should_not be_internal_server_error" do
17
- it "should passes if the actual is not equal to 500" do
18
- expect(400).not_to be_internal_server_error
19
- end
20
-
21
- it "should fail if the actual is equal to 500" do
22
- expect {
23
- expect(500).not_to be_internal_server_error
24
- }.to fail_with(%Q{expected that '500' to NOT be Internal Server Error.})
25
- end
26
- end
27
-
28
- describe "with change configuration" do
29
- before do
30
- APIMatchers.setup { |config| config.http_status_method = :http_status }
31
- end
32
-
33
- after do
34
- APIMatchers.setup { |config| config.http_status_method = nil }
35
- end
36
-
37
- it "should pass if the actual.http_status is equal to 500" do
38
- response = OpenStruct.new(:http_status => 500)
39
- expect(response).to be_internal_server_error
40
- end
41
-
42
- it "should fail if the actual.http_status is not equal to 500" do
43
- response = OpenStruct.new(:http_status => 402)
44
- expect {
45
- expect(response).to be_internal_server_error
46
- }.to fail_with(%Q{expected that '402' to be Internal Server Error with the status '500'.})
47
- end
48
- end
49
- end
@@ -1,49 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe APIMatchers::HTTPStatusCode::BeBadRequest do
4
- describe "should be_not_found" do
5
- it "should passes if the actual is equal to 404" do
6
- expect(404).to be_not_found
7
- end
8
-
9
- it "should fails if the actual is not equal to 404" do
10
- expect {
11
- expect(401).to be_not_found
12
- }.to fail_with(%Q{expected that '401' to be Not Found with the status '404'.})
13
- end
14
- end
15
-
16
- describe "should_not be_not_found" do
17
- it "should pass if the actual is not equal to 404" do
18
- expect(401).not_to be_not_found
19
- end
20
-
21
- it "should fail if the actual is equal to 404" do
22
- expect {
23
- expect(404).not_to be_not_found
24
- }.to fail_with(%Q{expected that '404' to NOT be Not Found with the status '404'.})
25
- end
26
- end
27
-
28
- describe "with change configuration" do
29
- before do
30
- APIMatchers.setup { |config| config.http_status_method = :http_status }
31
- end
32
-
33
- after do
34
- APIMatchers.setup { |config| config.http_status_method = nil }
35
- end
36
-
37
- it "should pass if the actual.http_status is equal to 404" do
38
- response = OpenStruct.new(:http_status => 404)
39
- expect(response).to be_not_found
40
- end
41
-
42
- it "should fail if the actual.http_status is not equal to 400" do
43
- response = OpenStruct.new(:http_status => 500)
44
- expect {
45
- expect(response).to be_not_found
46
- }.to fail_with(%Q{expected that '500' to be Not Found with the status '404'.})
47
- end
48
- end
49
- end
@@ -1,49 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe APIMatchers::HTTPStatusCode::BeOk do
4
- describe "should be_ok" do
5
- it "should passes if the actual is equal to 200" do
6
- expect(200).to be_ok
7
- end
8
-
9
- it "should fails if the actual is not equal to 200" do
10
- expect {
11
- expect(201).to be_ok
12
- }.to fail_with(%Q{expected that '201' to be ok with the status '200'.})
13
- end
14
- end
15
-
16
- describe "should_not be_ok_request" do
17
- it "should passes if the actual is not equal to 200" do
18
- expect(201).not_to be_ok
19
- end
20
-
21
- it "should fail if the actual is equal to 200" do
22
- expect {
23
- expect(200).not_to be_ok
24
- }.to fail_with(%Q{expected that '200' to NOT be ok with the status '200'.})
25
- end
26
- end
27
-
28
- describe "with change configuration" do
29
- before do
30
- APIMatchers.setup { |config| config.http_status_method = :http_status }
31
- end
32
-
33
- after do
34
- APIMatchers.setup { |config| config.http_status_method = nil }
35
- end
36
-
37
- it "should pass if the actual.http_status is equal to 200" do
38
- response = OpenStruct.new(:http_status => 200)
39
- expect(response).to be_ok
40
- end
41
-
42
- it "should fail if the actual.http_status is not equal to 200" do
43
- response = OpenStruct.new(:http_status => 500)
44
- expect {
45
- expect(response).to be_ok
46
- }.to fail_with(%Q{expected that '500' to be ok with the status '200'.})
47
- end
48
- end
49
- end
@@ -1,49 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe APIMatchers::HTTPStatusCode::BeUnauthorized do
4
- describe "should be_unauthorized" do
5
- it "should passes if the actual is equal to 401" do
6
- expect(401).to be_unauthorized
7
- end
8
-
9
- it "should fails if the actual is not equal to 401" do
10
- expect {
11
- expect(400).to be_unauthorized
12
- }.to fail_with(%Q{expected that '400' to be Unauthorized with the status '401'.})
13
- end
14
- end
15
-
16
- describe "should_not be_unauthorized" do
17
- it "should pass if the actual is not equal to 401" do
18
- expect(201).not_to be_unauthorized
19
- end
20
-
21
- it "should fail if the actual is equal to 401" do
22
- expect {
23
- expect(401).not_to be_unauthorized
24
- }.to fail_with(%Q{expected that '401' to NOT be Unauthorized.})
25
- end
26
- end
27
-
28
- describe "with change configuration" do
29
- before do
30
- APIMatchers.setup { |config| config.http_status_method = :http_status }
31
- end
32
-
33
- after do
34
- APIMatchers.setup { |config| config.http_status_method = nil }
35
- end
36
-
37
- it "should pass if the actual.http_status is equal to 401" do
38
- response = OpenStruct.new(:http_status => 401)
39
- expect(response).to be_unauthorized
40
- end
41
-
42
- it "should fail if the actual.http_status is not equal to 401" do
43
- response = OpenStruct.new(:http_status => 402)
44
- expect {
45
- expect(response).to be_unauthorized
46
- }.to fail_with(%Q{expected that '402' to be Unauthorized with the status '401'.})
47
- end
48
- end
49
- end
@@ -1,27 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe APIMatchers::HTTPStatusCode::BeUnprocessableEntity do
4
- describe "should be_unprocessable_entity" do
5
- it "should passes if the actual is equal to 422" do
6
- expect(422).to be_unprocessable_entity
7
- end
8
-
9
- it "should fails if the actual is not equal to 422" do
10
- expect {
11
- expect(500).to be_unprocessable_entity
12
- }.to fail_with(%Q{expected that '500' to be Unprocessable entity with the status '422'.})
13
- end
14
- end
15
-
16
- describe "should_not be_unprocessable_entity" do
17
- it "should passes if the actual is not equal to 200" do
18
- expect(400).not_to be_unprocessable_entity
19
- end
20
-
21
- it "should fail if the actual is equal to 200" do
22
- expect {
23
- expect(422).not_to be_unprocessable_entity
24
- }.to fail_with(%Q{expected that '422' to NOT be Unprocessable entity with the status '422'.})
25
- end
26
- end
27
- end
@@ -1,49 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe APIMatchers::HTTPStatusCode::CreateResource do
4
- describe "should create_resource" do
5
- it "should passes if the actual is equal to 201" do
6
- expect(201).to create_resource
7
- end
8
-
9
- it "should fails if the actual is not equal to 201" do
10
- expect {
11
- expect(200).to create_resource
12
- }.to fail_with(%Q{expected that '200' to be Created Resource with the status '201'.})
13
- end
14
- end
15
-
16
- describe "should_not create_resource" do
17
- it "should passes if the actual is not equal to 201" do
18
- expect(401).not_to create_resource
19
- end
20
-
21
- it "should fail if the actual is equal equal to 201" do
22
- expect {
23
- expect(201).not_to create_resource
24
- }.to fail_with(%Q{expected that '201' to NOT be Created Resource.})
25
- end
26
- end
27
-
28
- describe "with change configuration" do
29
- before do
30
- APIMatchers.setup { |config| config.http_status_method = :http_status }
31
- end
32
-
33
- after do
34
- APIMatchers.setup { |config| config.http_status_method = nil }
35
- end
36
-
37
- it "should pass if the actual.http_status is equal to 201" do
38
- response = OpenStruct.new(:http_status => 201)
39
- expect(response).to create_resource
40
- end
41
-
42
- it "should fail if the actual.http_status is not equal to 201" do
43
- response = OpenStruct.new(:http_status => 402)
44
- expect {
45
- expect(response).to create_resource
46
- }.to fail_with(%Q{expected that '402' to be Created Resource with the status '201'.})
47
- end
48
- end
49
- end