api_matchers 0.4.0 → 0.5.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.
- 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
@@ -1,37 +1,37 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe APIMatchers::ResponseBody::HaveJson do
|
4
|
-
describe "actual.
|
4
|
+
describe "actual).to have_json" do
|
5
5
|
context 'when pass' do
|
6
6
|
it 'equal json' do
|
7
|
-
['Petshop', 'Dogs'].to_json.
|
7
|
+
expect(['Petshop', 'Dogs'].to_json).to have_json(['Petshop', 'Dogs'])
|
8
8
|
end
|
9
9
|
|
10
10
|
it 'compares with Hash too' do
|
11
|
-
{ 'offers' => [10, 90] }.to_json.
|
11
|
+
expect({ 'offers' => [10, 90] }.to_json).to have_json({ 'offers' => [10,90] })
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
context 'when fails' do
|
16
16
|
it 'different json' do
|
17
17
|
expect {
|
18
|
-
['Petshop', 'Cats'].to_json.
|
18
|
+
expect(['Petshop', 'Cats'].to_json).to have_json(['Petshop', 'Dogs'])
|
19
19
|
}.to fail_with(%Q{expect to have json: '["Petshop","Cats"]'. Got: '["Petshop", "Cats"]'.})
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
describe "actual.
|
24
|
+
describe "actual).not_to have_json" do
|
25
25
|
context 'when pass' do
|
26
26
|
it 'different json' do
|
27
|
-
['Petshop', 'Cats'].to_json.
|
27
|
+
expect(['Petshop', 'Cats'].to_json).not_to have_json(['Petshop', 'Dogs'])
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
31
|
context 'when fails' do
|
32
32
|
it 'equal json' do
|
33
33
|
expect {
|
34
|
-
['Petshop', 'Cats'].to_json.
|
34
|
+
expect(['Petshop', 'Cats'].to_json).not_to have_json(['Petshop', 'Cats'])
|
35
35
|
}.to fail_with(%Q{expect to NOT have json: '["Petshop","Cats"]'.})
|
36
36
|
end
|
37
37
|
end
|
@@ -7,7 +7,7 @@ describe APIMatchers::ResponseBody::HaveNode do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
it "should parse the matcher for json" do
|
10
|
-
{ :product => 'chat' }.to_json.
|
10
|
+
expect({ :product => 'chat' }.to_json).to have_node(:product).with('chat')
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
@@ -17,7 +17,7 @@ describe APIMatchers::ResponseBody::HaveNode do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
it "should parse the matcher for xml" do
|
20
|
-
"<product>chat</product>".
|
20
|
+
expect("<product>chat</product>").to have_node(:product).with('chat')
|
21
21
|
end
|
22
22
|
|
23
23
|
after do
|
@@ -1,130 +1,141 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe APIMatchers::ResponseBody::HaveXmlNode do
|
4
|
-
describe "actual.
|
4
|
+
describe "actual).to have_xml_node" do
|
5
5
|
context 'expected key and value in top level' do
|
6
6
|
it "should pass when the expected key exist" do
|
7
|
-
"<product>gateway</product>".
|
7
|
+
expect("<product>gateway</product>").to have_xml_node(:product)
|
8
8
|
end
|
9
9
|
|
10
10
|
it "should fail when the expected key does not exist" do
|
11
11
|
expect {
|
12
|
-
"<product>pabx</product>".
|
12
|
+
expect("<product>pabx</product>").to have_xml_node(:developers)
|
13
13
|
}.to fail_with(%Q{expected to have node called: 'developers'. Got: '<product>pabx</product>'})
|
14
14
|
end
|
15
15
|
|
16
16
|
it "should pass when the expected key exist with the expected value" do
|
17
|
-
"<product>payment-gateway</product>".
|
17
|
+
expect("<product>payment-gateway</product>").to have_xml_node(:product).with('payment-gateway')
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should fail when the expected key exist but the expected value don't exist" do
|
21
21
|
expect {
|
22
|
-
"<product>payment-gateway</product>".
|
22
|
+
expect("<product>payment-gateway</product>").to have_xml_node(:product).with('email-marketing')
|
23
23
|
}.to fail_with(%Q{expected to have node called: 'product' with value: 'email-marketing'. Got: '<product>payment-gateway</product>'})
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should not parse the matcher for xml when you pass a json" do
|
27
27
|
expect {
|
28
|
-
{ :name => 'webdesk'}.to_json.
|
28
|
+
expect({ :name => 'webdesk'}.to_json).to have_xml_node(:name).with('webdesk')
|
29
29
|
}.to fail_with(%Q{expected to have node called: 'name' with value: 'webdesk'. Got: '{"name":"webdesk"}'})
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
33
|
context 'expected key and value in more deep in the XML' do
|
34
34
|
it "should pass when the expected key exist" do
|
35
|
-
"<transaction><id>150</id></transaction>".
|
35
|
+
expect("<transaction><id>150</id></transaction>").to have_xml_node(:id)
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should pass when the expected key and expected value exist" do
|
39
|
-
"<transaction><error><code>999</code></error></transaction>".
|
39
|
+
expect("<transaction><error><code>999</code></error></transaction>").to have_xml_node(:code).with('999')
|
40
40
|
end
|
41
41
|
|
42
42
|
it "should fail when the expected key does not exist" do
|
43
43
|
expect {
|
44
|
-
"<transaction><error></error></transaction>".
|
44
|
+
expect("<transaction><error></error></transaction>").to have_xml_node(:code)
|
45
45
|
}.to fail_with(%Q{expected to have node called: 'code'. Got: '<transaction><error></error></transaction>'})
|
46
46
|
end
|
47
47
|
|
48
48
|
it "should fail when the expected key exist but don't exist the expected value" do
|
49
49
|
expect {
|
50
|
-
"<transaction><error><code>999</code></error></transaction>".
|
50
|
+
expect("<transaction><error><code>999</code></error></transaction>").to have_xml_node(:code).with('001')
|
51
51
|
}.to fail_with(%Q{expected to have node called: 'code' with value: '001'. Got: '<transaction><error><code>999</code></error></transaction>'})
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
55
|
context "including_text" do
|
56
56
|
it "should pass when the expected is included in the actual" do
|
57
|
-
"<error><message>Transaction error: Name can't be blank</message></error>".
|
57
|
+
expect("<error><message>Transaction error: Name can't be blank</message></error>").to have_xml_node(:message).including_text("Transaction error")
|
58
58
|
end
|
59
59
|
|
60
60
|
it "should fail when the expected is not included in the actual" do
|
61
61
|
expect {
|
62
|
-
"<error><message>Transaction error: Name can't be blank</message></error>".
|
62
|
+
expect("<error><message>Transaction error: Name can't be blank</message></error>").to have_xml_node(:message).including_text("Fox on the run")
|
63
63
|
}.to fail_with(%Q{expected to have node called: 'message' including text: 'Fox on the run'. Got: '<error><message>Transaction error: Name can't be blank</message></error>'})
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
67
|
context "find matching node when multiple records" do
|
68
68
|
it "should pass when the expected is included in the actual (1 level)" do
|
69
|
-
%{
|
70
|
-
<
|
71
|
-
|
72
|
-
|
69
|
+
expect(%{
|
70
|
+
<messages>
|
71
|
+
<message><id>4</id></message>
|
72
|
+
<message><id>2</id></message>
|
73
|
+
</messages>
|
74
|
+
}).to have_xml_node(:id).with(2)
|
73
75
|
end
|
76
|
+
|
74
77
|
it "should fail when the expected is not included in the actual (1 level)" do
|
75
|
-
%{
|
76
|
-
<
|
77
|
-
|
78
|
-
|
78
|
+
expect(%{
|
79
|
+
<messages>
|
80
|
+
<message><id>4</id></message>
|
81
|
+
<message><id>2</id></message>
|
82
|
+
</messages>
|
83
|
+
}).not_to have_xml_node(:id).with(3)
|
79
84
|
end
|
85
|
+
|
80
86
|
it "should pass when the expected is included in the actual (2 levels)" do
|
81
|
-
%{
|
82
|
-
<
|
83
|
-
|
84
|
-
|
87
|
+
expect(%{
|
88
|
+
<messages>
|
89
|
+
<message><header><id>4</id></header></message>
|
90
|
+
<message><header><id>2</id></header></message>
|
91
|
+
</messages>
|
92
|
+
}).to have_xml_node(:id).with(2)
|
85
93
|
end
|
94
|
+
|
86
95
|
it "should fail when the expected is not included in the actual (2 levels)" do
|
87
|
-
%{
|
88
|
-
<
|
89
|
-
|
90
|
-
|
96
|
+
expect(%{
|
97
|
+
<messages>
|
98
|
+
<message><header><id>4</id></header></message>
|
99
|
+
<message><header><id>2</id></header></message>
|
100
|
+
</messages>
|
101
|
+
}).not_to have_xml_node(:id).with(3)
|
91
102
|
end
|
92
103
|
end
|
93
104
|
end
|
94
105
|
|
95
|
-
describe "actual.
|
106
|
+
describe "actual).not_to have_xml_node" do
|
96
107
|
it "should pass when don't have the expected node in root level" do
|
97
|
-
"<product>gateway</product>".
|
108
|
+
expect("<product>gateway</product>").not_to have_xml_node(:status)
|
98
109
|
end
|
99
110
|
|
100
111
|
it "should pass when don't have the expected node in any level" do
|
101
|
-
"<transaction><id>12</id><status>paid</status></transaction>".
|
112
|
+
expect("<transaction><id>12</id><status>paid</status></transaction>").not_to have_xml_node(:error)
|
102
113
|
end
|
103
114
|
|
104
115
|
it "should fail when the expected key exist" do
|
105
116
|
expect {
|
106
|
-
"<transaction><status>paid</status></transaction>".
|
117
|
+
expect("<transaction><status>paid</status></transaction>").not_to have_xml_node(:status)
|
107
118
|
}.to fail_with(%Q{expected to NOT have node called: 'status'. Got: '<transaction><status>paid</status></transaction>'})
|
108
119
|
end
|
109
120
|
|
110
121
|
it "should pass when have the expected key but have a different value" do
|
111
|
-
"<status>paid</status>".
|
122
|
+
expect("<status>paid</status>").not_to have_xml_node(:status).with('not_authorized')
|
112
123
|
end
|
113
124
|
|
114
125
|
it "should fail when have the expected key and have the expected value" do
|
115
126
|
expect {
|
116
|
-
"<transaction><status>paid</status></transaction>".
|
127
|
+
expect("<transaction><status>paid</status></transaction>").not_to have_xml_node(:status).with('paid')
|
117
128
|
}.to fail_with(%Q{expected to NOT have node called: 'status' with value: 'paid'. Got: '<transaction><status>paid</status></transaction>'})
|
118
129
|
end
|
119
130
|
|
120
131
|
context "including_text" do
|
121
132
|
it "should pass when the expected is included in the actual" do
|
122
|
-
"<error><message>Transaction error: Name can't be blank</message></error>".
|
133
|
+
expect("<error><message>Transaction error: Name can't be blank</message></error>").not_to have_xml_node(:message).including_text("Girls of Summer")
|
123
134
|
end
|
124
135
|
|
125
136
|
it "should fail when the expected is not included in the actual" do
|
126
137
|
expect {
|
127
|
-
"<error><message>Transaction error: Name can't be blank</message></error>".
|
138
|
+
expect("<error><message>Transaction error: Name can't be blank</message></error>").not_to have_xml_node(:message).including_text("Transaction error")
|
128
139
|
}.to fail_with(%Q{expected to NOT have node called: 'message' including text: 'Transaction error'. Got: '<error><message>Transaction error: Name can't be blank</message></error>'})
|
129
140
|
end
|
130
141
|
end
|
@@ -142,12 +153,14 @@ describe APIMatchers::ResponseBody::HaveXmlNode do
|
|
142
153
|
|
143
154
|
it "should pass if the actual.http_status is equal to 400" do
|
144
155
|
response = OpenStruct.new(:response_body => "<foo>bar</foo>")
|
145
|
-
response.
|
156
|
+
expect(response).to have_xml_node(:foo).with('bar')
|
146
157
|
end
|
147
158
|
|
148
159
|
it "should fail if the actual.http_status is not equal to 400" do
|
149
160
|
response = OpenStruct.new(:response_body => "<baz>bar</baz>")
|
150
|
-
expect {
|
161
|
+
expect {
|
162
|
+
expect(response).to have_xml_node(:bar)
|
163
|
+
}.to fail_with(%Q{expected to have node called: 'bar'. Got: '<baz>bar</baz>'})
|
151
164
|
end
|
152
165
|
end
|
153
166
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api_matchers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomas D'Stefano
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2.
|
19
|
+
version: '2.14'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 2.
|
26
|
+
version: '2.14'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activesupport
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -60,6 +60,7 @@ extensions: []
|
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
62
|
- .gitignore
|
63
|
+
- .rspec
|
63
64
|
- .rvmrc.example
|
64
65
|
- .travis.yml
|
65
66
|
- Gemfile
|
@@ -84,6 +85,7 @@ files:
|
|
84
85
|
- lib/api_matchers/http_status_code/be_not_found.rb
|
85
86
|
- lib/api_matchers/http_status_code/be_ok.rb
|
86
87
|
- lib/api_matchers/http_status_code/be_unauthorized.rb
|
88
|
+
- lib/api_matchers/http_status_code/be_unprocessable_entity.rb
|
87
89
|
- lib/api_matchers/http_status_code/create_resource.rb
|
88
90
|
- lib/api_matchers/response_body/base.rb
|
89
91
|
- lib/api_matchers/response_body/have_json.rb
|
@@ -102,6 +104,7 @@ files:
|
|
102
104
|
- spec/api_matchers/http_status_code/be_not_found_spec.rb
|
103
105
|
- spec/api_matchers/http_status_code/be_ok_spec.rb
|
104
106
|
- spec/api_matchers/http_status_code/be_unauthorized_spec.rb
|
107
|
+
- spec/api_matchers/http_status_code/be_unprocessable_entity_spec.rb
|
105
108
|
- spec/api_matchers/http_status_code/create_resource_spec.rb
|
106
109
|
- spec/api_matchers/response_body/base_spec.rb
|
107
110
|
- spec/api_matchers/response_body/have_json_node_spec.rb
|
@@ -128,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
131
|
version: '0'
|
129
132
|
requirements: []
|
130
133
|
rubyforge_project:
|
131
|
-
rubygems_version: 2.
|
134
|
+
rubygems_version: 2.0.5
|
132
135
|
signing_key:
|
133
136
|
specification_version: 4
|
134
137
|
summary: Collection of RSpec matchers for create your API.
|
@@ -144,6 +147,7 @@ test_files:
|
|
144
147
|
- spec/api_matchers/http_status_code/be_not_found_spec.rb
|
145
148
|
- spec/api_matchers/http_status_code/be_ok_spec.rb
|
146
149
|
- spec/api_matchers/http_status_code/be_unauthorized_spec.rb
|
150
|
+
- spec/api_matchers/http_status_code/be_unprocessable_entity_spec.rb
|
147
151
|
- spec/api_matchers/http_status_code/create_resource_spec.rb
|
148
152
|
- spec/api_matchers/response_body/base_spec.rb
|
149
153
|
- spec/api_matchers/response_body/have_json_node_spec.rb
|