grape-entity-matchers 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 81fbcbd04980d0e342d096b311b5592e2e0647d1
4
- data.tar.gz: e5af49a9acdb697686260d67405f9c4331cfe9cc
3
+ metadata.gz: 5c0426e2c74d00cf63c93edbf8f02fe8d3b633fd
4
+ data.tar.gz: da5e0ab865318a1c637da23cefc2ebb31b11c91c
5
5
  SHA512:
6
- metadata.gz: 7f966c2003667145459b5ba190e870f17480638025bb9768cf70ab159b2cd0f06ec14acd5d2035f53f05d5136e26b71b303101afa4ce5343ba911465707e8975
7
- data.tar.gz: 2cd1ae0092b63c43dd1b490f47fefe3a085ba0e4751f214c45631368faf5d72c054501e75fc6a67bc5fcd5ba12842d910758a0877389a261c6f8e959effe59ed
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(:brithday) }
17
- it { is_expected.to_not represent(:name).as(:brithday) }
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
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
14
14
 
15
15
  s.rubyforge_project = "grape-entity-matchers"
16
16
 
17
- s.add_runtime_dependency 'grape-entity', '~> 0.4.0'
17
+ s.add_runtime_dependency 'grape-entity', '~> 0.4.6'
18
18
  s.add_runtime_dependency 'rspec', '>= 3.2.0'
19
19
 
20
20
 
@@ -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(:valid_exposures).and_return(
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
- @subject.exposures[@expected_representable] == hash
145
+ exposure == hash
128
146
  else
129
- #@representee.call(@conditions.keys.first)
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
 
@@ -1,3 +1,3 @@
1
1
  module GrapeEntityMatchers
2
- VERSION = '1.0.1'
2
+ VERSION = '1.1.0'
3
3
  end
@@ -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.1
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: 2015-03-11 00:00:00.000000000 Z
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.0
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.0
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.