endo 0.4.1 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -4
- data/endo.gemspec +1 -0
- data/endo/sample.rb +20 -13
- data/lib/endo/core.rb +19 -10
- data/lib/endo/expectation_target.rb +6 -2
- data/lib/endo/matchers.rb +3 -3
- data/lib/endo/matchers/{eq.rb → equal.rb} +1 -1
- data/lib/endo/version.rb +1 -1
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 978a8802a583f38f85e7ccbfeb7b2604bd9baaf6
|
4
|
+
data.tar.gz: 188ba02ef58b0c08d8cb49ec2efb0b8d6e9ac5d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb819ea3b6f22b72a456916c21a781b254887628bcc97efe5a83c9581abcf44076501effc2bc311e1ce18ad7e6188552de730c9c5e428ab712e09f5a0ab3dd69
|
7
|
+
data.tar.gz: 91b47b79321e6a38022b8a162945856b1aa396b90980f4c1b4b8c1ea4a189dc014ce7af9438b861ad46bc352ecf29e2b43f108729082ddd3d82abd56e63ec81c
|
data/README.md
CHANGED
@@ -12,7 +12,7 @@ base_url 'http://localhost:3000'
|
|
12
12
|
basic_auth 'user', 'pass'
|
13
13
|
|
14
14
|
get '/articles' do
|
15
|
-
expect(header: 'Content-Type').to
|
15
|
+
expect(header: 'Content-Type').to equal 'application/json; charset=utf-8'
|
16
16
|
end
|
17
17
|
|
18
18
|
post '/articles.json' do
|
@@ -22,11 +22,11 @@ end
|
|
22
22
|
|
23
23
|
get '/articles/:article_id' do
|
24
24
|
param :article_id do
|
25
|
-
from :post, '/articles.json',
|
25
|
+
from :post, '/articles.json', 'id'
|
26
26
|
end
|
27
27
|
|
28
|
-
expect(header: 'Content-Type').to
|
29
|
-
expect(body:
|
28
|
+
expect(header: 'Content-Type').to equal 'application/json'
|
29
|
+
expect(body: 'title' }).to equal 'hello'
|
30
30
|
end
|
31
31
|
```
|
32
32
|
|
data/endo.gemspec
CHANGED
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
|
22
22
|
spec.add_runtime_dependency "thor"
|
23
23
|
spec.add_runtime_dependency "colorize"
|
24
|
+
spec.add_runtime_dependency "ruby_dig"
|
24
25
|
|
25
26
|
spec.add_development_dependency "bundler", "~> 1.8"
|
26
27
|
spec.add_development_dependency "rake", "~> 10.0"
|
data/endo/sample.rb
CHANGED
@@ -2,7 +2,7 @@ base_url 'http://localhost:3000'
|
|
2
2
|
basic_auth 'user', 'pass'
|
3
3
|
|
4
4
|
get '/articles' do
|
5
|
-
expect(header: 'Content-Type').to
|
5
|
+
expect(header: 'Content-Type').to equal 'application/json; charset=utf-8'
|
6
6
|
end
|
7
7
|
|
8
8
|
post '/articles.json' do
|
@@ -11,33 +11,40 @@ post '/articles.json' do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
get '/articles/:article_id' do
|
14
|
-
param
|
15
|
-
from
|
14
|
+
param 'article_id' do
|
15
|
+
from 'post', '/articles.json', 'id'
|
16
|
+
# or
|
17
|
+
# from :post, '/articles.json', -> { self['id'] }
|
18
|
+
|
19
|
+
# or
|
20
|
+
# from :post, '/articles.json' do |r|
|
21
|
+
# r['id']
|
22
|
+
# end
|
16
23
|
end
|
17
24
|
|
18
|
-
expect(header: 'Content-Type').to
|
19
|
-
expect(body:
|
25
|
+
expect(header: 'Content-Type').to equal 'application/json; charset=utf-8'
|
26
|
+
expect(body: 'title').to equal 'hello'
|
20
27
|
end
|
21
28
|
|
22
29
|
patch '/articles/:article_id.json' do
|
23
|
-
param
|
24
|
-
from :post, '/articles.json',
|
30
|
+
param 'article_id' do
|
31
|
+
from :post, '/articles.json', 'id'
|
25
32
|
end
|
26
33
|
|
27
34
|
param 'article[title]', 'こんにちは'
|
28
35
|
end
|
29
36
|
|
30
37
|
get '/articles/:article_id' do
|
31
|
-
param
|
32
|
-
from :post, '/articles.json',
|
38
|
+
param 'article_id' do
|
39
|
+
from :post, '/articles.json', 'id'
|
33
40
|
end
|
34
41
|
|
35
|
-
expect(body:
|
42
|
+
expect(body: 'title').to equal 'こんにちは'
|
36
43
|
end
|
37
44
|
|
38
45
|
put '/articles/:article_id.json' do
|
39
|
-
param
|
40
|
-
from :post, '/articles.json',
|
46
|
+
param 'article_id' do
|
47
|
+
from :post, '/articles.json', 'id'
|
41
48
|
end
|
42
49
|
|
43
50
|
param 'article[title]', 'bonjour'
|
@@ -45,6 +52,6 @@ end
|
|
45
52
|
|
46
53
|
delete '/articles/:article_id.json' do
|
47
54
|
param :article_id do
|
48
|
-
from :post, '/articles.json',
|
55
|
+
from :post, '/articles.json', 'id'
|
49
56
|
end
|
50
57
|
end
|
data/lib/endo/core.rb
CHANGED
@@ -2,6 +2,7 @@ require 'open-uri'
|
|
2
2
|
require 'json'
|
3
3
|
require 'net/http'
|
4
4
|
require 'colorize'
|
5
|
+
require 'ruby_dig'
|
5
6
|
|
6
7
|
module Endo
|
7
8
|
class Core
|
@@ -48,19 +49,27 @@ module Endo
|
|
48
49
|
end
|
49
50
|
|
50
51
|
# TODO: Limit scope
|
51
|
-
def from(method, endpoint,
|
52
|
+
def from(method, endpoint, prop = nil, &_block)
|
52
53
|
key = build_response_key(method, endpoint)
|
53
54
|
raise "NotFoundKey [#{key}]" unless @responses.key? key
|
54
55
|
|
55
56
|
res = @responses[key]
|
56
|
-
|
57
|
-
if !
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
57
|
+
|
58
|
+
val = if !prop.nil?
|
59
|
+
if prop.is_a?(String)
|
60
|
+
res[prop]
|
61
|
+
elsif prop.is_a?(Array)
|
62
|
+
res.dig(*prop)
|
63
|
+
elsif prop.is_a?(Proc)
|
64
|
+
res.instance_exec(&prop)
|
65
|
+
else
|
66
|
+
raise ArgumentError, 'BadPropType'
|
67
|
+
end
|
68
|
+
elsif block_given?
|
69
|
+
yield res
|
70
|
+
else
|
71
|
+
raise ArgumentError, 'UndefinedBlock'
|
72
|
+
end
|
64
73
|
|
65
74
|
unless val.is_a?(String) || val.is_a?(Integer) || val.is_a?(Numeric)
|
66
75
|
raise 'BadValueType'
|
@@ -147,7 +156,7 @@ module Endo
|
|
147
156
|
end
|
148
157
|
|
149
158
|
def parse_body_json(res)
|
150
|
-
JSON.parse(res.body
|
159
|
+
JSON.parse(res.body) if res.body
|
151
160
|
end
|
152
161
|
|
153
162
|
def build_response_key(method, endpoint)
|
@@ -16,8 +16,12 @@ module Endo
|
|
16
16
|
when :header
|
17
17
|
@actual = res.header[@query]
|
18
18
|
when :body
|
19
|
-
obj = JSON.parse res.body
|
20
|
-
@actual =
|
19
|
+
obj = JSON.parse res.body
|
20
|
+
@actual = if @query.is_a? Proc
|
21
|
+
obj.instance_exec(&@query)
|
22
|
+
else
|
23
|
+
obj[@query]
|
24
|
+
end
|
21
25
|
end
|
22
26
|
@matcher.matches?(@actual)
|
23
27
|
end
|
data/lib/endo/matchers.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'endo/matchers/base_matcher'
|
2
|
-
require 'endo/matchers/
|
2
|
+
require 'endo/matchers/equal'
|
3
3
|
require 'endo/matchers/include'
|
4
4
|
|
5
5
|
module Endo
|
6
6
|
module Matchers
|
7
|
-
def
|
8
|
-
Matchers::
|
7
|
+
def equal(expected)
|
8
|
+
Matchers::Equal.new(expected)
|
9
9
|
end
|
10
10
|
|
11
11
|
def include(expected)
|
data/lib/endo/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: endo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- maruware
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-08-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: ruby_dig
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: bundler
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -106,7 +120,7 @@ files:
|
|
106
120
|
- lib/endo/expectation_target.rb
|
107
121
|
- lib/endo/matchers.rb
|
108
122
|
- lib/endo/matchers/base_matcher.rb
|
109
|
-
- lib/endo/matchers/
|
123
|
+
- lib/endo/matchers/equal.rb
|
110
124
|
- lib/endo/matchers/include.rb
|
111
125
|
- lib/endo/version.rb
|
112
126
|
homepage: https://github.com/maruware/endo
|