endo 0.4.1 → 0.5.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 30a81727bcc13e0b820d605e38a94e5de3efc804
4
- data.tar.gz: 26ee7de9bacac40fc237f6a32d5f790f3976d9e9
3
+ metadata.gz: 978a8802a583f38f85e7ccbfeb7b2604bd9baaf6
4
+ data.tar.gz: 188ba02ef58b0c08d8cb49ec2efb0b8d6e9ac5d9
5
5
  SHA512:
6
- metadata.gz: b2a5f170105a8bbf39b851ffa613c0d89341b55ff4ff6113e1b328fdd8c89ce30532d399baba383a9122272bf826de39c232d2de6e33f915eb85b6b3128bd85e
7
- data.tar.gz: 7db7ace6ca42dcacf4cc16a68e23af76adab5ff0f95abb0cc0417420bfca69087a9a773d291b0e3d3d1691ebd8c0c82a4843832212cc5bef330568f665f6e019
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 eq 'application/json; charset=utf-8'
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', -> { self[:id] }
25
+ from :post, '/articles.json', 'id'
26
26
  end
27
27
 
28
- expect(header: 'Content-Type').to eq 'application/json'
29
- expect(body: -> { self[:title] }).to eq 'hello'
28
+ expect(header: 'Content-Type').to equal 'application/json'
29
+ expect(body: 'title' }).to equal 'hello'
30
30
  end
31
31
  ```
32
32
 
@@ -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"
@@ -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 eq 'application/json; charset=utf-8'
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 :article_id do
15
- from :post, '/articles.json', -> { self[:id] }
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 eq 'application/json; charset=utf-8'
19
- expect(body: -> { self[:title] }).to eq 'hello'
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 :article_id do
24
- from :post, '/articles.json', -> { self[:id] }
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 :article_id do
32
- from :post, '/articles.json', -> { self[:id] }
38
+ param 'article_id' do
39
+ from :post, '/articles.json', 'id'
33
40
  end
34
41
 
35
- expect(body: -> { self[:title] }).to eq 'こんにちは'
42
+ expect(body: 'title').to equal 'こんにちは'
36
43
  end
37
44
 
38
45
  put '/articles/:article_id.json' do
39
- param :article_id do
40
- from :post, '/articles.json', -> { self[:id] }
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', -> { self[:id] }
55
+ from :post, '/articles.json', 'id'
49
56
  end
50
57
  end
@@ -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, lmd = nil, &_block)
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
- val = nil
57
- if !lmd.nil?
58
- val = res.instance_exec(&lmd)
59
- elsif block_given?
60
- val = yield res
61
- else
62
- raise ArgumentError, 'UndefinedBlock'
63
- end
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, symbolize_names: true) if 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, symbolize_names: true
20
- @actual = obj.instance_exec(&@query)
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
@@ -1,11 +1,11 @@
1
1
  require 'endo/matchers/base_matcher'
2
- require 'endo/matchers/eq'
2
+ require 'endo/matchers/equal'
3
3
  require 'endo/matchers/include'
4
4
 
5
5
  module Endo
6
6
  module Matchers
7
- def eq(expected)
8
- Matchers::Eq.new(expected)
7
+ def equal(expected)
8
+ Matchers::Equal.new(expected)
9
9
  end
10
10
 
11
11
  def include(expected)
@@ -1,6 +1,6 @@
1
1
  module Endo
2
2
  module Matchers
3
- class Eq < BaseMatcher
3
+ class Equal < BaseMatcher
4
4
  attr_reader :expected
5
5
 
6
6
  private
@@ -1,3 +1,3 @@
1
1
  module Endo
2
- VERSION = '0.4.1'
2
+ VERSION = '0.5.1'
3
3
  end
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.1
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-05-02 00:00:00.000000000 Z
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/eq.rb
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