grape-entity-matchers 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -2
- data/CHANGELOG.markdown +5 -0
- data/README.markdown +3 -0
- data/grape-entity-matchers.gemspec +1 -1
- data/lib/grape_entity_matchers.rb +1 -0
- data/lib/grape_entity_matchers/document_matcher.rb +104 -0
- data/lib/grape_entity_matchers/represent_matcher.rb +1 -1
- data/lib/grape_entity_matchers/rspec_integration.rb +3 -1
- data/lib/grape_entity_matchers/version.rb +1 -1
- data/spec/grape_entity_matchers/document_matcher_spec.rb +61 -0
- metadata +9 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 85553a894b305c75e1d5d6c553f63672227d72f2
|
4
|
+
data.tar.gz: 6823417b9c2ca57cb21f20b9989ade6a942a3e7e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c99842401858a6303bb01c0901bc00a5f1467aad81ab4572405020ad76b0e745ebb968e97ad56761063a0803bca5200ca037f17086643183a13260be8727ff3
|
7
|
+
data.tar.gz: a2c0306cb164ce03f5033a39b4cff116e7e4da5d0b4018332caeba80a53941aabfc1f2ff6b9a42aae2b62b9e30a6e86739e71add41a5dbf2d876c4a59b962cb4
|
data/.travis.yml
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
rvm:
|
2
|
-
- 2.
|
3
|
-
- 2.
|
2
|
+
- 2.2.5
|
3
|
+
- 2.3.1
|
data/CHANGELOG.markdown
CHANGED
@@ -2,6 +2,11 @@ Next Release
|
|
2
2
|
============
|
3
3
|
* add support for minitest
|
4
4
|
|
5
|
+
1.1.0 (06/08/2016)
|
6
|
+
===========
|
7
|
+
* support grape-entity ~> 0.4.6
|
8
|
+
* add with_documentation method to RepresentMatcher
|
9
|
+
|
5
10
|
1.0.1 (07/30/2015)
|
6
11
|
============
|
7
12
|
* added fix for double from @zephyr-dev
|
data/README.markdown
CHANGED
@@ -27,6 +27,9 @@ it { is_expected.to represent(:dog).using(PetEntity) }
|
|
27
27
|
it { is_expected.to represent(:cat).as(:kitty).using(PetEntity) }
|
28
28
|
|
29
29
|
it { is_expected.to represent(:name).with_documentation(type: String) }
|
30
|
+
|
31
|
+
it { is_expected.to document(:name).with(type: String, desc: 'Name of the person') }
|
32
|
+
it { is_expected.to document(:name).type(String).desc('Name of the person') }
|
30
33
|
```
|
31
34
|
|
32
35
|
## Support for Rspec 2.0.0
|
@@ -0,0 +1,104 @@
|
|
1
|
+
module GrapeEntityMatchers
|
2
|
+
module DocumentMatcher
|
3
|
+
def document(documentable)
|
4
|
+
DocumentMatcher.new(documentable)
|
5
|
+
end
|
6
|
+
|
7
|
+
class DocumentMatcher
|
8
|
+
def initialize(documentable)
|
9
|
+
@expected_documentable = documentable
|
10
|
+
end
|
11
|
+
|
12
|
+
def description
|
13
|
+
"ensure that #{@subject} documents the #{@expected_documentable} exposure"
|
14
|
+
end
|
15
|
+
|
16
|
+
def matches?(subject)
|
17
|
+
@subject = subject
|
18
|
+
|
19
|
+
has_documentation? && verify_documentation
|
20
|
+
end
|
21
|
+
|
22
|
+
def type(type_value)
|
23
|
+
@type = type_value
|
24
|
+
self
|
25
|
+
end
|
26
|
+
|
27
|
+
def required(required_value)
|
28
|
+
@required = required_value
|
29
|
+
self
|
30
|
+
end
|
31
|
+
|
32
|
+
def desc(desc_value)
|
33
|
+
@desc = desc_value
|
34
|
+
self
|
35
|
+
end
|
36
|
+
|
37
|
+
def default(default_value)
|
38
|
+
@default = default_value
|
39
|
+
self
|
40
|
+
end
|
41
|
+
|
42
|
+
def values(values)
|
43
|
+
@values = values
|
44
|
+
self
|
45
|
+
end
|
46
|
+
|
47
|
+
def with(documentation)
|
48
|
+
@documentation = documentation
|
49
|
+
self
|
50
|
+
end
|
51
|
+
|
52
|
+
def failure_message
|
53
|
+
"#{@subject} didn't document #{@expected_documentable} "\
|
54
|
+
"as expected: #{expected_documentation}, got #{match_documentation}"
|
55
|
+
end
|
56
|
+
|
57
|
+
def failure_message_when_negated
|
58
|
+
message = "didn't expect #{@subject} to document #{@expected_documentable}"
|
59
|
+
message << " with: #{expected_documentation}" unless expected_documentation.empty?
|
60
|
+
message << ", got: #{actual_documentation}"
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def expected_documentation
|
66
|
+
@documentation ||
|
67
|
+
{
|
68
|
+
type: @type,
|
69
|
+
desc: @desc,
|
70
|
+
required: @required,
|
71
|
+
default: @default,
|
72
|
+
values: @values
|
73
|
+
}.compact
|
74
|
+
end
|
75
|
+
|
76
|
+
def match_documentation
|
77
|
+
if has_documentation?
|
78
|
+
exposure[:documentation].slice(*expected_documentation.keys)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def actual_documentation
|
83
|
+
exposure.try(:[], :documentation)
|
84
|
+
end
|
85
|
+
|
86
|
+
def has_documentation?
|
87
|
+
@subject.exposures.has_key?(@expected_documentable) &&
|
88
|
+
exposure[:documentation]
|
89
|
+
end
|
90
|
+
|
91
|
+
def exposure
|
92
|
+
@subject.exposures[@expected_documentable]
|
93
|
+
end
|
94
|
+
|
95
|
+
def verify_documentation
|
96
|
+
if @documentation
|
97
|
+
@documentation == exposure[:documentation]
|
98
|
+
else
|
99
|
+
expected_documentation == match_documentation
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'grape_entity'
|
3
|
+
|
4
|
+
describe GrapeEntityMatchers::DocumentMatcher do
|
5
|
+
let(:documentation) do
|
6
|
+
{
|
7
|
+
type: String,
|
8
|
+
desc: 'Some string',
|
9
|
+
default: 'xyz',
|
10
|
+
required: false,
|
11
|
+
values: ['abc', 'xyz']
|
12
|
+
}
|
13
|
+
end
|
14
|
+
before(:all) do
|
15
|
+
class TestEntity < Grape::Entity
|
16
|
+
expose :str, documentation: {
|
17
|
+
type: String,
|
18
|
+
desc: 'Some string',
|
19
|
+
default: 'xyz',
|
20
|
+
required: false,
|
21
|
+
values: ['abc', 'xyz']
|
22
|
+
}
|
23
|
+
expose :no_doc
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
subject(:entity) { TestEntity }
|
28
|
+
|
29
|
+
context "ensure that the exposure matches the documentation" do
|
30
|
+
it { is_expected.to document(:str).with(documentation) }
|
31
|
+
end
|
32
|
+
|
33
|
+
context "ensure individual keys of documentation" do
|
34
|
+
it { is_expected.to document(:str).type(String) }
|
35
|
+
it { is_expected.not_to document(:str).type(Fixnum) }
|
36
|
+
|
37
|
+
it { is_expected.to document(:str).desc('Some string') }
|
38
|
+
it { is_expected.not_to document(:str).desc('Some other string') }
|
39
|
+
|
40
|
+
it { is_expected.to document(:str).default('xyz') }
|
41
|
+
it { is_expected.not_to document(:str).default('abc') }
|
42
|
+
|
43
|
+
it { is_expected.to document(:str).required(false) }
|
44
|
+
it { is_expected.not_to document(:str).required(true) }
|
45
|
+
|
46
|
+
it { is_expected.to document(:str).values(['abc', 'xyz']) }
|
47
|
+
it { is_expected.not_to document(:str).values(['foo', 'bar']) }
|
48
|
+
end
|
49
|
+
|
50
|
+
context "ensure a combination of keys of documentation" do
|
51
|
+
it { is_expected.to document(:str).type(String).desc('Some string') }
|
52
|
+
end
|
53
|
+
|
54
|
+
context "ensure that an exposure is not documented" do
|
55
|
+
it { is_expected.to_not document(:no_doc) }
|
56
|
+
end
|
57
|
+
|
58
|
+
context "ensure that a specific documentation is not used" do
|
59
|
+
it { is_expected.to_not document(:str).with(type: String, required: false) }
|
60
|
+
end
|
61
|
+
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.2.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: 2016-
|
11
|
+
date: 2016-08-17 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.4.
|
19
|
+
version: 0.4.8
|
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.8
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,9 +114,11 @@ files:
|
|
114
114
|
- grape-entity-matchers.gemspec
|
115
115
|
- lib/grape-entity-matchers.rb
|
116
116
|
- lib/grape_entity_matchers.rb
|
117
|
+
- lib/grape_entity_matchers/document_matcher.rb
|
117
118
|
- lib/grape_entity_matchers/represent_matcher.rb
|
118
119
|
- lib/grape_entity_matchers/rspec_integration.rb
|
119
120
|
- lib/grape_entity_matchers/version.rb
|
121
|
+
- spec/grape_entity_matchers/document_matcher_spec.rb
|
120
122
|
- spec/grape_entity_matchers/represent_matcher_spec.rb
|
121
123
|
- spec/spec_helper.rb
|
122
124
|
homepage: https://github.com/agileanimal/grape-entity-matchers
|
@@ -144,6 +146,7 @@ signing_key:
|
|
144
146
|
specification_version: 4
|
145
147
|
summary: Shoulda-like matchers for Grape Entity.
|
146
148
|
test_files:
|
149
|
+
- spec/grape_entity_matchers/document_matcher_spec.rb
|
147
150
|
- spec/grape_entity_matchers/represent_matcher_spec.rb
|
148
151
|
- spec/spec_helper.rb
|
149
152
|
has_rdoc:
|