grape-entity-matchers 1.2.0 → 1.3.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 +5 -5
- data/.travis.yml +3 -2
- data/CHANGELOG.markdown +39 -26
- data/README.markdown +1 -1
- data/grape-entity-matchers.gemspec +2 -3
- data/lib/grape_entity_matchers.rb +1 -0
- data/lib/grape_entity_matchers/document_matcher.rb +7 -6
- data/lib/grape_entity_matchers/exposures.rb +21 -0
- data/lib/grape_entity_matchers/represent_matcher.rb +31 -13
- data/lib/grape_entity_matchers/version.rb +1 -1
- data/spec/grape_entity_matchers/document_matcher_spec.rb +26 -1
- metadata +9 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 179d037a620591d43c496fc8ee7ffa2ae1e1b93d1bb372ce16adeb2855524a54
|
4
|
+
data.tar.gz: 76a101cc479badf012f8587bf90b1164b101542f46efa4ba13dc6327c631bd95
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed9c6bf7a3ded651aafc8828418fa2675ace09c031b58b6da05999b896efd7ff000d85fb98233c7ed0d89a0eee689606e54c3ff3d7d8b7c65f20d72719cf2bb6
|
7
|
+
data.tar.gz: 31b4c0148e4f7befb14de5d3bac85b0d9fc4433163d80482cadde6752ee9ca47bdc18dd133c7bba595dc9090e75b5bacfefabeb325eb005ed76c30f22a44215a
|
data/.travis.yml
CHANGED
data/CHANGELOG.markdown
CHANGED
@@ -1,34 +1,47 @@
|
|
1
|
-
Next Release
|
2
|
-
============
|
3
|
-
* add support for minitest
|
1
|
+
# Next Release
|
4
2
|
|
5
|
-
|
6
|
-
===========
|
7
|
-
* support grape-entity ~> 0.4.6
|
8
|
-
* add with_documentation method to RepresentMatcher
|
3
|
+
- add support for minitest
|
9
4
|
|
10
|
-
1.
|
11
|
-
============
|
12
|
-
* added fix for double from @zephyr-dev
|
13
|
-
* added formatters from @cveneziani
|
5
|
+
# 1.3.1 (unreleased)
|
14
6
|
|
15
|
-
|
16
|
-
============
|
17
|
-
* move support from rspec 2.x to rspec 3.x
|
7
|
+
- {add changes here}
|
18
8
|
|
19
|
-
|
20
|
-
============
|
21
|
-
* fix error when an entity contains itself nested by nil-ing out the nested version.
|
9
|
+
# 1.3.0 (01/24/2020)
|
22
10
|
|
23
|
-
0.
|
24
|
-
|
25
|
-
|
11
|
+
- support for grape-entity >= 0.5.0
|
12
|
+
- require ruby >= 2.5
|
13
|
+
- fix deprecation warnings
|
26
14
|
|
27
|
-
|
28
|
-
============
|
29
|
-
* Fixed error in error messages.
|
15
|
+
# 1.2.0 (08/16/2016)
|
30
16
|
|
31
|
-
0.
|
32
|
-
==================
|
17
|
+
- support grape-entity 0.4.8
|
33
18
|
|
34
|
-
|
19
|
+
# 1.1.0 (06/08/2016)
|
20
|
+
|
21
|
+
- support grape-entity ~> 0.4.6
|
22
|
+
- add with_documentation method to RepresentMatcher
|
23
|
+
|
24
|
+
# 1.0.1 (07/30/2015)
|
25
|
+
|
26
|
+
- added fix for double from @zephyr-dev
|
27
|
+
- added formatters from @cveneziani
|
28
|
+
|
29
|
+
# 1.0.0 (07/30/2014)
|
30
|
+
|
31
|
+
- move support from rspec 2.x to rspec 3.x
|
32
|
+
|
33
|
+
# 0.4.1 (02/22/2014)
|
34
|
+
|
35
|
+
- fix error when an entity contains itself nested by nil-ing out the nested version.
|
36
|
+
|
37
|
+
# 0.4.0 (02/22/2014)
|
38
|
+
|
39
|
+
- Support grape-entity 0.4.0.
|
40
|
+
|
41
|
+
# 0.0.2 (01/17/2013)
|
42
|
+
|
43
|
+
- Fixed error in error messages.
|
44
|
+
|
45
|
+
# 0.0.1 (01/11/2013)
|
46
|
+
|
47
|
+
- Initial Release
|
data/README.markdown
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Grape::Entity::Matchers
|
2
2
|
|
3
|
-
[](https://travis-ci.org/agileanimal/grape-entity-matchers)
|
4
4
|
|
5
5
|
## Introduction
|
6
6
|
|
@@ -12,12 +12,11 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.description = %q{Shoulda-like matchers for Grape Entity.}
|
13
13
|
s.license = "MIT"
|
14
14
|
|
15
|
-
s.
|
15
|
+
s.required_ruby_version = '>= 2.5'
|
16
16
|
|
17
|
-
s.add_runtime_dependency 'grape-entity', '0.
|
17
|
+
s.add_runtime_dependency 'grape-entity', '>= 0.5.0'
|
18
18
|
s.add_runtime_dependency 'rspec', '>= 3.2.0'
|
19
19
|
|
20
|
-
|
21
20
|
s.add_development_dependency 'rake'
|
22
21
|
s.add_development_dependency 'maruku'
|
23
22
|
s.add_development_dependency 'yard'
|
@@ -5,6 +5,8 @@ module GrapeEntityMatchers
|
|
5
5
|
end
|
6
6
|
|
7
7
|
class DocumentMatcher
|
8
|
+
include Exposures
|
9
|
+
|
8
10
|
def initialize(documentable)
|
9
11
|
@expected_documentable = documentable
|
10
12
|
end
|
@@ -75,26 +77,25 @@ module GrapeEntityMatchers
|
|
75
77
|
|
76
78
|
def match_documentation
|
77
79
|
if has_documentation?
|
78
|
-
|
80
|
+
actual_documentation.slice(*expected_documentation.keys)
|
79
81
|
end
|
80
82
|
end
|
81
83
|
|
82
84
|
def actual_documentation
|
83
|
-
exposure.
|
85
|
+
exposure.documentation
|
84
86
|
end
|
85
87
|
|
86
88
|
def has_documentation?
|
87
|
-
|
88
|
-
exposure[:documentation]
|
89
|
+
exposures.has_key?(@expected_documentable) && actual_documentation
|
89
90
|
end
|
90
91
|
|
91
92
|
def exposure
|
92
|
-
|
93
|
+
exposures[@expected_documentable]
|
93
94
|
end
|
94
95
|
|
95
96
|
def verify_documentation
|
96
97
|
if @documentation
|
97
|
-
@documentation ==
|
98
|
+
@documentation == actual_documentation
|
98
99
|
else
|
99
100
|
expected_documentation == match_documentation
|
100
101
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module GrapeEntityMatchers
|
2
|
+
module Exposures
|
3
|
+
private
|
4
|
+
|
5
|
+
def exposures
|
6
|
+
@exposures ||= extract_exposures(@subject.root_exposures)
|
7
|
+
end
|
8
|
+
|
9
|
+
def extract_exposures(exposures, hash = {}, prefix = nil)
|
10
|
+
exposures.each_with_object(hash) do |exposure, hash|
|
11
|
+
key = "#{prefix}#{exposure.attribute}"
|
12
|
+
if exposure.is_a?(Grape::Entity::Exposure::NestingExposure)
|
13
|
+
hash[key.to_sym] = Hash.new
|
14
|
+
extract_exposures(exposure.nested_exposures.to_a, hash, "#{key}__")
|
15
|
+
else
|
16
|
+
hash[key.to_sym] = exposure
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -9,6 +9,8 @@ module GrapeEntityMatchers
|
|
9
9
|
|
10
10
|
class RepresentMatcher
|
11
11
|
include ::RSpec::Mocks::ExampleMethods
|
12
|
+
include Exposures
|
13
|
+
|
12
14
|
def initialize(representable)
|
13
15
|
@expected_representable = representable
|
14
16
|
RSpec::Mocks::setup
|
@@ -43,9 +45,8 @@ module GrapeEntityMatchers
|
|
43
45
|
def using(other_entity)
|
44
46
|
@other_entity = other_entity
|
45
47
|
@represented_attribute = double("RepresentedAttribute")
|
46
|
-
@other_entity.
|
47
|
-
|
48
|
-
end
|
48
|
+
other_entity_exposures = extract_exposures(@other_entity.root_exposures)
|
49
|
+
allow_exposure_methods(@represented_attribute, other_entity_exposures)
|
49
50
|
self
|
50
51
|
end
|
51
52
|
|
@@ -90,7 +91,7 @@ module GrapeEntityMatchers
|
|
90
91
|
|
91
92
|
def limit_exposure_to_method(entity, method)
|
92
93
|
allow(entity).to receive(:root_exposures).and_return(
|
93
|
-
entity.
|
94
|
+
extract_exposures(entity.root_exposures).slice(method).values
|
94
95
|
)
|
95
96
|
end
|
96
97
|
|
@@ -98,10 +99,19 @@ module GrapeEntityMatchers
|
|
98
99
|
@representee = double("RepresentedObject")
|
99
100
|
@represented_attribute ||= :value
|
100
101
|
|
101
|
-
|
102
|
-
|
102
|
+
# The condition will only be checked if entity has the exposure
|
103
|
+
if exposure_keys.include?(@actual_representation || @expected_representable) && !@conditions.nil?
|
104
|
+
expect(@representee).to receive(@conditions.keys.first).and_return(@conditions.values.first) unless @conditions.nil?
|
105
|
+
end
|
106
|
+
|
107
|
+
if @actual_representation
|
108
|
+
exposure = exposures.values.find { |exposure| exposure.key == @actual_representation }
|
109
|
+
allow(@representee).to receive(exposure.attribute).and_return(@represented_attribute) if exposure
|
110
|
+
else
|
111
|
+
allow(@representee).to receive(@expected_representable).and_return(@represented_attribute)
|
112
|
+
end
|
103
113
|
|
104
|
-
representation = @subject.represent(@representee)
|
114
|
+
representation = @subject.represent(@representee, only: [@actual_representation || @expected_representable])
|
105
115
|
|
106
116
|
@serialized_hash = if @root
|
107
117
|
limit_exposure_to_method(representation[@root.to_s], @expected_representable)
|
@@ -123,7 +133,11 @@ module GrapeEntityMatchers
|
|
123
133
|
end
|
124
134
|
|
125
135
|
def has_exposure?
|
126
|
-
|
136
|
+
exposures.has_key?(@expected_representable)
|
137
|
+
end
|
138
|
+
|
139
|
+
def exposure_keys
|
140
|
+
exposures.values.map { |exposure| exposure.key || exposure.attribute }
|
127
141
|
end
|
128
142
|
|
129
143
|
def verify_exposure
|
@@ -132,7 +146,7 @@ module GrapeEntityMatchers
|
|
132
146
|
hash[:as] = @actual_representation unless @actual_representation.nil?
|
133
147
|
hash[:format_with] = @formatter if @formatter
|
134
148
|
|
135
|
-
exposure =
|
149
|
+
exposure = exposures[@expected_representable].send(:options).dup
|
136
150
|
|
137
151
|
# ignore documentation unless with_documentation was specified
|
138
152
|
if @documentation
|
@@ -148,13 +162,17 @@ module GrapeEntityMatchers
|
|
148
162
|
end
|
149
163
|
end
|
150
164
|
|
165
|
+
def allow_exposure_methods(entity, exposures)
|
166
|
+
exposures.keys.each do |key|
|
167
|
+
allow(entity).to receive(key).and_return(exposures[key].nil? ? :value : nil)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
151
171
|
def check_value
|
152
172
|
if @other_entity
|
153
173
|
other_representation = @other_entity.represent(@represented_attribute)
|
154
|
-
|
155
|
-
other_representation
|
156
|
-
allow(other_representation).to receive(key).and_return( other_representation.exposures[key].nil? ? :value : nil)
|
157
|
-
end
|
174
|
+
other_representation_exposures = extract_exposures(other_representation.root_exposures)
|
175
|
+
allow_exposure_methods(other_representation, other_representation_exposures)
|
158
176
|
|
159
177
|
@serialized_hash[@actual_representation || @expected_representable] == other_representation.serializable_hash
|
160
178
|
else
|
@@ -32,7 +32,7 @@ describe GrapeEntityMatchers::DocumentMatcher do
|
|
32
32
|
|
33
33
|
context "ensure individual keys of documentation" do
|
34
34
|
it { is_expected.to document(:str).type(String) }
|
35
|
-
it { is_expected.not_to document(:str).type(
|
35
|
+
it { is_expected.not_to document(:str).type(Integer) }
|
36
36
|
|
37
37
|
it { is_expected.to document(:str).desc('Some string') }
|
38
38
|
it { is_expected.not_to document(:str).desc('Some other string') }
|
@@ -58,4 +58,29 @@ describe GrapeEntityMatchers::DocumentMatcher do
|
|
58
58
|
context "ensure that a specific documentation is not used" do
|
59
59
|
it { is_expected.to_not document(:str).with(type: String, required: false) }
|
60
60
|
end
|
61
|
+
|
62
|
+
context "with a nested exposure" do
|
63
|
+
before(:all) do
|
64
|
+
class TestEntityWithNested < Grape::Entity
|
65
|
+
expose :nested do
|
66
|
+
expose :str, documentation: {
|
67
|
+
type: String,
|
68
|
+
desc: 'Some string',
|
69
|
+
default: 'xyz',
|
70
|
+
required: false,
|
71
|
+
values: ['abc', 'xyz']
|
72
|
+
}
|
73
|
+
expose :no_doc
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
subject(:entity) do
|
79
|
+
TestEntityWithNested
|
80
|
+
end
|
81
|
+
|
82
|
+
context "ensure that a nested exposure matches the documentation" do
|
83
|
+
it { is_expected.to document(:nested__str).with(documentation) }
|
84
|
+
end
|
85
|
+
end
|
61
86
|
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape-entity-matchers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Madsen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grape-entity
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.5.0
|
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: 0.
|
26
|
+
version: 0.5.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -115,6 +115,7 @@ files:
|
|
115
115
|
- lib/grape-entity-matchers.rb
|
116
116
|
- lib/grape_entity_matchers.rb
|
117
117
|
- lib/grape_entity_matchers/document_matcher.rb
|
118
|
+
- lib/grape_entity_matchers/exposures.rb
|
118
119
|
- lib/grape_entity_matchers/represent_matcher.rb
|
119
120
|
- lib/grape_entity_matchers/rspec_integration.rb
|
120
121
|
- lib/grape_entity_matchers/version.rb
|
@@ -133,15 +134,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
133
134
|
requirements:
|
134
135
|
- - ">="
|
135
136
|
- !ruby/object:Gem::Version
|
136
|
-
version: '
|
137
|
+
version: '2.5'
|
137
138
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
139
|
requirements:
|
139
140
|
- - ">="
|
140
141
|
- !ruby/object:Gem::Version
|
141
142
|
version: '0'
|
142
143
|
requirements: []
|
143
|
-
|
144
|
-
rubygems_version: 2.4.5.1
|
144
|
+
rubygems_version: 3.0.3
|
145
145
|
signing_key:
|
146
146
|
specification_version: 4
|
147
147
|
summary: Shoulda-like matchers for Grape Entity.
|
@@ -149,4 +149,3 @@ test_files:
|
|
149
149
|
- spec/grape_entity_matchers/document_matcher_spec.rb
|
150
150
|
- spec/grape_entity_matchers/represent_matcher_spec.rb
|
151
151
|
- spec/spec_helper.rb
|
152
|
-
has_rdoc:
|