neo4j-rspec 0.1.0 → 0.1.1

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: a0ad68a0d597c5eb07fd04204d67753160f3ca37
4
- data.tar.gz: 10796e7f9d7fd0237f04259862e41173e932378c
3
+ metadata.gz: ee149c3a79b54728a0c8eb5143504c274c24414d
4
+ data.tar.gz: 24a61f9cf468b5e96e457221329c814941a8168b
5
5
  SHA512:
6
- metadata.gz: 17f1dbc7daaf197cbda8d4c06ce0d6ada2b759a0d1e0bd1399e24894b51702bd67405f3777bbd76823e65a0c2da7252808f50d6756e593635ea2ebc68520695d
7
- data.tar.gz: 2a455fc7025658b6970828ed7c9f10e84d22cbfa6e5fe5b7e827fc84d7372cc2a1836d43d9662462cee3695053b509f2adac53fc604be11dcc5162443c73d1f0
6
+ metadata.gz: 1190c3ab180492d432979ca534514bf63e0f181c056d0349f0541ce2d7efe45afbe31f7109db5e114e611c157c1b1a329a781369c73223067385e256b7a1b4e1
7
+ data.tar.gz: f06d85d848c244b0041c3532b5d4cad52ec011da42f2f43cb96b45adee1665548eafaf51772560def5cad4366ce21961951f585c7ff8c082f45ac82015e9f325
data/README.md CHANGED
@@ -1,32 +1,45 @@
1
1
  # Neo4j::Rspec [![Build Status](https://travis-ci.org/sineed/neo4j-rspec.svg?branch=master)](https://travis-ci.org/sineed/neo4j-rspec)
2
2
 
3
- ## Examples
4
-
3
+ ## Install
4
+ Add line into your Gemfile:
5
5
  ```ruby
6
- subject { ModelClass }
6
+ gem "neo4j-rspec"
7
+ ```
8
+ or install it directly
7
9
 
8
- # Properties
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
- # `has_one` and `has_many`
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
- # Constraints
34
+ ### Constraints
25
35
 
36
+ ```ruby
26
37
  it { is_expected.to define_constraint :name, :unique }
38
+ ```
27
39
 
28
- # `created_at` and `updated_at`
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
- class BaseMatcher
6
- attr_reader :matcher, :value, :key, :actual
5
+ module With
6
+ class Base
7
+ attr_reader :expected
7
8
 
8
- def initialize(matcher, value)
9
- @matcher = matcher
10
- @value = convert_value(value)
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
- def add_negative
20
- matcher.expectation_message << negative_expectation_message
21
- matcher.association[key] = self
22
- matcher
23
- end
14
+ class DirectionMatcher < Base
15
+ def match(association)
16
+ expected == association.direction
17
+ end
24
18
 
25
- def matches?(actual)
26
- @actual = extact_actual(actual)
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
- private
24
+ class OriginMatcher < Base
25
+ def match(association)
26
+ expected == association.relationship_type
27
+ end
37
28
 
38
- def matches
39
- value != actual
29
+ def description
30
+ "with #{expected} origin"
31
+ end
40
32
  end
41
33
 
42
- def convert_value(val)
43
- val
44
- end
45
- end
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
- def extact_actual(actual)
55
- actual.direction
39
+ def description
40
+ "with #{expected} type"
41
+ end
56
42
  end
57
43
 
58
- def expectation_message
59
- " with #{value} direction"
60
- end
44
+ class ModelClassMatcher < Base
45
+ def match(association)
46
+ actual = Array(association.model_class)
47
+ actual & expected == actual
48
+ end
61
49
 
62
- def result_message
63
- "#{actual} direction"
50
+ def description
51
+ "with #{expected.join(', ')} model class"
52
+ end
64
53
  end
65
54
  end
66
55
 
67
- class TypeMatcher < BaseMatcher
68
- private
69
-
70
- def key
71
- :type
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
- def result_message
87
- "#{actual} relationship type"
62
+ def description
63
+ "without type"
64
+ end
88
65
  end
89
66
  end
90
67
 
91
- class OriginMatcher < BaseMatcher
92
- private
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 expectation_message
103
- " with #{value} origin"
73
+ def description(model_name)
74
+ "have many #{model_name}"
104
75
  end
105
76
 
106
- def result_message
107
- "#{actual} origin"
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 ModelClassesMatcher < BaseMatcher
112
- private
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 extact_actual(actual)
123
- Array(actual.model_class)
87
+ def description(model_name)
88
+ "have one #{model_name}"
124
89
  end
125
90
 
126
- def matches
127
- (value & actual) != value
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
- class AssociationMatcher
141
- attr_accessor :association, :expectation_message, :negative_result_message,
142
- :positive_result_message
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
- def with_origin(origin)
175
- OriginMatcher.new(self, origin).add
176
- end
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
- def matches?(actual)
183
- @actual = actual
184
- actual_association = actual.class.associations[association[:name]]
109
+ chain :with_direction do |direction|
110
+ matchers.push With::DirectionMatcher.new(direction)
111
+ end
185
112
 
186
- unless actual_association
187
- self.negative_result_message = "no association named #{association[:name]}"
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
- matchers.each do |_, matcher|
194
- return false unless matcher.matches?(actual_association)
117
+ chain :with_type do |type|
118
+ matchers.push With::TypeMatcher.new(type)
195
119
  end
196
120
 
197
- true
198
- end
121
+ chain :with_model_class do |*model_classes|
122
+ matchers.push With::ModelClassMatcher.new(model_classes)
123
+ end
199
124
 
200
- def failure_message
201
- "Expected #{@actual.class} to #{expectation_message}, got #{negative_result_message}"
202
- end
125
+ chain :without_type do
126
+ matchers.push Without::TypeMatcher.new
127
+ end
203
128
 
204
- def failure_message_when_negated
205
- "Expected #{@actual.class} to not #{expectation_message}, got #{positive_result_message}"
206
- end
129
+ description do |model|
130
+ with_messages = matchers.map(&:description).join(" ")
131
+ macro.description(model.class.name) + " " + with_messages
132
+ end
207
133
 
208
- def description
209
- expectation_message
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
@@ -1,5 +1,5 @@
1
1
  module Neo4j
2
2
  module RSpec
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
@@ -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", "~> 6"
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.0
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-01 00:00:00.000000000 Z
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: '6'
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: '6'
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
- - ".gitignore"
49
- - ".rspec"
50
- - ".travis.yml"
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.5.1
81
+ rubygems_version: 2.0.14
82
82
  signing_key:
83
83
  specification_version: 4
84
84
  summary: RSpec matchers for Neo4j.rb