api_matchers 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +1 -0
- data/History.markdown +9 -0
- data/LICENSE +1 -1
- data/README.markdown +3 -1
- data/TODO.markdown +2 -1
- data/api_matchers.gemspec +1 -1
- data/lib/api_matchers.rb +1 -0
- data/lib/api_matchers/core/rspec_matchers.rb +4 -0
- data/lib/api_matchers/headers/base.rb +1 -1
- data/lib/api_matchers/headers/be_json.rb +7 -3
- data/lib/api_matchers/headers/be_xml.rb +7 -3
- data/lib/api_matchers/http_status_code/base.rb +1 -1
- data/lib/api_matchers/http_status_code/be_bad_request.rb +7 -3
- data/lib/api_matchers/http_status_code/be_internal_server_error.rb +7 -3
- data/lib/api_matchers/http_status_code/be_not_found.rb +7 -3
- data/lib/api_matchers/http_status_code/be_ok.rb +7 -3
- data/lib/api_matchers/http_status_code/be_unauthorized.rb +7 -3
- data/lib/api_matchers/http_status_code/be_unprocessable_entity.rb +21 -0
- data/lib/api_matchers/http_status_code/create_resource.rb +7 -3
- data/lib/api_matchers/response_body/base.rb +6 -2
- data/lib/api_matchers/response_body/have_json.rb +6 -3
- data/lib/api_matchers/version.rb +1 -1
- data/spec/api_matchers/core/find_in_json_spec.rb +4 -4
- data/spec/api_matchers/headers/be_json_spec.rb +17 -9
- data/spec/api_matchers/headers/be_xml_spec.rb +13 -9
- data/spec/api_matchers/http_status_code/be_bad_request_spec.rb +12 -6
- data/spec/api_matchers/http_status_code/be_internal_server_error_spec.rb +12 -6
- data/spec/api_matchers/http_status_code/be_not_found_spec.rb +12 -6
- data/spec/api_matchers/http_status_code/be_ok_spec.rb +12 -6
- data/spec/api_matchers/http_status_code/be_unauthorized_spec.rb +12 -6
- data/spec/api_matchers/http_status_code/be_unprocessable_entity_spec.rb +27 -0
- data/spec/api_matchers/http_status_code/create_resource_spec.rb +12 -6
- data/spec/api_matchers/response_body/base_spec.rb +4 -4
- data/spec/api_matchers/response_body/have_json_node_spec.rb +63 -57
- data/spec/api_matchers/response_body/have_json_spec.rb +7 -7
- data/spec/api_matchers/response_body/have_node_spec.rb +2 -2
- data/spec/api_matchers/response_body/have_xml_node_spec.rb +51 -38
- metadata +9 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e256da4250d9b304bed9733e30b1949b13f60c27
|
4
|
+
data.tar.gz: 361d34707eafd42661b8dea22bdaa95470eb8632
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35c9a63f902431792e244e97a8b6f11307b7b4afc5cb8250a960b43039b3e2aadce22321347c3cf00536169f5074449dfeadccc994ee72275935a26ffd5c206e
|
7
|
+
data.tar.gz: 803747cf15d4d5d461a5ad23d84541a6ede2a878a08e34e5e0808967c35136fb25493b80aaf98bb219fa851c91ce4368ef42c735b872a9ebdb9f7145f6a129bb
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/History.markdown
CHANGED
data/LICENSE
CHANGED
data/README.markdown
CHANGED
data/TODO.markdown
CHANGED
data/api_matchers.gemspec
CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |gem|
|
|
15
15
|
gem.require_paths = ["lib"]
|
16
16
|
gem.version = APIMatchers::VERSION
|
17
17
|
|
18
|
-
gem.add_dependency 'rspec', '>= 2.
|
18
|
+
gem.add_dependency 'rspec', '>= 2.14'
|
19
19
|
gem.add_dependency 'activesupport', '>= 3.2.5'
|
20
20
|
gem.add_dependency 'nokogiri', '>= 1.5.2'
|
21
21
|
end
|
data/lib/api_matchers.rb
CHANGED
@@ -14,6 +14,7 @@ module APIMatchers
|
|
14
14
|
autoload :BeInternalServerError, 'api_matchers/http_status_code/be_internal_server_error'
|
15
15
|
autoload :BeUnauthorized, 'api_matchers/http_status_code/be_unauthorized'
|
16
16
|
autoload :BeOk, 'api_matchers/http_status_code/be_ok'
|
17
|
+
autoload :BeUnprocessableEntity, 'api_matchers/http_status_code/be_unprocessable_entity'
|
17
18
|
autoload :CreateResource, 'api_matchers/http_status_code/create_resource'
|
18
19
|
end
|
19
20
|
|
@@ -22,6 +22,10 @@ module APIMatchers
|
|
22
22
|
::APIMatchers::HTTPStatusCode::BeOk.new(::APIMatchers::Core::Setup)
|
23
23
|
end
|
24
24
|
|
25
|
+
def be_unprocessable_entity
|
26
|
+
::APIMatchers::HTTPStatusCode::BeUnprocessableEntity.new(::APIMatchers::Core::Setup)
|
27
|
+
end
|
28
|
+
|
25
29
|
def create_resource
|
26
30
|
::APIMatchers::HTTPStatusCode::CreateResource.new(::APIMatchers::Core::Setup)
|
27
31
|
end
|
@@ -5,13 +5,17 @@ module APIMatchers
|
|
5
5
|
'application/json; charset=utf-8'
|
6
6
|
end
|
7
7
|
|
8
|
-
def
|
8
|
+
def failure_message
|
9
9
|
%Q{expected a JSON response with '#{expected_content_type}'. Got: '#{content_type_response}'.}
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
12
|
+
def failure_message_when_negated
|
13
13
|
%Q{expected to not be a JSON response. Got: '#{expected_content_type}'.}
|
14
14
|
end
|
15
|
+
|
16
|
+
# RSpec 2 compatibility:
|
17
|
+
alias_method :failure_message_for_should, :failure_message
|
18
|
+
alias_method :failure_message_for_should_not, :failure_message_when_negated
|
15
19
|
end
|
16
20
|
end
|
17
|
-
end
|
21
|
+
end
|
@@ -5,13 +5,17 @@ module APIMatchers
|
|
5
5
|
'application/xml; charset=utf-8'
|
6
6
|
end
|
7
7
|
|
8
|
-
def
|
8
|
+
def failure_message
|
9
9
|
%Q{expected a XML response with '#{expected_content_type}'. Got: '#{content_type_response}'.}
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
12
|
+
def failure_message_when_negated
|
13
13
|
%Q{expected to not be a XML response. Got: '#{expected_content_type}'.}
|
14
14
|
end
|
15
|
+
|
16
|
+
# RSpec 2 compatibility:
|
17
|
+
alias_method :failure_message_for_should, :failure_message
|
18
|
+
alias_method :failure_message_for_should_not, :failure_message_when_negated
|
15
19
|
end
|
16
20
|
end
|
17
|
-
end
|
21
|
+
end
|
@@ -5,13 +5,17 @@ module APIMatchers
|
|
5
5
|
400
|
6
6
|
end
|
7
7
|
|
8
|
-
def
|
8
|
+
def failure_message
|
9
9
|
%Q{expected that '#{@http_status_code}' to be a Bad Request with the status '400'.}
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
12
|
+
def failure_message_when_negated
|
13
13
|
%Q{expected that '#{@http_status_code}' to NOT be a Bad Request with the status '400'.}
|
14
14
|
end
|
15
|
+
|
16
|
+
# RSpec 2 compatibility:
|
17
|
+
alias_method :failure_message_for_should, :failure_message
|
18
|
+
alias_method :failure_message_for_should_not, :failure_message_when_negated
|
15
19
|
end
|
16
20
|
end
|
17
|
-
end
|
21
|
+
end
|
@@ -5,13 +5,17 @@ module APIMatchers
|
|
5
5
|
500
|
6
6
|
end
|
7
7
|
|
8
|
-
def
|
8
|
+
def failure_message
|
9
9
|
%Q{expected that '#{@http_status_code}' to be Internal Server Error with the status '500'.}
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
12
|
+
def failure_message_when_negated
|
13
13
|
%Q{expected that '#{@http_status_code}' to NOT be Internal Server Error.}
|
14
14
|
end
|
15
|
+
|
16
|
+
# RSpec 2 compatibility:
|
17
|
+
alias_method :failure_message_for_should, :failure_message
|
18
|
+
alias_method :failure_message_for_should_not, :failure_message_when_negated
|
15
19
|
end
|
16
20
|
end
|
17
|
-
end
|
21
|
+
end
|
@@ -5,13 +5,17 @@ module APIMatchers
|
|
5
5
|
404
|
6
6
|
end
|
7
7
|
|
8
|
-
def
|
8
|
+
def failure_message
|
9
9
|
%Q{expected that '#{@http_status_code}' to be Not Found with the status '404'.}
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
12
|
+
def failure_message_when_negated
|
13
13
|
%Q{expected that '#{@http_status_code}' to NOT be Not Found with the status '404'.}
|
14
14
|
end
|
15
|
+
|
16
|
+
# RSpec 2 compatibility:
|
17
|
+
alias_method :failure_message_for_should, :failure_message
|
18
|
+
alias_method :failure_message_for_should_not, :failure_message_when_negated
|
15
19
|
end
|
16
20
|
end
|
17
|
-
end
|
21
|
+
end
|
@@ -5,13 +5,17 @@ module APIMatchers
|
|
5
5
|
200
|
6
6
|
end
|
7
7
|
|
8
|
-
def
|
8
|
+
def failure_message
|
9
9
|
%Q{expected that '#{@http_status_code}' to be ok with the status '200'.}
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
12
|
+
def failure_message_when_negated
|
13
13
|
%Q{expected that '#{@http_status_code}' to NOT be ok with the status '200'.}
|
14
14
|
end
|
15
|
+
|
16
|
+
# RSpec 2 compatibility:
|
17
|
+
alias_method :failure_message_for_should, :failure_message
|
18
|
+
alias_method :failure_message_for_should_not, :failure_message_when_negated
|
15
19
|
end
|
16
20
|
end
|
17
|
-
end
|
21
|
+
end
|
@@ -5,13 +5,17 @@ module APIMatchers
|
|
5
5
|
401
|
6
6
|
end
|
7
7
|
|
8
|
-
def
|
8
|
+
def failure_message
|
9
9
|
%Q{expected that '#{@http_status_code}' to be Unauthorized with the status '401'.}
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
12
|
+
def failure_message_when_negated
|
13
13
|
%Q{expected that '#{@http_status_code}' to NOT be Unauthorized.}
|
14
14
|
end
|
15
|
+
|
16
|
+
# RSpec 2 compatibility:
|
17
|
+
alias_method :failure_message_for_should, :failure_message
|
18
|
+
alias_method :failure_message_for_should_not, :failure_message_when_negated
|
15
19
|
end
|
16
20
|
end
|
17
|
-
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module APIMatchers
|
2
|
+
module HTTPStatusCode
|
3
|
+
class BeUnprocessableEntity < Base
|
4
|
+
def expected_status_code
|
5
|
+
422
|
6
|
+
end
|
7
|
+
|
8
|
+
def failure_message
|
9
|
+
%Q{expected that '#{@http_status_code}' to be Unprocessable entity with the status '#{expected_status_code}'.}
|
10
|
+
end
|
11
|
+
|
12
|
+
def failure_message_when_negated
|
13
|
+
%Q{expected that '#{@http_status_code}' to NOT be Unprocessable entity with the status '#{expected_status_code}'.}
|
14
|
+
end
|
15
|
+
|
16
|
+
# RSpec 2 compatibility:
|
17
|
+
alias_method :failure_message_for_should, :failure_message
|
18
|
+
alias_method :failure_message_for_should_not, :failure_message_when_negated
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -5,13 +5,17 @@ module APIMatchers
|
|
5
5
|
201
|
6
6
|
end
|
7
7
|
|
8
|
-
def
|
8
|
+
def failure_message
|
9
9
|
%Q{expected that '#{@http_status_code}' to be Created Resource with the status '201'.}
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
12
|
+
def failure_message_when_negated
|
13
13
|
%Q{expected that '#{@http_status_code}' to NOT be Created Resource.}
|
14
14
|
end
|
15
|
+
|
16
|
+
# RSpec 2 compatibility:
|
17
|
+
alias_method :failure_message_for_should, :failure_message
|
18
|
+
alias_method :failure_message_for_should_not, :failure_message_when_negated
|
15
19
|
end
|
16
20
|
end
|
17
|
-
end
|
21
|
+
end
|
@@ -31,14 +31,18 @@ module APIMatchers
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
def
|
34
|
+
def failure_message
|
35
35
|
"expected to have node called: '#{@expected_node}'" << added_message << ". Got: '#{response_body}'"
|
36
36
|
end
|
37
37
|
|
38
|
-
def
|
38
|
+
def failure_message_when_negated
|
39
39
|
"expected to NOT have node called: '#{@expected_node}'" << added_message << ". Got: '#{response_body}'"
|
40
40
|
end
|
41
41
|
|
42
|
+
# RSpec 2 compatibility:
|
43
|
+
alias_method :failure_message_for_should, :failure_message
|
44
|
+
alias_method :failure_message_for_should_not, :failure_message_when_negated
|
45
|
+
|
42
46
|
def added_message
|
43
47
|
if @with_value
|
44
48
|
" with value: '#{@with_value}'"
|
@@ -14,14 +14,17 @@ module APIMatchers
|
|
14
14
|
@expected_json == json
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
17
|
+
def failure_message
|
18
18
|
"expect to have json: '#{response_body}'. Got: '#{json}'."
|
19
19
|
end
|
20
20
|
|
21
|
-
def
|
21
|
+
def failure_message_when_negated
|
22
22
|
"expect to NOT have json: '#{response_body}'."
|
23
23
|
end
|
24
|
+
|
25
|
+
# RSpec 2 compatibility:
|
26
|
+
alias_method :failure_message_for_should, :failure_message
|
27
|
+
alias_method :failure_message_for_should_not, :failure_message_when_negated
|
24
28
|
end
|
25
29
|
end
|
26
30
|
end
|
27
|
-
|
data/lib/api_matchers/version.rb
CHANGED
@@ -5,21 +5,21 @@ module APIMatchers::Core
|
|
5
5
|
describe "#find" do
|
6
6
|
context 'when node exists' do
|
7
7
|
it "should return the value of the expected key" do
|
8
|
-
FindInJSON.new('product' => 'gateway').find(node: 'product').
|
8
|
+
expect(FindInJSON.new('product' => 'gateway').find(node: 'product')).to eql 'gateway'
|
9
9
|
end
|
10
10
|
|
11
11
|
it "should return the value of the deep expected key in the json" do
|
12
|
-
FindInJSON.new('transaction' => { 'error' => { 'code' => '999' } }).find(node: 'code').
|
12
|
+
expect(FindInJSON.new('transaction' => { 'error' => { 'code' => '999' } }).find(node: 'code')).to eql '999'
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
16
|
context 'when node do not exists' do
|
17
17
|
it "should return nil if don't find the expected node" do
|
18
|
-
expect{ FindInJSON.new('product' => 'pabx').find(node: 'developers').
|
18
|
+
expect { FindInJSON.new('product' => 'pabx').find(node: 'developers') }.to raise_error( ::APIMatchers::Core::Exceptions::KeyNotFound)
|
19
19
|
end
|
20
20
|
|
21
21
|
it "should return nil if don't find the expected node in the deep JSON" do
|
22
|
-
expect{ FindInJSON.new('transaction' => { 'id' => 150, 'error' => {} }).find(node: 'code').
|
22
|
+
expect { FindInJSON.new('transaction' => { 'id' => 150, 'error' => {} }).find(node: 'code') }.to raise_error( ::APIMatchers::Core::Exceptions::KeyNotFound)
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
@@ -1,23 +1,27 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe APIMatchers::Headers::BeJSON do
|
4
|
-
describe "actual.
|
4
|
+
describe "actual.to be_json" do
|
5
5
|
it "should pass when the actual is json response" do
|
6
|
-
"application/json; charset=utf-8".
|
6
|
+
expect("application/json; charset=utf-8").to be_json
|
7
7
|
end
|
8
8
|
|
9
9
|
it "should not pass when the actual is not a json response" do
|
10
|
-
expect {
|
10
|
+
expect {
|
11
|
+
expect("application/xml; charset=utf-8").to be_json
|
12
|
+
}.to fail_with(%Q{expected a JSON response with 'application/json; charset=utf-8'. Got: 'application/xml; charset=utf-8'.})
|
11
13
|
end
|
12
14
|
end
|
13
15
|
|
14
|
-
describe "actual.
|
16
|
+
describe "actual.not_to be_json" do
|
15
17
|
it "should pass when the actual is not a json response" do
|
16
|
-
"application/xml; charset=utf-8".
|
18
|
+
expect("application/xml; charset=utf-8").not_to be_json
|
17
19
|
end
|
18
20
|
|
19
21
|
it "should not pass when the actual is a json response" do
|
20
|
-
expect
|
22
|
+
expect{
|
23
|
+
expect("application/json; charset=utf-8").not_to be_json
|
24
|
+
}.to fail_with(%Q{expected to not be a JSON response. Got: 'application/json; charset=utf-8'.})
|
21
25
|
end
|
22
26
|
end
|
23
27
|
|
@@ -38,17 +42,21 @@ describe APIMatchers::Headers::BeJSON do
|
|
38
42
|
|
39
43
|
it "should pass if the actual.response_header is equal to application/json" do
|
40
44
|
response = OpenStruct.new(:response_header => { 'Content-Type' => "application/json; charset=utf-8"})
|
41
|
-
response.
|
45
|
+
expect(response).to be_json
|
42
46
|
end
|
43
47
|
|
44
48
|
it "should fail if the actual.response_header is not equal to application/json" do
|
45
49
|
response = OpenStruct.new(:response_header => { "Content-Type" => "application/xml; charset=utf-8"})
|
46
|
-
expect {
|
50
|
+
expect {
|
51
|
+
expect(response).to be_json
|
52
|
+
}.to fail_with(%Q{expected a JSON response with 'application/json; charset=utf-8'. Got: 'application/xml; charset=utf-8'.})
|
47
53
|
end
|
48
54
|
|
49
55
|
it "should fail if the actual.response_header is not equal to application/json" do
|
50
56
|
response = OpenStruct.new(:response_header => { "foo-bar" => "application/xml; charset=utf-8"})
|
51
|
-
expect {
|
57
|
+
expect {
|
58
|
+
expect(response).to be_json
|
59
|
+
}.to fail_with(%Q{expected a JSON response with 'application/json; charset=utf-8'. Got: '{"foo-bar"=>"application/xml; charset=utf-8"}'.})
|
52
60
|
end
|
53
61
|
end
|
54
62
|
end
|
@@ -1,26 +1,26 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe APIMatchers::Headers::BeXML do
|
4
|
-
describe "actual.
|
4
|
+
describe "actual.to be_xml" do
|
5
5
|
it "should pass when the actual is json response" do
|
6
|
-
"application/xml; charset=utf-8".
|
6
|
+
expect("application/xml; charset=utf-8").to be_xml
|
7
7
|
end
|
8
8
|
|
9
9
|
it "should not pass when the actual is not a json response" do
|
10
10
|
expect {
|
11
|
-
"application/json; charset=utf-8".
|
11
|
+
expect("application/json; charset=utf-8").to be_xml
|
12
12
|
}.to fail_with(%Q{expected a XML response with 'application/xml; charset=utf-8'. Got: 'application/json; charset=utf-8'.})
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
describe "actual.
|
16
|
+
describe "actual.not_to be_xml" do
|
17
17
|
it "should pass when the actual is not a json response" do
|
18
|
-
"application/json; charset=utf-8".
|
18
|
+
expect("application/json; charset=utf-8").not_to be_xml
|
19
19
|
end
|
20
20
|
|
21
21
|
it "should not pass when the actual is a json response" do
|
22
22
|
expect {
|
23
|
-
"application/xml; charset=utf-8".
|
23
|
+
expect("application/xml; charset=utf-8").not_to be_xml
|
24
24
|
}.to fail_with(%Q{expected to not be a XML response. Got: 'application/xml; charset=utf-8'.})
|
25
25
|
end
|
26
26
|
end
|
@@ -42,17 +42,21 @@ describe APIMatchers::Headers::BeXML do
|
|
42
42
|
|
43
43
|
it "should pass if the actual.response_header is equal to application/xml" do
|
44
44
|
response = OpenStruct.new(:response_header => { 'Content-Type' => "application/xml; charset=utf-8"})
|
45
|
-
response.
|
45
|
+
expect(response).to be_xml
|
46
46
|
end
|
47
47
|
|
48
48
|
it "should fail if the actual.response_header is not equal to application/xml" do
|
49
49
|
response = OpenStruct.new(:response_header => { "Content-Type" => "application/json; charset=utf-8"})
|
50
|
-
expect {
|
50
|
+
expect {
|
51
|
+
expect(response).to be_xml
|
52
|
+
}.to fail_with(%Q{expected a XML response with 'application/xml; charset=utf-8'. Got: 'application/json; charset=utf-8'.})
|
51
53
|
end
|
52
54
|
|
53
55
|
it "should fail when pass the actual that have headers but not the content type key" do
|
54
56
|
response = OpenStruct.new(:response_header => { "foo-baz" => "application/json; charset=utf-8"})
|
55
|
-
expect {
|
57
|
+
expect {
|
58
|
+
expect(response).to be_xml
|
59
|
+
}.to fail_with(%Q{expected a XML response with 'application/xml; charset=utf-8'. Got: '{"foo-baz"=>"application/json; charset=utf-8"}'.})
|
56
60
|
end
|
57
61
|
end
|
58
62
|
end
|