resource_kit 0.1.4 → 0.1.5
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/.travis.yml +2 -2
- data/lib/resource_kit/action_invoker.rb +1 -1
- data/lib/resource_kit/testing/action_handler_matchers.rb +9 -3
- data/lib/resource_kit/testing/have_action_matchers.rb +22 -5
- data/lib/resource_kit/version.rb +1 -1
- data/spec/lib/resource_kit/testing/action_handler_matchers_spec.rb +29 -1
- data/spec/lib/resource_kit/testing/have_action_matchers_spec.rb +50 -1
- metadata +24 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: debf0798083a39aebb213b7a9995a645398a2d1f
|
4
|
+
data.tar.gz: e5f9b6538de589a4f1318d057ce4d011d1b10000
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3de72db2d188acab91e170f1443053bb25233b5c2f7589e1367efea6d9e2393b8fb2bb24fc9ea8ec2d15a92bd623d094bc958be814576f29440634aa641bc95
|
7
|
+
data.tar.gz: 397411346322facbb8f2894f83c69f9524c14520b32ba73f8f57d80019f1358c2e3f546d94aca9ea2d049d0dfdc81cc1eaab0257c9f5ab194cbfd1fcf704297c
|
data/.travis.yml
CHANGED
@@ -32,7 +32,7 @@ module ResourceKit
|
|
32
32
|
raise ArgumentError, "Verb '#{action.verb}' is not allowed" unless ALLOWED_VERBS.include?(action.verb)
|
33
33
|
|
34
34
|
@response = connection.send(action.verb, resolver.resolve(options)) do |request|
|
35
|
-
request.body = construct_body if action.body and [:post, :put, :patch].include?(action.verb)
|
35
|
+
request.body = construct_body if action.body and [:post, :put, :patch, :delete].include?(action.verb)
|
36
36
|
append_hooks(:before, request)
|
37
37
|
end
|
38
38
|
end
|
@@ -5,7 +5,7 @@ module ResourceKit
|
|
5
5
|
class ActionHandlerMatchers
|
6
6
|
ResponseStub = Class.new(OpenStruct)
|
7
7
|
|
8
|
-
attr_reader :action, :response_stub
|
8
|
+
attr_reader :action, :response_stub, :failure_message
|
9
9
|
|
10
10
|
def initialize(action)
|
11
11
|
@action = action
|
@@ -21,10 +21,16 @@ module ResourceKit
|
|
21
21
|
def matches?(subject, &block)
|
22
22
|
@handled_block ||= block
|
23
23
|
action = subject.resources.find_action(self.action)
|
24
|
-
|
24
|
+
unless action
|
25
|
+
@failure_message = "expected :#{self.action} to be handled by the class."
|
26
|
+
return false
|
27
|
+
end
|
25
28
|
|
26
29
|
status_code = response_stub.status || 200
|
27
|
-
|
30
|
+
unless action.handlers[status_code]
|
31
|
+
@failure_message = "expected the #{status_code} status code to be handled by the class."
|
32
|
+
return false
|
33
|
+
end
|
28
34
|
|
29
35
|
handled_response = action.handlers[status_code].call(response_stub)
|
30
36
|
@handled_block.call(handled_response)
|
@@ -5,6 +5,7 @@ module ResourceKit
|
|
5
5
|
|
6
6
|
def initialize(action)
|
7
7
|
@action = action
|
8
|
+
@failures = []
|
8
9
|
end
|
9
10
|
|
10
11
|
def that_handles(*codes)
|
@@ -39,14 +40,25 @@ module ResourceKit
|
|
39
40
|
@handler_codes ||= []
|
40
41
|
end
|
41
42
|
|
43
|
+
def failure_message
|
44
|
+
return "expected class to have action #{action}." if failures.empty?
|
45
|
+
|
46
|
+
failures.map do |validation, expected, got|
|
47
|
+
"expected #{expected} #{validation}, got #{got} instead."
|
48
|
+
end.join('\n')
|
49
|
+
end
|
50
|
+
|
42
51
|
private
|
52
|
+
attr_reader :failures
|
43
53
|
|
44
54
|
def check_keys(action)
|
45
55
|
keys = action.handlers.keys
|
46
56
|
|
47
|
-
|
57
|
+
unless handler_codes.empty?
|
48
58
|
handler_codes.each do |handler_code|
|
49
|
-
|
59
|
+
unless keys.include?(handler_code)
|
60
|
+
return failed(:status_code, handler_code, keys)
|
61
|
+
end
|
50
62
|
end
|
51
63
|
end
|
52
64
|
|
@@ -55,14 +67,19 @@ module ResourceKit
|
|
55
67
|
|
56
68
|
def check_path(action)
|
57
69
|
return true unless self.path
|
58
|
-
action.path == self.path
|
70
|
+
action.path == self.path or failed(:path, self.path, action.path)
|
59
71
|
end
|
60
72
|
|
61
73
|
def check_verb(action)
|
62
74
|
return true unless self.verb
|
63
75
|
checked_verb = self.verb.kind_of?(String) ? self.verb.downcase.to_sym : self.verb
|
64
|
-
action.verb == checked_verb
|
76
|
+
action.verb == checked_verb or failed(:verb, checked_verb, action.verb)
|
77
|
+
end
|
78
|
+
|
79
|
+
def failed(validation, expected, got)
|
80
|
+
failures << [validation, expected, got]
|
81
|
+
false
|
65
82
|
end
|
66
83
|
end
|
67
84
|
end
|
68
|
-
end
|
85
|
+
end
|
data/lib/resource_kit/version.rb
CHANGED
@@ -37,4 +37,32 @@ RSpec.describe ResourceKit::Testing::ActionHandlerMatchers do
|
|
37
37
|
expect(change_var).to be(true)
|
38
38
|
end
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
|
+
describe '#failure_message' do
|
42
|
+
context "when the matchers doesnt handle the same status code" do
|
43
|
+
it 'returns "expected the #{status_code} status code to be handled by the class."' do
|
44
|
+
resource_class.resources.action :all, 'GET /all' do
|
45
|
+
handler(200) { |response| JSON.load(response.body) }
|
46
|
+
end
|
47
|
+
|
48
|
+
matcher.with(status: 201, body: '{"Hello": "World"}')
|
49
|
+
matcher.matches?(resource_class) { }
|
50
|
+
|
51
|
+
expect(matcher.failure_message).to eq('expected the 201 status code to be handled by the class.')
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "when the matchers doesnt handle the same status code" do
|
56
|
+
it 'returns "expected the #{status_code} status code to be handled by the class."' do
|
57
|
+
resource_class.resources.action :show, 'GET /all' do
|
58
|
+
handler(200) { |response| JSON.load(response.body) }
|
59
|
+
end
|
60
|
+
|
61
|
+
matcher.with(status: 200, body: '{"Hello": "World"}')
|
62
|
+
matcher.matches?(resource_class) { }
|
63
|
+
|
64
|
+
expect(matcher.failure_message).to eq('expected :all to be handled by the class.')
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -105,4 +105,53 @@ RSpec.describe ResourceKit::Testing::HaveActionMatchers do
|
|
105
105
|
end
|
106
106
|
end
|
107
107
|
end
|
108
|
-
|
108
|
+
|
109
|
+
describe '#failure_message' do
|
110
|
+
let(:resource_class) {
|
111
|
+
Class.new(ResourceKit::Resource) { |resource|
|
112
|
+
resource.resources {
|
113
|
+
action :all, 'POST valid_path' do
|
114
|
+
handler(201)
|
115
|
+
end
|
116
|
+
}
|
117
|
+
}
|
118
|
+
}
|
119
|
+
|
120
|
+
context 'when the matcher doesnt find the action' do
|
121
|
+
it 'returns "expected class to have action #{action}".' do
|
122
|
+
matcher = described_class.new(:all)
|
123
|
+
expect(matcher.failure_message).to eq('expected class to have action all.')
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
context 'when the matcher doesnt find the path' do
|
128
|
+
it 'returns "expected #{expected} path, got #{gotten_value} instead".' do
|
129
|
+
matcher = described_class.new(:all)
|
130
|
+
matcher.at_path('invalid_path')
|
131
|
+
matcher.matches?(resource_class)
|
132
|
+
|
133
|
+
expect(matcher.failure_message).to eq('expected invalid_path path, got valid_path instead.')
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
context 'when the matcher doesnt find the status code' do
|
138
|
+
it 'returns "expected #{expected} status_code, got #{gotten_value} instead".' do
|
139
|
+
matcher = described_class.new(:all)
|
140
|
+
matcher.that_handles(:ok)
|
141
|
+
matcher.matches?(resource_class)
|
142
|
+
|
143
|
+
expect(matcher.failure_message).to eq('expected 200 status_code, got [201] instead.')
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
context 'when the matcher doesnt find the verb code' do
|
148
|
+
it 'returns "expected #{expected} verb, got #{gotten_value} instead".' do
|
149
|
+
matcher = described_class.new(:all)
|
150
|
+
matcher.with_verb(:get)
|
151
|
+
matcher.matches?(resource_class)
|
152
|
+
|
153
|
+
expect(matcher.failure_message).to eq('expected get verb, got post instead.')
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resource_kit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Ross
|
@@ -9,118 +9,118 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2016-03-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: addressable
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- - ~>
|
18
|
+
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
20
|
version: 2.3.6
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- - ~>
|
25
|
+
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: 2.3.6
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: bundler
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- - ~>
|
32
|
+
- - "~>"
|
33
33
|
- !ruby/object:Gem::Version
|
34
34
|
version: '1.6'
|
35
35
|
type: :development
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
|
-
- - ~>
|
39
|
+
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '1.6'
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: rake
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
|
-
- -
|
46
|
+
- - ">="
|
47
47
|
- !ruby/object:Gem::Version
|
48
48
|
version: '0'
|
49
49
|
type: :development
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
|
-
- -
|
53
|
+
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '0'
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: faraday
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
|
-
- -
|
60
|
+
- - ">="
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: '0'
|
63
63
|
type: :development
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
|
-
- -
|
67
|
+
- - ">="
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: '0'
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: rspec
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
|
-
- - ~>
|
74
|
+
- - "~>"
|
75
75
|
- !ruby/object:Gem::Version
|
76
76
|
version: '3.0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
79
|
version_requirements: !ruby/object:Gem::Requirement
|
80
80
|
requirements:
|
81
|
-
- - ~>
|
81
|
+
- - "~>"
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '3.0'
|
84
84
|
- !ruby/object:Gem::Dependency
|
85
85
|
name: webmock
|
86
86
|
requirement: !ruby/object:Gem::Requirement
|
87
87
|
requirements:
|
88
|
-
- - ~>
|
88
|
+
- - "~>"
|
89
89
|
- !ruby/object:Gem::Version
|
90
90
|
version: 1.18.0
|
91
91
|
type: :development
|
92
92
|
prerelease: false
|
93
93
|
version_requirements: !ruby/object:Gem::Requirement
|
94
94
|
requirements:
|
95
|
-
- - ~>
|
95
|
+
- - "~>"
|
96
96
|
- !ruby/object:Gem::Version
|
97
97
|
version: 1.18.0
|
98
98
|
- !ruby/object:Gem::Dependency
|
99
99
|
name: kartograph
|
100
100
|
requirement: !ruby/object:Gem::Requirement
|
101
101
|
requirements:
|
102
|
-
- - ~>
|
102
|
+
- - "~>"
|
103
103
|
- !ruby/object:Gem::Version
|
104
104
|
version: 0.0.8
|
105
105
|
type: :development
|
106
106
|
prerelease: false
|
107
107
|
version_requirements: !ruby/object:Gem::Requirement
|
108
108
|
requirements:
|
109
|
-
- - ~>
|
109
|
+
- - "~>"
|
110
110
|
- !ruby/object:Gem::Version
|
111
111
|
version: 0.0.8
|
112
112
|
- !ruby/object:Gem::Dependency
|
113
113
|
name: pry
|
114
114
|
requirement: !ruby/object:Gem::Requirement
|
115
115
|
requirements:
|
116
|
-
- - ~>
|
116
|
+
- - "~>"
|
117
117
|
- !ruby/object:Gem::Version
|
118
118
|
version: 0.10.1
|
119
119
|
type: :development
|
120
120
|
prerelease: false
|
121
121
|
version_requirements: !ruby/object:Gem::Requirement
|
122
122
|
requirements:
|
123
|
-
- - ~>
|
123
|
+
- - "~>"
|
124
124
|
- !ruby/object:Gem::Version
|
125
125
|
version: 0.10.1
|
126
126
|
description: ''
|
@@ -132,9 +132,9 @@ executables: []
|
|
132
132
|
extensions: []
|
133
133
|
extra_rdoc_files: []
|
134
134
|
files:
|
135
|
-
- .gitignore
|
136
|
-
- .rspec
|
137
|
-
- .travis.yml
|
135
|
+
- ".gitignore"
|
136
|
+
- ".rspec"
|
137
|
+
- ".travis.yml"
|
138
138
|
- Gemfile
|
139
139
|
- LICENSE.txt
|
140
140
|
- README.md
|
@@ -177,17 +177,17 @@ require_paths:
|
|
177
177
|
- lib
|
178
178
|
required_ruby_version: !ruby/object:Gem::Requirement
|
179
179
|
requirements:
|
180
|
-
- -
|
180
|
+
- - ">="
|
181
181
|
- !ruby/object:Gem::Version
|
182
182
|
version: '2.0'
|
183
183
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
184
184
|
requirements:
|
185
|
-
- -
|
185
|
+
- - ">="
|
186
186
|
- !ruby/object:Gem::Version
|
187
187
|
version: '0'
|
188
188
|
requirements: []
|
189
189
|
rubyforge_project:
|
190
|
-
rubygems_version: 2.
|
190
|
+
rubygems_version: 2.5.1
|
191
191
|
signing_key:
|
192
192
|
specification_version: 4
|
193
193
|
summary: Resource Kit provides tools to aid in making API Clients. Such as URL resolving,
|