neo4j-rspec 0.1.0 → 0.1.1
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 +4 -4
- data/README.md +23 -10
- data/lib/neo4j/rspec/matchers/has_n.rb +86 -166
- data/lib/neo4j/rspec/version.rb +1 -1
- data/neo4j-rspec.gemspec +1 -1
- metadata +14 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee149c3a79b54728a0c8eb5143504c274c24414d
|
4
|
+
data.tar.gz: 24a61f9cf468b5e96e457221329c814941a8168b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1190c3ab180492d432979ca534514bf63e0f181c056d0349f0541ce2d7efe45afbe31f7109db5e114e611c157c1b1a329a781369c73223067385e256b7a1b4e1
|
7
|
+
data.tar.gz: f06d85d848c244b0041c3532b5d4cad52ec011da42f2f43cb96b45adee1665548eafaf51772560def5cad4366ce21961951f585c7ff8c082f45ac82015e9f325
|
data/README.md
CHANGED
@@ -1,32 +1,45 @@
|
|
1
1
|
# Neo4j::Rspec [](https://travis-ci.org/sineed/neo4j-rspec)
|
2
2
|
|
3
|
-
##
|
4
|
-
|
3
|
+
## Install
|
4
|
+
Add line into your Gemfile:
|
5
5
|
```ruby
|
6
|
-
|
6
|
+
gem "neo4j-rspec"
|
7
|
+
```
|
8
|
+
or install it directly
|
7
9
|
|
8
|
-
|
10
|
+
```
|
11
|
+
gem install neo4j-rspec
|
12
|
+
```
|
9
13
|
|
14
|
+
## Examples
|
15
|
+
|
16
|
+
### Properties
|
17
|
+
|
18
|
+
```ruby
|
10
19
|
it { is_expected.to define_property :general }
|
11
20
|
it { is_expected.to define_property :string, String }
|
12
21
|
it { is_expected.to define_property :boolean, Boolean } # This might need to be `ActiveAttr::Typecasting::Boolean`
|
22
|
+
```
|
13
23
|
|
14
|
-
it { is_expected.to have_many(:written_things).with_direction(:in).without_type.with_model_class([:Post, :Comment]) }
|
15
|
-
|
16
|
-
# etc...
|
17
24
|
|
18
|
-
|
25
|
+
### `has_one` and `has_many`
|
19
26
|
|
27
|
+
```ruby
|
20
28
|
it { is_expected.to have_many(:comments) }
|
21
29
|
it { is_expected.to have_many(:comments).with_direction(:in) }
|
22
30
|
it { is_expected.to have_many(:comments).with_direction(:in).with_origin(:post) }
|
31
|
+
it { is_expected.to have_many(:written_things).with_direction(:in).without_type.with_model_class([:Post, :Comment]) }
|
32
|
+
```
|
23
33
|
|
24
|
-
|
34
|
+
### Constraints
|
25
35
|
|
36
|
+
```ruby
|
26
37
|
it { is_expected.to define_constraint :name, :unique }
|
38
|
+
```
|
27
39
|
|
28
|
-
|
40
|
+
### `created_at` and `updated_at`
|
29
41
|
|
42
|
+
```ruby
|
30
43
|
it { is_expected.to track_creations } # `created_at`
|
31
44
|
it { is_expected.to track_modifications } # `updated_at`
|
32
45
|
|
@@ -2,221 +2,141 @@ module Neo4j
|
|
2
2
|
module RSpec
|
3
3
|
module Matchers
|
4
4
|
module HasN
|
5
|
-
|
6
|
-
|
5
|
+
module With
|
6
|
+
class Base
|
7
|
+
attr_reader :expected
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
12
|
-
|
13
|
-
def add
|
14
|
-
matcher.expectation_message << expectation_message
|
15
|
-
matcher.association[key] = self
|
16
|
-
matcher
|
9
|
+
def initialize(expected)
|
10
|
+
@expected = expected
|
11
|
+
end
|
17
12
|
end
|
18
13
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
14
|
+
class DirectionMatcher < Base
|
15
|
+
def match(association)
|
16
|
+
expected == association.direction
|
17
|
+
end
|
24
18
|
|
25
|
-
|
26
|
-
|
27
|
-
if matches
|
28
|
-
matcher.negative_result_message = result_message
|
29
|
-
false
|
30
|
-
else
|
31
|
-
matcher.positive_result_message = result_message
|
32
|
-
true
|
19
|
+
def description
|
20
|
+
"with #{expected} direction"
|
33
21
|
end
|
34
22
|
end
|
35
23
|
|
36
|
-
|
24
|
+
class OriginMatcher < Base
|
25
|
+
def match(association)
|
26
|
+
expected == association.relationship_type
|
27
|
+
end
|
37
28
|
|
38
|
-
|
39
|
-
|
29
|
+
def description
|
30
|
+
"with #{expected} origin"
|
31
|
+
end
|
40
32
|
end
|
41
33
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
class DirectionMatcher < BaseMatcher
|
48
|
-
private
|
49
|
-
|
50
|
-
def key
|
51
|
-
:direction
|
52
|
-
end
|
34
|
+
class TypeMatcher < Base
|
35
|
+
def match(association)
|
36
|
+
expected == association.relationship_type
|
37
|
+
end
|
53
38
|
|
54
|
-
|
55
|
-
|
39
|
+
def description
|
40
|
+
"with #{expected} type"
|
41
|
+
end
|
56
42
|
end
|
57
43
|
|
58
|
-
|
59
|
-
|
60
|
-
|
44
|
+
class ModelClassMatcher < Base
|
45
|
+
def match(association)
|
46
|
+
actual = Array(association.model_class)
|
47
|
+
actual & expected == actual
|
48
|
+
end
|
61
49
|
|
62
|
-
|
63
|
-
|
50
|
+
def description
|
51
|
+
"with #{expected.join(', ')} model class"
|
52
|
+
end
|
64
53
|
end
|
65
54
|
end
|
66
55
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
end
|
73
|
-
|
74
|
-
def extact_actual(actual)
|
75
|
-
actual.relationship_type
|
76
|
-
end
|
77
|
-
|
78
|
-
def expectation_message
|
79
|
-
" with #{value} relationship type"
|
80
|
-
end
|
81
|
-
|
82
|
-
def negative_expectation_message
|
83
|
-
" without relationship type"
|
84
|
-
end
|
56
|
+
module Without
|
57
|
+
class TypeMatcher
|
58
|
+
def match(association)
|
59
|
+
!association.relationship_type
|
60
|
+
end
|
85
61
|
|
86
|
-
|
87
|
-
|
62
|
+
def description
|
63
|
+
"without type"
|
64
|
+
end
|
88
65
|
end
|
89
66
|
end
|
90
67
|
|
91
|
-
class
|
92
|
-
|
93
|
-
|
94
|
-
def key
|
95
|
-
:origin
|
96
|
-
end
|
97
|
-
|
98
|
-
def extact_actual(actual)
|
99
|
-
actual.relationship_type
|
68
|
+
class HaveMany
|
69
|
+
def name
|
70
|
+
:have_many
|
100
71
|
end
|
101
72
|
|
102
|
-
def
|
103
|
-
"
|
73
|
+
def description(model_name)
|
74
|
+
"have many #{model_name}"
|
104
75
|
end
|
105
76
|
|
106
|
-
def
|
107
|
-
"#{
|
77
|
+
def failure_message(model_name)
|
78
|
+
"expected the #{model_name} model to have many #{name}"
|
108
79
|
end
|
109
80
|
end
|
110
81
|
|
111
|
-
class
|
112
|
-
|
113
|
-
|
114
|
-
def key
|
115
|
-
:model_classes
|
116
|
-
end
|
117
|
-
|
118
|
-
def convert_value(val)
|
119
|
-
Array(val)
|
82
|
+
class HaveOne
|
83
|
+
def name
|
84
|
+
:have_one
|
120
85
|
end
|
121
86
|
|
122
|
-
def
|
123
|
-
|
87
|
+
def description(model_name)
|
88
|
+
"have one #{model_name}"
|
124
89
|
end
|
125
90
|
|
126
|
-
def
|
127
|
-
|
128
|
-
end
|
129
|
-
|
130
|
-
def expectation_message
|
131
|
-
" with #{value.join(", ")} model classes"
|
132
|
-
end
|
133
|
-
|
134
|
-
def result_message
|
135
|
-
"#{actual.join(", ")} model classes"
|
91
|
+
def failure_message(model_name)
|
92
|
+
"expected the #{model_name} model to have one #{name}"
|
136
93
|
end
|
137
94
|
end
|
138
95
|
|
96
|
+
extend ::RSpec::Matchers::DSL
|
139
97
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
def initialize(name, macro)
|
145
|
-
@association = {}
|
146
|
-
@association[:name] = name.to_sym
|
147
|
-
@association[:macro] = macro
|
148
|
-
@expectation_message = "#{macro_description} #{@association[:name]}"
|
149
|
-
end
|
150
|
-
|
151
|
-
def macro_description
|
152
|
-
case association[:macro]
|
153
|
-
when :has_many then "have many"
|
154
|
-
when :has_one then "have one"
|
98
|
+
[HaveMany.new, HaveOne.new].each do |macro|
|
99
|
+
matcher macro.name do |association_name|
|
100
|
+
def matchers
|
101
|
+
@matchers ||= []
|
155
102
|
end
|
156
|
-
end
|
157
|
-
|
158
|
-
def matchers
|
159
|
-
association.select { |_, v| v.is_a? BaseMatcher }
|
160
|
-
end
|
161
|
-
|
162
|
-
def with_direction(direction)
|
163
|
-
DirectionMatcher.new(self, direction).add
|
164
|
-
end
|
165
|
-
|
166
|
-
def with_type(type)
|
167
|
-
TypeMatcher.new(self, type).add
|
168
|
-
end
|
169
|
-
|
170
|
-
def without_type
|
171
|
-
TypeMatcher.new(self, false).add_negative
|
172
|
-
end
|
173
103
|
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
def with_model_class(model_class)
|
179
|
-
ModelClassesMatcher.new(self, model_class).add
|
180
|
-
end
|
104
|
+
match do |model|
|
105
|
+
association = model.class.associations[association_name]
|
106
|
+
association && matchers.all? { |m| m.match(association) }
|
107
|
+
end
|
181
108
|
|
182
|
-
|
183
|
-
|
184
|
-
|
109
|
+
chain :with_direction do |direction|
|
110
|
+
matchers.push With::DirectionMatcher.new(direction)
|
111
|
+
end
|
185
112
|
|
186
|
-
|
187
|
-
|
188
|
-
return false
|
189
|
-
else
|
190
|
-
self.positive_result_message = "association named #{association[:name]}"
|
113
|
+
chain :with_origin do |origin|
|
114
|
+
matchers.push With::OriginMatcher.new(origin)
|
191
115
|
end
|
192
116
|
|
193
|
-
|
194
|
-
|
117
|
+
chain :with_type do |type|
|
118
|
+
matchers.push With::TypeMatcher.new(type)
|
195
119
|
end
|
196
120
|
|
197
|
-
|
198
|
-
|
121
|
+
chain :with_model_class do |*model_classes|
|
122
|
+
matchers.push With::ModelClassMatcher.new(model_classes)
|
123
|
+
end
|
199
124
|
|
200
|
-
|
201
|
-
|
202
|
-
|
125
|
+
chain :without_type do
|
126
|
+
matchers.push Without::TypeMatcher.new
|
127
|
+
end
|
203
128
|
|
204
|
-
|
205
|
-
|
206
|
-
|
129
|
+
description do |model|
|
130
|
+
with_messages = matchers.map(&:description).join(" ")
|
131
|
+
macro.description(model.class.name) + " " + with_messages
|
132
|
+
end
|
207
133
|
|
208
|
-
|
209
|
-
|
134
|
+
failure_message do |model|
|
135
|
+
with_messages = matchers.map(&:description).join(" ")
|
136
|
+
macro.failure_message(model.class.name) + " " + with_messages
|
137
|
+
end
|
210
138
|
end
|
211
139
|
end
|
212
|
-
|
213
|
-
def have_many(association_name)
|
214
|
-
AssociationMatcher.new(association_name, :has_many)
|
215
|
-
end
|
216
|
-
|
217
|
-
def have_one(association_name)
|
218
|
-
AssociationMatcher.new(association_name, :has_one)
|
219
|
-
end
|
220
140
|
end
|
221
141
|
end
|
222
142
|
end
|
data/lib/neo4j/rspec/version.rb
CHANGED
data/neo4j-rspec.gemspec
CHANGED
@@ -16,6 +16,6 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
17
|
spec.require_paths = ["lib"]
|
18
18
|
|
19
|
-
spec.add_dependency "neo4j", "
|
19
|
+
spec.add_dependency "neo4j", ">= 6.0.0"
|
20
20
|
spec.add_dependency "rspec", "~> 3.4"
|
21
21
|
end
|
metadata
CHANGED
@@ -1,41 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: neo4j-rspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Denis Tataurov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: neo4j
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 6.0.0
|
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:
|
26
|
+
version: 6.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '3.4'
|
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
40
|
version: '3.4'
|
41
41
|
description: RSpec matchers for Neo4j.rb
|
@@ -45,9 +45,9 @@ executables: []
|
|
45
45
|
extensions: []
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
|
-
-
|
49
|
-
-
|
50
|
-
-
|
48
|
+
- .gitignore
|
49
|
+
- .rspec
|
50
|
+
- .travis.yml
|
51
51
|
- Gemfile
|
52
52
|
- LICENSE.txt
|
53
53
|
- README.md
|
@@ -68,17 +68,17 @@ require_paths:
|
|
68
68
|
- lib
|
69
69
|
required_ruby_version: !ruby/object:Gem::Requirement
|
70
70
|
requirements:
|
71
|
-
- -
|
71
|
+
- - '>='
|
72
72
|
- !ruby/object:Gem::Version
|
73
73
|
version: '0'
|
74
74
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
75
|
requirements:
|
76
|
-
- -
|
76
|
+
- - '>='
|
77
77
|
- !ruby/object:Gem::Version
|
78
78
|
version: '0'
|
79
79
|
requirements: []
|
80
80
|
rubyforge_project:
|
81
|
-
rubygems_version: 2.
|
81
|
+
rubygems_version: 2.0.14
|
82
82
|
signing_key:
|
83
83
|
specification_version: 4
|
84
84
|
summary: RSpec matchers for Neo4j.rb
|