grape-entity-matchers 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.markdown +9 -1
- data/README.markdown +15 -15
- data/grape-entity-matchers.gemspec +2 -2
- data/lib/grape_entity_matchers/represent_matcher.rb +27 -20
- data/lib/grape_entity_matchers/version.rb +1 -1
- data/spec/grape_entity_matchers/represent_matcher_spec.rb +30 -26
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81fbcbd04980d0e342d096b311b5592e2e0647d1
|
4
|
+
data.tar.gz: e5af49a9acdb697686260d67405f9c4331cfe9cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f966c2003667145459b5ba190e870f17480638025bb9768cf70ab159b2cd0f06ec14acd5d2035f53f05d5136e26b71b303101afa4ce5343ba911465707e8975
|
7
|
+
data.tar.gz: 2cd1ae0092b63c43dd1b490f47fefe3a085ba0e4751f214c45631368faf5d72c054501e75fc6a67bc5fcd5ba12842d910758a0877389a261c6f8e959effe59ed
|
data/CHANGELOG.markdown
CHANGED
@@ -1,8 +1,16 @@
|
|
1
1
|
Next Release
|
2
2
|
============
|
3
|
-
* move support from rspec 2.x to rspec 3.x
|
4
3
|
* add support for minitest
|
5
4
|
|
5
|
+
1.0.1 (07/30/2015)
|
6
|
+
============
|
7
|
+
* added fix for double from @zephyr-dev
|
8
|
+
* added formatters from @cveneziani
|
9
|
+
|
10
|
+
1.0.0 (07/30/2014)
|
11
|
+
============
|
12
|
+
* move support from rspec 2.x to rspec 3.x
|
13
|
+
|
6
14
|
0.4.1 (02/22/2014)
|
7
15
|
============
|
8
16
|
* fix error when an entity contains itself nested by nil-ing out the nested version.
|
data/README.markdown
CHANGED
@@ -13,23 +13,23 @@ Currently compatible Rspec 3.
|
|
13
13
|
Here are some examples of the matchers in use:
|
14
14
|
|
15
15
|
``` ruby
|
16
|
-
it {
|
17
|
-
it {
|
18
|
-
it {
|
19
|
-
|
20
|
-
it {
|
21
|
-
it {
|
22
|
-
|
23
|
-
it {
|
24
|
-
it {
|
25
|
-
|
26
|
-
it {
|
27
|
-
it {
|
16
|
+
it { is_expected.to represent(:date_of_birth).as(:brithday) }
|
17
|
+
it { is_expected.to_not represent(:name).as(:brithday) }
|
18
|
+
it { is_expected.to_not represent(:date_of_birth) }
|
19
|
+
|
20
|
+
it { is_expected.to represent(:secret).when( :authorized? => true ) }
|
21
|
+
it { is_expected.to_not represent(:secret).when( :authorized? => false ) }
|
22
|
+
|
23
|
+
it { is_expected.to represent(:super_dooper_secret).as(:top_secret).when( :authorized? => true ) }
|
24
|
+
it { is_expected.to_not represent(:super_dooper_secret).as(:top_secret).when( :authorized? => false ) }
|
25
|
+
|
26
|
+
it { is_expected.to represent(:dog).using(PetEntity) }
|
27
|
+
it { is_expected.to represent(:cat).as(:kitty).using(PetEntity) }
|
28
28
|
```
|
29
29
|
|
30
|
-
## Support Rspec 2.0.0
|
30
|
+
## Support for Rspec 2.0.0
|
31
31
|
|
32
|
-
Rspec 2.0.0 is no longer
|
32
|
+
Rspec 2.0.0 is no longer supported. For Rspec 2 use version 0.4.0.
|
33
33
|
|
34
34
|
## Minitest
|
35
35
|
|
@@ -63,4 +63,4 @@ MIT License. See LICENSE for details.
|
|
63
63
|
|
64
64
|
## Copyright
|
65
65
|
|
66
|
-
Copyright (c)
|
66
|
+
Copyright (c) 2014 Mark Madsen, and AGiLE ANiMAL INC.
|
@@ -15,9 +15,9 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.rubyforge_project = "grape-entity-matchers"
|
16
16
|
|
17
17
|
s.add_runtime_dependency 'grape-entity', '~> 0.4.0'
|
18
|
-
s.add_runtime_dependency 'rspec', '>= 3.
|
18
|
+
s.add_runtime_dependency 'rspec', '>= 3.2.0'
|
19
|
+
|
19
20
|
|
20
|
-
|
21
21
|
s.add_development_dependency 'rake'
|
22
22
|
s.add_development_dependency 'maruku'
|
23
23
|
s.add_development_dependency 'yard'
|
@@ -6,33 +6,39 @@ module GrapeEntityMatchers
|
|
6
6
|
def represent(representable)
|
7
7
|
RepresentMatcher.new(representable)
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
class RepresentMatcher
|
11
|
+
include ::RSpec::Mocks::ExampleMethods
|
11
12
|
def initialize(representable)
|
12
13
|
@expected_representable = representable
|
13
14
|
RSpec::Mocks::setup
|
14
15
|
end
|
15
|
-
|
16
|
+
|
16
17
|
def matches?(subject)
|
17
18
|
@subject = subject
|
18
19
|
|
19
20
|
check_methods && verify_exposure && check_value
|
20
21
|
end
|
21
|
-
|
22
|
+
|
22
23
|
def as(representation)
|
23
24
|
@actual_representation = representation
|
24
25
|
self
|
25
26
|
end
|
26
|
-
|
27
|
+
|
28
|
+
def format_with(formatter)
|
29
|
+
@formatter = formatter
|
30
|
+
self
|
31
|
+
end
|
32
|
+
|
27
33
|
def when(conditions)
|
28
34
|
@conditions = conditions
|
29
35
|
self
|
30
36
|
end
|
31
|
-
|
37
|
+
|
32
38
|
def using(other_entity)
|
33
39
|
@other_entity = other_entity
|
34
|
-
@represented_attribute = double("
|
35
|
-
@other_entity.exposures.keys.each do |key|
|
40
|
+
@represented_attribute = double("RepresentedAttribute")
|
41
|
+
@other_entity.exposures.keys.each do |key|
|
36
42
|
allow(@represented_attribute ).to receive(key).and_return( @other_entity.exposures[key].nil? ? :value : nil)
|
37
43
|
end
|
38
44
|
self
|
@@ -54,7 +60,7 @@ module GrapeEntityMatchers
|
|
54
60
|
message << "#{@subject} didn't return the correct value for #{@expected_representable}. (#{@serialized_hash[@actual_representation || @expected_representable] } != #{@represented_attribute || :value})" unless check_value
|
55
61
|
message
|
56
62
|
end
|
57
|
-
|
63
|
+
|
58
64
|
def failure_message_when_negated
|
59
65
|
message = ""
|
60
66
|
message << "Didn't expect #{@subject} to expose #{@expected_representable} correctly: #{@subject.exposures[@expected_representable]} \n" if verify_exposure
|
@@ -74,28 +80,28 @@ module GrapeEntityMatchers
|
|
74
80
|
def description
|
75
81
|
"Ensures that #{@subject} properly obtains the value of #{@expected_representable} from a mock class."
|
76
82
|
end
|
77
|
-
|
83
|
+
|
78
84
|
private
|
79
85
|
|
80
86
|
def limit_exposure_to_method(entity, method)
|
81
|
-
allow(entity).to receive(:valid_exposures).and_return(
|
87
|
+
allow(entity).to receive(:valid_exposures).and_return(
|
82
88
|
entity.exposures.slice(method)
|
83
89
|
)
|
84
90
|
end
|
85
|
-
|
91
|
+
|
86
92
|
def check_methods
|
87
|
-
@representee = double("
|
93
|
+
@representee = double("RepresentedObject")
|
88
94
|
@represented_attribute ||= :value
|
89
95
|
|
90
|
-
allow(@representee).to receive(@expected_representable).and_return(@represented_attribute)
|
96
|
+
allow(@representee).to receive(@expected_representable).and_return(@represented_attribute)
|
91
97
|
expect(@representee).to receive(@conditions.keys.first).and_return(@conditions.values.first) unless @conditions.nil?
|
92
|
-
|
98
|
+
|
93
99
|
representation = @subject.represent(@representee)
|
94
100
|
|
95
101
|
@serialized_hash = if @root
|
96
|
-
limit_exposure_to_method(representation[@root.to_s], @expected_representable)
|
102
|
+
limit_exposure_to_method(representation[@root.to_s], @expected_representable)
|
97
103
|
representation[@root.to_s].serializable_hash
|
98
|
-
else
|
104
|
+
else
|
99
105
|
limit_exposure_to_method(representation, @expected_representable)
|
100
106
|
representation.serializable_hash
|
101
107
|
end
|
@@ -107,14 +113,15 @@ module GrapeEntityMatchers
|
|
107
113
|
# here one can use #{e} to construct an error message
|
108
114
|
methods_called = false
|
109
115
|
end
|
110
|
-
|
116
|
+
|
111
117
|
methods_called
|
112
118
|
end
|
113
|
-
|
119
|
+
|
114
120
|
def verify_exposure
|
115
121
|
hash = {}
|
116
122
|
hash[:using] = @other_entity unless @other_entity.nil?
|
117
123
|
hash[:as] = @actual_representation unless @actual_representation.nil?
|
124
|
+
hash[:format_with] = @formatter if @formatter
|
118
125
|
|
119
126
|
if @conditions.nil?
|
120
127
|
@subject.exposures[@expected_representable] == hash
|
@@ -124,12 +131,12 @@ module GrapeEntityMatchers
|
|
124
131
|
exposures.delete(:if) != nil && exposures == hash
|
125
132
|
end
|
126
133
|
end
|
127
|
-
|
134
|
+
|
128
135
|
def check_value
|
129
136
|
if @other_entity
|
130
137
|
other_representation = @other_entity.represent(@represented_attribute)
|
131
138
|
|
132
|
-
other_representation.exposures.keys.each do |key|
|
139
|
+
other_representation.exposures.keys.each do |key|
|
133
140
|
allow(other_representation).to receive(key).and_return( other_representation.exposures[key].nil? ? :value : nil)
|
134
141
|
end
|
135
142
|
|
@@ -9,7 +9,11 @@ describe GrapeEntityMatchers do
|
|
9
9
|
class Person
|
10
10
|
include Grape::Entity::DSL
|
11
11
|
entity :name, :age do
|
12
|
-
|
12
|
+
format_with(:date_formatter) do |date|
|
13
|
+
date
|
14
|
+
end
|
15
|
+
|
16
|
+
expose :date_of_birth, :as => :birthday, :format_with => :date_formatter
|
13
17
|
expose :cat, :as => :feline, :using => PetEntity
|
14
18
|
expose :dog, :using => PetEntity
|
15
19
|
expose :secret, :if => lambda{ |person, options| person.authorized? }
|
@@ -32,41 +36,41 @@ describe GrapeEntityMatchers do
|
|
32
36
|
subject(:entity) { Person::Entity }
|
33
37
|
|
34
38
|
# TODO: move the tests to this format to shadow the thoughtbot tests.
|
35
|
-
# it {
|
36
|
-
context "
|
37
|
-
it {
|
39
|
+
# it { is_expected.to represent(:name) }
|
40
|
+
context "ensure the representation includes the specified property" do
|
41
|
+
it { is_expected.to represent :name}
|
38
42
|
end
|
39
|
-
|
40
|
-
it { should represent :name}
|
41
|
-
|
42
|
-
it { should represent(:date_of_birth).as(:birthday) }
|
43
|
-
|
44
|
-
it { should_not represent(:t_shirt_size) }
|
45
|
-
it { should_not represent(:t_shirt_size).as(:birthday) }
|
46
|
-
it { should_not represent(:name).as(:brithday) }
|
47
|
-
it { should_not represent(:date_of_birth) }
|
48
|
-
|
49
|
-
it { should represent(:secret).when( :authorized? => true ) }
|
50
|
-
it { should_not represent(:secret).when( :authorized? => false ) }
|
51
43
|
|
52
|
-
it {
|
53
|
-
|
54
|
-
it {
|
55
|
-
|
56
|
-
it {
|
57
|
-
it {
|
58
|
-
it {
|
44
|
+
it { is_expected.to represent :name}
|
45
|
+
|
46
|
+
it { is_expected.to represent(:date_of_birth).as(:birthday).format_with(:date_formatter) }
|
47
|
+
|
48
|
+
it { is_expected.to_not represent(:t_shirt_size) }
|
49
|
+
it { is_expected.to_not represent(:t_shirt_size).as(:birthday) }
|
50
|
+
it { is_expected.to_not represent(:name).as(:brithday) }
|
51
|
+
it { is_expected.to_not represent(:date_of_birth) }
|
52
|
+
|
53
|
+
it { is_expected.to represent(:secret).when( :authorized? => true ) }
|
54
|
+
it { is_expected.to_not represent(:secret).when( :authorized? => false ) }
|
55
|
+
|
56
|
+
it { is_expected.to represent(:super_dooper_secret).as(:top_secret).when( :authorized? => true ) }
|
57
|
+
it { is_expected.to_not represent(:super_dooper_secret).as(:top_secret).when( :authorized? => false ) }
|
58
|
+
it { is_expected.to_not represent(:super_dooper_secret).when( :authorized? => true ) }
|
59
|
+
|
60
|
+
it { is_expected.to represent(:dog).using(PetEntity) }
|
61
|
+
it { is_expected.to represent(:cat).as(:feline).using(PetEntity) }
|
62
|
+
it { is_expected.to_not represent(:cat).using(PetEntity) }
|
59
63
|
|
60
64
|
end
|
61
65
|
|
62
66
|
context 'matchers within a root' do
|
63
67
|
subject(:entity) { Vet }
|
64
|
-
it {
|
68
|
+
it { is_expected.to represent(:name).with_root('vet') }
|
65
69
|
end
|
66
70
|
|
67
71
|
context 'matchers with with a tree structure' do
|
68
72
|
subject(:entity) { ItemEntity }
|
69
|
-
it {
|
70
|
-
it {
|
73
|
+
it { is_expected.to represent(:name).as(:title) }
|
74
|
+
it { is_expected.to represent(:sub_items).as(:children).using(ItemEntity) }
|
71
75
|
end
|
72
76
|
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.0.1
|
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: 2015-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grape-entity
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 3.
|
33
|
+
version: 3.2.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 3.
|
40
|
+
version: 3.2.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
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.
|
142
|
+
rubygems_version: 2.4.5
|
143
143
|
signing_key:
|
144
144
|
specification_version: 4
|
145
145
|
summary: Shoulda-like matchers for Grape Entity.
|