grape-entity-matchers 1.0.1 → 1.1.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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c0426e2c74d00cf63c93edbf8f02fe8d3b633fd
|
4
|
+
data.tar.gz: da5e0ab865318a1c637da23cefc2ebb31b11c91c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41cb2134865d792307c39b3c6e62bcc9d4237ffebbc93f141cb8b8af3a0f27651e306fcb7b3c9aa46e9f62fcf0001fc2a5513c64b8effa6b06c946891a10838c
|
7
|
+
data.tar.gz: 81e30fbd7fe9efa952c2146ebddb5c764dbf08546232700ba93862ad3d8d886ba082059f76641db507f0287b31683f7b4b6adec9ffe92a6a457bd469439a6806
|
data/README.markdown
CHANGED
@@ -13,8 +13,8 @@ Currently compatible Rspec 3.
|
|
13
13
|
Here are some examples of the matchers in use:
|
14
14
|
|
15
15
|
``` ruby
|
16
|
-
it { is_expected.to represent(:date_of_birth).as(:
|
17
|
-
it { is_expected.to_not represent(:name).as(:
|
16
|
+
it { is_expected.to represent(:date_of_birth).as(:birthday) }
|
17
|
+
it { is_expected.to_not represent(:name).as(:birthday) }
|
18
18
|
it { is_expected.to_not represent(:date_of_birth) }
|
19
19
|
|
20
20
|
it { is_expected.to represent(:secret).when( :authorized? => true ) }
|
@@ -25,6 +25,8 @@ it { is_expected.to_not represent(:super_dooper_secret).as(:top_secret).when( :a
|
|
25
25
|
|
26
26
|
it { is_expected.to represent(:dog).using(PetEntity) }
|
27
27
|
it { is_expected.to represent(:cat).as(:kitty).using(PetEntity) }
|
28
|
+
|
29
|
+
it { is_expected.to represent(:name).with_documentation(type: String) }
|
28
30
|
```
|
29
31
|
|
30
32
|
## Support for Rspec 2.0.0
|
@@ -17,7 +17,7 @@ module GrapeEntityMatchers
|
|
17
17
|
def matches?(subject)
|
18
18
|
@subject = subject
|
19
19
|
|
20
|
-
check_methods && verify_exposure && check_value
|
20
|
+
check_methods && has_exposure? && verify_exposure && check_value
|
21
21
|
end
|
22
22
|
|
23
23
|
def as(representation)
|
@@ -35,6 +35,11 @@ module GrapeEntityMatchers
|
|
35
35
|
self
|
36
36
|
end
|
37
37
|
|
38
|
+
def with_documentation(documentation)
|
39
|
+
@documentation = documentation
|
40
|
+
self
|
41
|
+
end
|
42
|
+
|
38
43
|
def using(other_entity)
|
39
44
|
@other_entity = other_entity
|
40
45
|
@represented_attribute = double("RepresentedAttribute")
|
@@ -84,7 +89,7 @@ module GrapeEntityMatchers
|
|
84
89
|
private
|
85
90
|
|
86
91
|
def limit_exposure_to_method(entity, method)
|
87
|
-
allow(entity).to receive(:
|
92
|
+
allow(entity).to receive(:root_exposures).and_return(
|
88
93
|
entity.exposures.slice(method)
|
89
94
|
)
|
90
95
|
end
|
@@ -117,18 +122,29 @@ module GrapeEntityMatchers
|
|
117
122
|
methods_called
|
118
123
|
end
|
119
124
|
|
125
|
+
def has_exposure?
|
126
|
+
@subject.exposures.has_key?(@expected_representable)
|
127
|
+
end
|
128
|
+
|
120
129
|
def verify_exposure
|
121
130
|
hash = {}
|
122
131
|
hash[:using] = @other_entity unless @other_entity.nil?
|
123
132
|
hash[:as] = @actual_representation unless @actual_representation.nil?
|
124
133
|
hash[:format_with] = @formatter if @formatter
|
125
134
|
|
135
|
+
exposure = @subject.exposures[@expected_representable].dup
|
136
|
+
|
137
|
+
# ignore documentation unless with_documentation was specified
|
138
|
+
if @documentation
|
139
|
+
hash[:documentation] = @documentation
|
140
|
+
else
|
141
|
+
exposure.delete(:documentation)
|
142
|
+
end
|
143
|
+
|
126
144
|
if @conditions.nil?
|
127
|
-
|
145
|
+
exposure == hash
|
128
146
|
else
|
129
|
-
|
130
|
-
exposures = @subject.exposures[@expected_representable].dup
|
131
|
-
exposures.delete(:if) != nil && exposures == hash
|
147
|
+
exposure.delete(:if) != nil && exposure == hash
|
132
148
|
end
|
133
149
|
end
|
134
150
|
|
@@ -29,6 +29,9 @@ describe GrapeEntityMatchers do
|
|
29
29
|
expose :name, as: :title
|
30
30
|
expose :sub_items, as: :children, using: ItemEntity
|
31
31
|
end
|
32
|
+
class Customer < Grape::Entity
|
33
|
+
expose :name, documentation: { type: String, required: true, desc: 'Customer Name' }
|
34
|
+
end
|
32
35
|
nil
|
33
36
|
end
|
34
37
|
|
@@ -73,4 +76,16 @@ describe GrapeEntityMatchers do
|
|
73
76
|
it { is_expected.to represent(:name).as(:title) }
|
74
77
|
it { is_expected.to represent(:sub_items).as(:children).using(ItemEntity) }
|
75
78
|
end
|
79
|
+
|
80
|
+
context 'matchers with documentation' do
|
81
|
+
subject(:entity) { Customer }
|
82
|
+
|
83
|
+
context "allow documentation to be ignored" do
|
84
|
+
it { is_expected.to represent(:name) }
|
85
|
+
end
|
86
|
+
|
87
|
+
context "allow documentationto be matched" do
|
88
|
+
it { is_expected.to represent(:name).with_documentation(type: String, required: true, desc: 'Customer Name') }
|
89
|
+
end
|
90
|
+
end
|
76
91
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape-entity-matchers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.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: 2016-06-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grape-entity
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.4.
|
19
|
+
version: 0.4.6
|
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.4.
|
26
|
+
version: 0.4.6
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -139,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
139
|
version: '0'
|
140
140
|
requirements: []
|
141
141
|
rubyforge_project: grape-entity-matchers
|
142
|
-
rubygems_version: 2.4.5
|
142
|
+
rubygems_version: 2.4.5.1
|
143
143
|
signing_key:
|
144
144
|
specification_version: 4
|
145
145
|
summary: Shoulda-like matchers for Grape Entity.
|