grape-entity-matchers 0.0.2 → 0.4.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 +7 -0
- data/CHANGELOG.markdown +11 -2
- data/Gemfile +1 -4
- data/Guardfile +8 -8
- data/LICENSE +1 -1
- data/README.markdown +10 -0
- data/grape-entity-matchers.gemspec +2 -2
- data/lib/grape_entity_matchers/represent_matcher.rb +44 -11
- data/lib/grape_entity_matchers/version.rb +1 -1
- data/spec/grape_entity_matchers/represent_matcher_spec.rb +18 -8
- data/spec/spec_helper.rb +6 -1
- metadata +37 -57
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e4a77ad8de5fcd52e5779362cb357986aa797ae5
|
4
|
+
data.tar.gz: b215fa9e8c378c4693f219bbdeab5ecff6451ebe
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 494d033ea301b521801be9e73c426b98a6d73f7f875a6256347c0568e5c4c29beddfad12f8815d41d79ce1c042fcff0442d2c5b4670b42178b2ba8eedabcf96f
|
7
|
+
data.tar.gz: bde091cdeaf87af6b12b4ab69801111472bba8bb864d5f7e5bb3a35cc7d4bff28b4a1a727369f7c48917817bfd1ff2162ed3a5997321af802ee8cfae78cf3627
|
data/CHANGELOG.markdown
CHANGED
@@ -1,8 +1,17 @@
|
|
1
1
|
Next Release
|
2
2
|
============
|
3
|
-
*
|
3
|
+
* move support from rspec 2.x to rspec 3.x
|
4
|
+
* add support for minitest
|
4
5
|
|
5
|
-
0.
|
6
|
+
0.4.0 (02/22/2014)
|
7
|
+
============
|
8
|
+
* Support grape-entity 0.4.0.
|
9
|
+
|
10
|
+
0.0.2 (01/17/2013)
|
11
|
+
============
|
12
|
+
* Fixed error in error messages.
|
13
|
+
|
14
|
+
0.0.1 (01/11/2013)
|
6
15
|
==================
|
7
16
|
|
8
17
|
* Initial Release
|
data/Gemfile
CHANGED
@@ -3,14 +3,11 @@ source 'http://rubygems.org'
|
|
3
3
|
gemspec
|
4
4
|
|
5
5
|
group :development, :test do
|
6
|
-
gem 'pry'
|
7
|
-
gem 'guard'
|
8
6
|
gem 'guard-rspec'
|
9
7
|
gem 'guard-bundler'
|
8
|
+
gem 'terminal-notifier-guard'
|
10
9
|
gem 'rb-fsevent'
|
11
|
-
gem 'growl'
|
12
10
|
gem 'json'
|
13
|
-
gem 'rspec'
|
14
11
|
gem 'rack-test', "~> 0.6.2", :require => "rack/test"
|
15
12
|
gem 'github-markup'
|
16
13
|
end
|
data/Guardfile
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
|
2
|
-
# More info at https://github.com/guard/guard#readme
|
1
|
+
notification :terminal_notifier
|
3
2
|
|
4
|
-
guard '
|
3
|
+
guard 'bundler' do
|
4
|
+
watch('Gemfile')
|
5
|
+
# Uncomment next line if Gemfile contain `gemspec' command
|
6
|
+
# watch(/^.+\.gemspec/)
|
7
|
+
end
|
8
|
+
|
9
|
+
guard :rspec, cmd: 'bundle exec rspec' do
|
5
10
|
watch(%r{^spec/.+_spec\.rb$})
|
6
11
|
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
7
12
|
watch(%r{^spec/support/shared_versioning_examples.rb$}) { |m| "spec/" }
|
8
13
|
watch('spec/spec_helper.rb') { "spec/" }
|
9
14
|
end
|
10
15
|
|
11
|
-
|
12
|
-
guard 'bundler' do
|
13
|
-
watch('Gemfile')
|
14
|
-
watch(/^.+\.gemspec/)
|
15
|
-
end
|
data/LICENSE
CHANGED
data/README.markdown
CHANGED
@@ -6,6 +6,8 @@
|
|
6
6
|
|
7
7
|
This gem provides shoulda-style matchers for Rspec to [GrapeEntity](https://github.com/agileanimal/grape-entity).
|
8
8
|
|
9
|
+
Currently compatible with Rspec 2. For Rspec 3 use the rspec3 branch.
|
10
|
+
|
9
11
|
## Using the Matchers
|
10
12
|
|
11
13
|
Here are some examples of the matchers in use:
|
@@ -25,6 +27,14 @@ it { should represent(:dog).using(PetEntity) }
|
|
25
27
|
it { should represent(:cat).as(:kitty).using(PetEntity) }
|
26
28
|
```
|
27
29
|
|
30
|
+
## Support Rspec 3.0.0
|
31
|
+
|
32
|
+
Rspec 3.0.0 is in beta 2 at the time of writing this. Support for Rspec will be added on the ```rspec3``` branch.
|
33
|
+
|
34
|
+
## Minitest
|
35
|
+
|
36
|
+
It's coming next.
|
37
|
+
|
28
38
|
## Installation
|
29
39
|
|
30
40
|
Add this line to your application's Gemfile:
|
@@ -14,8 +14,8 @@ Gem::Specification.new do |s|
|
|
14
14
|
|
15
15
|
s.rubyforge_project = "grape-entity-matchers"
|
16
16
|
|
17
|
-
s.add_runtime_dependency 'grape-entity', '
|
18
|
-
s.add_runtime_dependency 'rspec', '~> 2.
|
17
|
+
s.add_runtime_dependency 'grape-entity', '~> 0.4.0'
|
18
|
+
s.add_runtime_dependency 'rspec', '~> 2.6'
|
19
19
|
|
20
20
|
|
21
21
|
s.add_development_dependency 'rake'
|
@@ -1,4 +1,5 @@
|
|
1
|
-
require
|
1
|
+
require "rspec/mocks"
|
2
|
+
require "rspec/mocks/standalone"
|
2
3
|
|
3
4
|
module GrapeEntityMatchers
|
4
5
|
module RepresentMatcher
|
@@ -30,6 +31,13 @@ module GrapeEntityMatchers
|
|
30
31
|
|
31
32
|
def using(other_entity)
|
32
33
|
@other_entity = other_entity
|
34
|
+
@represented_attribute = double("RepresetedAttribute")
|
35
|
+
@other_entity.exposures.keys.each {|key| allow(@represented_attribute ).to receive(key).and_return(:value)}
|
36
|
+
self
|
37
|
+
end
|
38
|
+
|
39
|
+
def with_root(root)
|
40
|
+
@root = root
|
33
41
|
self
|
34
42
|
end
|
35
43
|
|
@@ -41,15 +49,23 @@ module GrapeEntityMatchers
|
|
41
49
|
message = ""
|
42
50
|
message << "#{@subject} didn't expose #{@expected_representable} as expected: #{@subject.exposures[@expected_representable]}" unless verify_exposure
|
43
51
|
message << "#{@subject} didn't call the method #{@actual_representation || @expected_representable} to get #{@expected_representable} from the test class.\n" unless check_methods
|
44
|
-
message << "#{@subject} return the correct value for #{@expected_representable}." unless check_value
|
52
|
+
message << "#{@subject} didn't return the correct value for #{@expected_representable}. (#{@serialized_hash[@actual_representation || @expected_representable] } != #{@represented_attribute || :value})" unless check_value
|
45
53
|
message
|
46
54
|
end
|
47
55
|
|
56
|
+
def failure_message_when_negated
|
57
|
+
message = ""
|
58
|
+
message << "Didn't expect #{@subject} to expose #{@expected_representable} correctly: #{@subject.exposures[@expected_representable]} \n" if verify_exposure
|
59
|
+
message << "Didn't expect #{@subject} to call #{@actual_representation || @expected_representable} to get #{@expected_representable} from the test class.\n" if check_methods
|
60
|
+
message << "Didn't expect #{@subject} to return the correct value for #{@expected_representable}. (#{@serialized_hash[@actual_representation || @expected_representable] } != #{@represented_attribute || :value})" if check_value
|
61
|
+
message
|
62
|
+
end
|
63
|
+
|
48
64
|
def negative_failure_message
|
49
65
|
message = ""
|
50
66
|
message << "Didn't expect #{@subject} to expose #{@expected_representable} correctly: #{@subject.exposures[@expected_representable]} \n" if verify_exposure
|
51
67
|
message << "Didn't expect #{@subject} to call #{@actual_representation || @expected_representable} to get #{@expected_representable} from the test class.\n" if check_methods
|
52
|
-
message << "Didn't expect #{@subject} to return the correct value for #{@expected_representable}
|
68
|
+
message << "Didn't expect #{@subject} to return the correct value for #{@expected_representable}. (#{@serialized_hash[@actual_representation || @expected_representable] } != #{@represented_attribute || :value})" if check_value
|
53
69
|
message
|
54
70
|
end
|
55
71
|
|
@@ -58,14 +74,30 @@ module GrapeEntityMatchers
|
|
58
74
|
end
|
59
75
|
|
60
76
|
private
|
77
|
+
|
78
|
+
def limit_exposure_to_method(entity, method)
|
79
|
+
allow(entity).to receive(:valid_exposures).and_return(
|
80
|
+
entity.exposures.slice(method)
|
81
|
+
)
|
82
|
+
end
|
61
83
|
|
62
84
|
def check_methods
|
63
|
-
representee =
|
64
|
-
|
65
|
-
|
85
|
+
@representee = double("RepresetedObject")
|
86
|
+
@represented_attribute ||= :value
|
87
|
+
|
88
|
+
expect(@representee).to receive(@expected_representable).and_return(@represented_attribute)
|
89
|
+
expect(@representee).to receive(@conditions.keys.first).and_return(@conditions.values.first) unless @conditions.nil?
|
66
90
|
|
67
|
-
|
68
|
-
|
91
|
+
representation = @subject.represent(@representee)
|
92
|
+
|
93
|
+
@serialized_hash = if @root
|
94
|
+
limit_exposure_to_method(representation[@root.to_s], @expected_representable)
|
95
|
+
representation[@root.to_s].serializable_hash
|
96
|
+
else
|
97
|
+
limit_exposure_to_method(representation, @expected_representable)
|
98
|
+
representation.serializable_hash
|
99
|
+
end
|
100
|
+
|
69
101
|
begin
|
70
102
|
RSpec::Mocks::verify # run mock verifications
|
71
103
|
methods_called = true
|
@@ -85,6 +117,7 @@ module GrapeEntityMatchers
|
|
85
117
|
if @conditions.nil?
|
86
118
|
@subject.exposures[@expected_representable] == hash
|
87
119
|
else
|
120
|
+
#@representee.call(@conditions.keys.first)
|
88
121
|
exposures = @subject.exposures[@expected_representable].dup
|
89
122
|
exposures.delete(:if) != nil && exposures == hash
|
90
123
|
end
|
@@ -92,13 +125,13 @@ module GrapeEntityMatchers
|
|
92
125
|
|
93
126
|
def check_value
|
94
127
|
if @other_entity
|
95
|
-
|
96
|
-
|
128
|
+
other_representation = @other_entity.represent(@represented_attribute)
|
129
|
+
other_representation.exposures.keys.each {|key| allow(other_representation).to receive(key).and_return(:value)}
|
130
|
+
@serialized_hash[@actual_representation || @expected_representable] == other_representation.serializable_hash
|
97
131
|
else
|
98
132
|
@serialized_hash[@actual_representation || @expected_representable] == :value
|
99
133
|
end
|
100
134
|
end
|
101
|
-
|
102
135
|
end
|
103
136
|
end
|
104
137
|
end
|
@@ -9,36 +9,41 @@ describe GrapeEntityMatchers do
|
|
9
9
|
class Person
|
10
10
|
include Grape::Entity::DSL
|
11
11
|
entity :name, :age do
|
12
|
-
expose :date_of_birth, :as => :
|
12
|
+
expose :date_of_birth, :as => :birthday
|
13
13
|
expose :cat, :as => :cat, :using => PetEntity
|
14
14
|
expose :dog, :using => PetEntity
|
15
15
|
expose :secret, :if => lambda{ |person, options| person.authorized? }
|
16
16
|
expose :super_dooper_secret, :as => :top_secret, :if => lambda{ |person, options| person.authorized? }
|
17
17
|
end
|
18
18
|
end
|
19
|
+
class Vet < Grape::Entity
|
20
|
+
root 'vets', 'vet'
|
21
|
+
expose :name
|
22
|
+
end
|
23
|
+
nil
|
19
24
|
end
|
20
25
|
|
21
26
|
context 'matchers' do
|
22
|
-
subject(:entity){ Person::Entity }
|
27
|
+
subject(:entity) { Person::Entity }
|
23
28
|
|
24
29
|
# TODO: move the tests to this format to shadow the thoughtbot tests.
|
25
30
|
# it { should represent(:name) }
|
26
|
-
|
27
|
-
|
31
|
+
context "should ensure the representation includes the specified property" do
|
32
|
+
it { should represent :name}
|
28
33
|
end
|
29
34
|
|
35
|
+
it { should represent :name}
|
30
36
|
|
31
|
-
|
32
|
-
it { should represent(:date_of_birth).as(:brithday) }
|
37
|
+
it { should represent(:date_of_birth).as(:birthday) }
|
33
38
|
|
34
39
|
it { should_not represent(:t_shirt_size) }
|
35
|
-
it { should_not represent(:t_shirt_size).as(:
|
40
|
+
it { should_not represent(:t_shirt_size).as(:birthday) }
|
36
41
|
it { should_not represent(:name).as(:brithday) }
|
37
42
|
it { should_not represent(:date_of_birth) }
|
38
43
|
|
39
44
|
it { should represent(:secret).when( :authorized? => true ) }
|
40
45
|
it { should_not represent(:secret).when( :authorized? => false ) }
|
41
|
-
|
46
|
+
|
42
47
|
it { should represent(:super_dooper_secret).as(:top_secret).when( :authorized? => true ) }
|
43
48
|
it { should_not represent(:super_dooper_secret).as(:top_secret).when( :authorized? => false ) }
|
44
49
|
it { should_not represent(:super_dooper_secret).when( :authorized? => true ) }
|
@@ -48,4 +53,9 @@ describe GrapeEntityMatchers do
|
|
48
53
|
it { should_not represent(:cat).using(PetEntity) }
|
49
54
|
|
50
55
|
end
|
56
|
+
|
57
|
+
context 'matchers within a root' do
|
58
|
+
subject(:entity) { Vet }
|
59
|
+
it { should represent(:name).with_root('vet') }
|
60
|
+
end
|
51
61
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,110 +1,97 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape-entity-matchers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
version: 0.0.2
|
4
|
+
version: 0.4.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Mark Madsen
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-02-23 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
14
|
+
name: grape-entity
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.4.0
|
15
20
|
type: :runtime
|
16
21
|
prerelease: false
|
17
|
-
name: grape-entity
|
18
22
|
version_requirements: !ruby/object:Gem::Requirement
|
19
|
-
none: false
|
20
23
|
requirements:
|
21
|
-
- -
|
24
|
+
- - ~>
|
22
25
|
- !ruby/object:Gem::Version
|
23
|
-
version: 0.
|
26
|
+
version: 0.4.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
24
29
|
requirement: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
30
|
requirements:
|
27
|
-
- -
|
31
|
+
- - ~>
|
28
32
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
30
|
-
- !ruby/object:Gem::Dependency
|
33
|
+
version: '2.6'
|
31
34
|
type: :runtime
|
32
35
|
prerelease: false
|
33
|
-
name: rspec
|
34
36
|
version_requirements: !ruby/object:Gem::Requirement
|
35
|
-
none: false
|
36
37
|
requirements:
|
37
38
|
- - ~>
|
38
39
|
- !ruby/object:Gem::Version
|
39
|
-
version: '2.
|
40
|
+
version: '2.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
40
43
|
requirement: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
44
|
requirements:
|
43
|
-
- -
|
45
|
+
- - '>='
|
44
46
|
- !ruby/object:Gem::Version
|
45
|
-
version: '
|
46
|
-
- !ruby/object:Gem::Dependency
|
47
|
+
version: '0'
|
47
48
|
type: :development
|
48
49
|
prerelease: false
|
49
|
-
name: rake
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
none: false
|
52
51
|
requirements:
|
53
|
-
- -
|
52
|
+
- - '>='
|
54
53
|
- !ruby/object:Gem::Version
|
55
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: maruku
|
56
57
|
requirement: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
|
-
- !ruby/object:Gem::Dependency
|
63
62
|
type: :development
|
64
63
|
prerelease: false
|
65
|
-
name: maruku
|
66
64
|
version_requirements: !ruby/object:Gem::Requirement
|
67
|
-
none: false
|
68
65
|
requirements:
|
69
|
-
- -
|
66
|
+
- - '>='
|
70
67
|
- !ruby/object:Gem::Version
|
71
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: yard
|
72
71
|
requirement: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
72
|
requirements:
|
75
|
-
- -
|
73
|
+
- - '>='
|
76
74
|
- !ruby/object:Gem::Version
|
77
75
|
version: '0'
|
78
|
-
- !ruby/object:Gem::Dependency
|
79
76
|
type: :development
|
80
77
|
prerelease: false
|
81
|
-
name: yard
|
82
78
|
version_requirements: !ruby/object:Gem::Requirement
|
83
|
-
none: false
|
84
79
|
requirements:
|
85
|
-
- -
|
80
|
+
- - '>='
|
86
81
|
- !ruby/object:Gem::Version
|
87
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: bundler
|
88
85
|
requirement: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
86
|
requirements:
|
91
|
-
- -
|
87
|
+
- - '>='
|
92
88
|
- !ruby/object:Gem::Version
|
93
89
|
version: '0'
|
94
|
-
- !ruby/object:Gem::Dependency
|
95
90
|
type: :development
|
96
91
|
prerelease: false
|
97
|
-
name: bundler
|
98
92
|
version_requirements: !ruby/object:Gem::Requirement
|
99
|
-
none: false
|
100
|
-
requirements:
|
101
|
-
- - ! '>='
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
104
|
-
requirement: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
93
|
requirements:
|
107
|
-
- -
|
94
|
+
- - '>='
|
108
95
|
- !ruby/object:Gem::Version
|
109
96
|
version: '0'
|
110
97
|
description: Shoulda-like matchers for Grape Entity.
|
@@ -135,33 +122,26 @@ files:
|
|
135
122
|
homepage: https://github.com/agileanimal/grape-entity-matchers
|
136
123
|
licenses:
|
137
124
|
- MIT
|
125
|
+
metadata: {}
|
138
126
|
post_install_message:
|
139
127
|
rdoc_options: []
|
140
128
|
require_paths:
|
141
129
|
- lib
|
142
130
|
required_ruby_version: !ruby/object:Gem::Requirement
|
143
|
-
none: false
|
144
131
|
requirements:
|
145
|
-
- -
|
132
|
+
- - '>='
|
146
133
|
- !ruby/object:Gem::Version
|
147
|
-
segments:
|
148
|
-
- 0
|
149
|
-
hash: 186511890577646696
|
150
134
|
version: '0'
|
151
135
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
152
|
-
none: false
|
153
136
|
requirements:
|
154
|
-
- -
|
137
|
+
- - '>='
|
155
138
|
- !ruby/object:Gem::Version
|
156
|
-
segments:
|
157
|
-
- 0
|
158
|
-
hash: 186511890577646696
|
159
139
|
version: '0'
|
160
140
|
requirements: []
|
161
141
|
rubyforge_project: grape-entity-matchers
|
162
|
-
rubygems_version:
|
142
|
+
rubygems_version: 2.0.14
|
163
143
|
signing_key:
|
164
|
-
specification_version:
|
144
|
+
specification_version: 4
|
165
145
|
summary: Shoulda-like matchers for Grape Entity.
|
166
146
|
test_files:
|
167
147
|
- spec/grape_entity_matchers/represent_matcher_spec.rb
|