mongoid-minitest 0.1.1 → 0.1.2
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.
- data/CHANGELOG.md +14 -2
- data/README.md +11 -2
- data/lib/matchers/associations/associations.rb +17 -3
- data/lib/matchers/document/be_stored_in.rb +1 -3
- data/lib/matchers/document/document.rb +8 -10
- data/lib/matchers/document/have_field.rb +4 -6
- data/lib/matchers/document/have_index.rb +1 -3
- data/lib/matchers/helpers.rb +2 -2
- data/lib/matchers/matcher.rb +17 -0
- data/lib/matchers/validations/exclusion.rb +12 -3
- data/lib/matchers/validations/format.rb +9 -9
- data/lib/matchers/validations/inclusion.rb +13 -4
- data/lib/matchers/validations/validations.rb +1 -3
- data/lib/mongoid-minitest.rb +2 -2
- data/lib/mongoid-minitest/version.rb +1 -1
- metadata +22 -5
- data/lib/minitest/matchers.rb +0 -42
data/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
|
-
## 0.1.
|
|
1
|
+
## 0.1.2 - August 13, 2012
|
|
2
2
|
|
|
3
|
-
+
|
|
3
|
+
+ Allow passing in a Regex to the validate_format_of matcher.
|
|
4
|
+
Pull Request [#12](https://github.com/frodsan/mongoid-minitest/pull/12) - *Godfrey Chan*.
|
|
5
|
+
+ Allow non-array values for inclusion/exclusion matchers.
|
|
6
|
+
Pull Request [#11](https://github.com/frodsan/mongoid-minitest/pull/11) - *Godfrey Chan*.
|
|
7
|
+
+ Added as_inverse_of for association matchers.
|
|
8
|
+
Pull Request [#10](https://frodsan/mongoid-minitest/pull/10) - *Godfrey Chan*.
|
|
9
|
+
+ Use [minitest-matchers](https://github.com/zenspider/minitest-matchers) gem
|
|
10
|
+
instead of our matchers implementation - *Francesco Rodriguez*.
|
|
11
|
+
+ Bump mongoid version to 3.0.4 - *Francesco Rodriguez*.
|
|
12
|
+
|
|
13
|
+
## 0.1.1 - August 09, 2012
|
|
14
|
+
|
|
15
|
+
+ Remove required ruby version from the gemspec. Fixes [#9](https://github.com/frodsan/mongoid-minitest/pull/9). *Francesco Rodriguez*
|
|
4
16
|
|
|
5
17
|
## 0.1.0 - August 09, 2012
|
|
6
18
|
|
data/README.md
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
|
-
# mongoid-minitest
|
|
1
|
+
# mongoid-minitest
|
|
2
2
|
|
|
3
3
|
MiniTest matchers for Mongoid.
|
|
4
4
|
|
|
5
|
+
[](http://travis-ci.org/frodsan/mongoid-minitest)
|
|
6
|
+
|
|
5
7
|
## Support
|
|
6
8
|
|
|
7
9
|
This gem supports:
|
|
8
10
|
|
|
9
11
|
* Ruby 1.9.3
|
|
10
|
-
* Mongoid ~>3.0.
|
|
12
|
+
* Mongoid ~>3.0.4
|
|
11
13
|
* MiniTest ~>3.3.0
|
|
12
14
|
|
|
15
|
+
If you're using Mongoid 2.4.x, you should use [0.0.3.1 version](https://github.com/frodsan/mongoid-minitest/tree/274976e8814cc9bfb3f1c83eba1bed21fa3cf26b).
|
|
16
|
+
|
|
13
17
|
## Installation
|
|
14
18
|
|
|
15
19
|
Add this line to your application's Gemfile:
|
|
@@ -175,6 +179,11 @@ See the following examples:
|
|
|
175
179
|
|
|
176
180
|
To run unit tests, run `bundle exec rake`.
|
|
177
181
|
|
|
182
|
+
## Maintainers
|
|
183
|
+
|
|
184
|
+
* Francesco Rodriguez (<https://github.com/frodsan/>).
|
|
185
|
+
* Sascha Wessel (<https://github.com/gr4y>).
|
|
186
|
+
|
|
178
187
|
## License
|
|
179
188
|
|
|
180
189
|
MIT License. Copyright 2012 Francesco Rodriguez. See [LICENSE](https://github.com/frodsan/lego/blob/master/LICENSE)
|
|
@@ -9,9 +9,7 @@ module Mongoid
|
|
|
9
9
|
EMBEDS_MANY = Mongoid::Relations::Embedded::Many
|
|
10
10
|
EMBEDDED_IN = Mongoid::Relations::Embedded::In
|
|
11
11
|
|
|
12
|
-
class HaveAssociationMatcher
|
|
13
|
-
include Helpers
|
|
14
|
-
|
|
12
|
+
class HaveAssociationMatcher < Matcher
|
|
15
13
|
def initialize(name, type)
|
|
16
14
|
@association = {}
|
|
17
15
|
@association[:name] = name.to_s
|
|
@@ -25,6 +23,12 @@ module Mongoid
|
|
|
25
23
|
self
|
|
26
24
|
end
|
|
27
25
|
|
|
26
|
+
def as_inverse_of(inverse_of)
|
|
27
|
+
@association[:inverse_of] = inverse_of
|
|
28
|
+
@description << " as the inverse of #{@association[:inverse_of].inspect}"
|
|
29
|
+
self
|
|
30
|
+
end
|
|
31
|
+
|
|
28
32
|
def matches?(subject)
|
|
29
33
|
@klass = class_of(subject)
|
|
30
34
|
@metadata = @klass.relations[@association[:name]]
|
|
@@ -33,6 +37,7 @@ module Mongoid
|
|
|
33
37
|
check_association_name
|
|
34
38
|
check_association_type
|
|
35
39
|
check_association_class if @association[:class]
|
|
40
|
+
check_association_inverse_of if @association[:inverse_of]
|
|
36
41
|
|
|
37
42
|
@result
|
|
38
43
|
end
|
|
@@ -82,6 +87,15 @@ module Mongoid
|
|
|
82
87
|
end
|
|
83
88
|
end
|
|
84
89
|
|
|
90
|
+
def check_association_inverse_of
|
|
91
|
+
if @association[:inverse_of] != @metadata.inverse_of
|
|
92
|
+
@negative_message = "..."
|
|
93
|
+
@result = false
|
|
94
|
+
else
|
|
95
|
+
@positive_message << " as inverse of #{@metadata.inverse_of}" if @association[:inverse_of]
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
85
99
|
def type_description(type = nil, passive = true)
|
|
86
100
|
type ||= @association[:type]
|
|
87
101
|
case type.name
|
|
@@ -6,15 +6,13 @@ module Mongoid
|
|
|
6
6
|
VERSIONING = Mongoid::Versioning
|
|
7
7
|
TIMESTAMPS = Mongoid::Timestamps
|
|
8
8
|
|
|
9
|
-
class
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
def initialize(mod)
|
|
9
|
+
class DocumentMatcher < Matcher
|
|
10
|
+
def initialize mod
|
|
13
11
|
@mod = mod
|
|
14
12
|
end
|
|
15
13
|
|
|
16
|
-
def matches?
|
|
17
|
-
class_of(subject).included_modules.include?
|
|
14
|
+
def matches? subject
|
|
15
|
+
class_of(subject).included_modules.include? @mod
|
|
18
16
|
end
|
|
19
17
|
|
|
20
18
|
def description
|
|
@@ -31,19 +29,19 @@ module Mongoid
|
|
|
31
29
|
end
|
|
32
30
|
|
|
33
31
|
def be_document
|
|
34
|
-
|
|
32
|
+
DocumentMatcher.new DOCUMENT
|
|
35
33
|
end
|
|
36
34
|
|
|
37
35
|
def be_paranoid
|
|
38
|
-
|
|
36
|
+
DocumentMatcher.new PARANOIA
|
|
39
37
|
end
|
|
40
38
|
|
|
41
39
|
def be_versioned
|
|
42
|
-
|
|
40
|
+
DocumentMatcher.new VERSIONING
|
|
43
41
|
end
|
|
44
42
|
|
|
45
43
|
def be_timestamped
|
|
46
|
-
|
|
44
|
+
DocumentMatcher.new TIMESTAMPS
|
|
47
45
|
end
|
|
48
46
|
end
|
|
49
47
|
end
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
module Mongoid
|
|
2
2
|
module Matchers
|
|
3
3
|
module Document
|
|
4
|
-
class HaveFieldMatcher
|
|
5
|
-
include Helpers
|
|
6
|
-
|
|
4
|
+
class HaveFieldMatcher < Matcher
|
|
7
5
|
def initialize(*fields)
|
|
8
6
|
@fields = fields.collect(&:to_s)
|
|
9
7
|
end
|
|
@@ -26,7 +24,7 @@ module Mongoid
|
|
|
26
24
|
if @klass.fields.include?(field)
|
|
27
25
|
error = ""
|
|
28
26
|
result_field = @klass.fields[field]
|
|
29
|
-
|
|
27
|
+
|
|
30
28
|
if check_type_with(result_field.type)
|
|
31
29
|
error << " of type #{result_field.type.inspect}"
|
|
32
30
|
end
|
|
@@ -62,11 +60,11 @@ module Mongoid
|
|
|
62
60
|
end
|
|
63
61
|
|
|
64
62
|
private
|
|
65
|
-
|
|
63
|
+
|
|
66
64
|
def check_type_with(type)
|
|
67
65
|
@type && type != @type
|
|
68
66
|
end
|
|
69
|
-
|
|
67
|
+
|
|
70
68
|
def check_default_with(default)
|
|
71
69
|
!@default.nil? && !default.nil? && default != @default
|
|
72
70
|
end
|
data/lib/matchers/helpers.rb
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require_relative 'helpers'
|
|
2
|
+
|
|
3
|
+
module Mongoid
|
|
4
|
+
module Matchers
|
|
5
|
+
class Matcher
|
|
6
|
+
include Helpers
|
|
7
|
+
|
|
8
|
+
def failure_message
|
|
9
|
+
"Expected #{inspect} to #{description}".squeeze ' '
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def negative_failure_message
|
|
13
|
+
"Expected not to #{description}".squeeze ' '
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -7,14 +7,14 @@ module Mongoid
|
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
def to_not_allow(*values)
|
|
10
|
-
@not_allowed_values = values.flatten
|
|
10
|
+
@not_allowed_values = (values.length > 1) ? values.flatten : values[0]
|
|
11
11
|
self
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
def matches?(subject)
|
|
15
15
|
return false unless result = super(subject)
|
|
16
16
|
|
|
17
|
-
if @not_allowed_values
|
|
17
|
+
if Array === @not_allowed_values
|
|
18
18
|
allowed_values = @not_allowed_values - @validator.options[:in].to_a
|
|
19
19
|
if allowed_values.empty?
|
|
20
20
|
@positive_message << ' not allowing all values mentioned'
|
|
@@ -23,14 +23,23 @@ module Mongoid
|
|
|
23
23
|
@negative_message << " #{to_sentence(allowed_values)}"
|
|
24
24
|
result = false
|
|
25
25
|
end
|
|
26
|
+
elsif @not_allowed_values
|
|
27
|
+
if @not_allowed_values == @validator.options[:in]
|
|
28
|
+
@positive_message << " not allowing values in #{@not_allowed_values.inspect}"
|
|
29
|
+
else
|
|
30
|
+
@negative_message << " not allowing values in #{@validator.options[:in].inspect}"
|
|
31
|
+
result = false
|
|
32
|
+
end
|
|
26
33
|
end
|
|
27
34
|
|
|
28
35
|
result
|
|
29
36
|
end
|
|
30
37
|
|
|
31
38
|
def description
|
|
32
|
-
if @not_allowed_values
|
|
39
|
+
if Array === @not_allowed_values
|
|
33
40
|
super << " not allowing the values: #{to_sentence(@not_allowed_values)}"
|
|
41
|
+
elsif @not_allowed_values
|
|
42
|
+
super << " not allowing the values in #{@not_allowed_values.inspect}"
|
|
34
43
|
end
|
|
35
44
|
end
|
|
36
45
|
end
|
|
@@ -2,21 +2,21 @@ module Mongoid
|
|
|
2
2
|
module Matchers
|
|
3
3
|
module Validations
|
|
4
4
|
class ValidateFormatMatcher < HaveValidationMatcher
|
|
5
|
-
def initialize
|
|
6
|
-
super
|
|
5
|
+
def initialize field
|
|
6
|
+
super field, :format
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
-
def to_allow
|
|
9
|
+
def to_allow valid_value
|
|
10
10
|
@valid = valid_value
|
|
11
11
|
self
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
-
def to_not_allow
|
|
14
|
+
def to_not_allow invalid_value
|
|
15
15
|
@invalid = invalid_value
|
|
16
16
|
self
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
-
def matches?
|
|
19
|
+
def matches? subject
|
|
20
20
|
return false unless @result = super(subject)
|
|
21
21
|
|
|
22
22
|
check_valid_value if @valid
|
|
@@ -35,7 +35,7 @@ module Mongoid
|
|
|
35
35
|
private
|
|
36
36
|
|
|
37
37
|
def check_valid_value
|
|
38
|
-
if format =~ @valid
|
|
38
|
+
if format == @valid || format =~ @valid
|
|
39
39
|
@positive_message << " with #{@valid.inspect} as a valid value"
|
|
40
40
|
else
|
|
41
41
|
@negative_message << " with #{@valid.inspect} as an invalid value"
|
|
@@ -44,7 +44,7 @@ module Mongoid
|
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
def check_invalid_value
|
|
47
|
-
if
|
|
47
|
+
if format !~ @invalid
|
|
48
48
|
@positive_message << " with #{@invalid.inspect} as a invalid value"
|
|
49
49
|
else
|
|
50
50
|
@negative_message << " with #{@invalid.inspect} as a valid value"
|
|
@@ -57,8 +57,8 @@ module Mongoid
|
|
|
57
57
|
end
|
|
58
58
|
end
|
|
59
59
|
|
|
60
|
-
def validate_format_of
|
|
61
|
-
ValidateFormatMatcher.new
|
|
60
|
+
def validate_format_of field
|
|
61
|
+
ValidateFormatMatcher.new field
|
|
62
62
|
end
|
|
63
63
|
end
|
|
64
64
|
end
|
|
@@ -7,30 +7,39 @@ module Mongoid
|
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
def to_allow(*values)
|
|
10
|
-
@allowed_values = values.flatten
|
|
10
|
+
@allowed_values = (values.length > 1) ? values.flatten : values[0]
|
|
11
11
|
self
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
def matches?(subject)
|
|
15
15
|
return false unless result = super(subject)
|
|
16
16
|
|
|
17
|
-
if @allowed_values
|
|
17
|
+
if Array === @allowed_values
|
|
18
18
|
not_allowed_values = @allowed_values - @validator.options[:in].to_a
|
|
19
19
|
if not_allowed_values.empty?
|
|
20
20
|
@positive_message << ' allowing all values mentioned'
|
|
21
21
|
else
|
|
22
|
-
@negative_message << ' not allowing the following the
|
|
22
|
+
@negative_message << ' not allowing the following the values:'
|
|
23
23
|
@negative_message << " #{not_allowed_values.inspect}"
|
|
24
24
|
result = false
|
|
25
25
|
end
|
|
26
|
+
elsif @allowed_values
|
|
27
|
+
if @allowed_values == @validator.options[:in]
|
|
28
|
+
@positive_message << " allowing values in #{@allowed_values.inspect}"
|
|
29
|
+
else
|
|
30
|
+
@negative_message << " allowing values in #{@validator.options[:in].inspect}"
|
|
31
|
+
result = false
|
|
32
|
+
end
|
|
26
33
|
end
|
|
27
34
|
|
|
28
35
|
result
|
|
29
36
|
end
|
|
30
37
|
|
|
31
38
|
def description
|
|
32
|
-
if @allowed_values
|
|
39
|
+
if Array === @allowed_values
|
|
33
40
|
super << " allowing the values: #{to_sentence(@allowed_values)}"
|
|
41
|
+
elsif @allowed_values
|
|
42
|
+
super << " allowing the values in #{@allowed_values.inspect}"
|
|
34
43
|
end
|
|
35
44
|
end
|
|
36
45
|
end
|
data/lib/mongoid-minitest.rb
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
gem 'minitest'
|
|
2
2
|
require 'mongoid'
|
|
3
3
|
require 'minitest/spec'
|
|
4
|
-
|
|
5
4
|
require 'minitest/matchers'
|
|
6
|
-
|
|
5
|
+
|
|
6
|
+
require 'matchers/matcher'
|
|
7
7
|
require 'matchers/document/document'
|
|
8
8
|
require 'matchers/document/have_field'
|
|
9
9
|
require 'matchers/document/be_stored_in'
|
metadata
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: mongoid-minitest
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.2
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
8
8
|
- Francesco Rodriguez
|
|
9
|
+
- Sascha Wessel
|
|
9
10
|
autorequire:
|
|
10
11
|
bindir: bin
|
|
11
12
|
cert_chain: []
|
|
12
|
-
date: 2012-08-
|
|
13
|
+
date: 2012-08-13 00:00:00.000000000 Z
|
|
13
14
|
dependencies:
|
|
14
15
|
- !ruby/object:Gem::Dependency
|
|
15
16
|
name: minitest
|
|
@@ -27,6 +28,22 @@ dependencies:
|
|
|
27
28
|
- - ~>
|
|
28
29
|
- !ruby/object:Gem::Version
|
|
29
30
|
version: 3.3.0
|
|
31
|
+
- !ruby/object:Gem::Dependency
|
|
32
|
+
name: minitest-matchers
|
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
|
34
|
+
none: false
|
|
35
|
+
requirements:
|
|
36
|
+
- - ~>
|
|
37
|
+
- !ruby/object:Gem::Version
|
|
38
|
+
version: 1.2.0
|
|
39
|
+
type: :runtime
|
|
40
|
+
prerelease: false
|
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
42
|
+
none: false
|
|
43
|
+
requirements:
|
|
44
|
+
- - ~>
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: 1.2.0
|
|
30
47
|
- !ruby/object:Gem::Dependency
|
|
31
48
|
name: mongoid
|
|
32
49
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -34,7 +51,7 @@ dependencies:
|
|
|
34
51
|
requirements:
|
|
35
52
|
- - ~>
|
|
36
53
|
- !ruby/object:Gem::Version
|
|
37
|
-
version: 3.0.
|
|
54
|
+
version: 3.0.4
|
|
38
55
|
type: :runtime
|
|
39
56
|
prerelease: false
|
|
40
57
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -42,7 +59,7 @@ dependencies:
|
|
|
42
59
|
requirements:
|
|
43
60
|
- - ~>
|
|
44
61
|
- !ruby/object:Gem::Version
|
|
45
|
-
version: 3.0.
|
|
62
|
+
version: 3.0.4
|
|
46
63
|
- !ruby/object:Gem::Dependency
|
|
47
64
|
name: rake
|
|
48
65
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -72,6 +89,7 @@ files:
|
|
|
72
89
|
- lib/matchers/document/have_field.rb
|
|
73
90
|
- lib/matchers/document/have_index.rb
|
|
74
91
|
- lib/matchers/helpers.rb
|
|
92
|
+
- lib/matchers/matcher.rb
|
|
75
93
|
- lib/matchers/validations/acceptance.rb
|
|
76
94
|
- lib/matchers/validations/associated.rb
|
|
77
95
|
- lib/matchers/validations/confirmation.rb
|
|
@@ -82,7 +100,6 @@ files:
|
|
|
82
100
|
- lib/matchers/validations/presence.rb
|
|
83
101
|
- lib/matchers/validations/uniqueness.rb
|
|
84
102
|
- lib/matchers/validations/validations.rb
|
|
85
|
-
- lib/minitest/matchers.rb
|
|
86
103
|
- lib/mongoid-minitest/version.rb
|
|
87
104
|
- lib/mongoid-minitest.rb
|
|
88
105
|
- LICENSE
|
data/lib/minitest/matchers.rb
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
module MiniTest
|
|
2
|
-
module Assertions
|
|
3
|
-
def assert_must(subject, matcher, msg = nil)
|
|
4
|
-
msg = message(msg) do
|
|
5
|
-
if matcher.respond_to? :failure_message
|
|
6
|
-
"Expected #{matcher.failure_message}".squeeze(" ")
|
|
7
|
-
else
|
|
8
|
-
"Expected #{subject.inspect} to #{matcher.description}".squeeze(" ")
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
assert matcher.matches?(subject), msg
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def assert_wont(subject, matcher, msg = nil)
|
|
16
|
-
msg = message(msg) do
|
|
17
|
-
if matcher.respond_to? :negative_failure_message
|
|
18
|
-
"Expected #{matcher.negative_failure_message}".squeeze(" ")
|
|
19
|
-
else
|
|
20
|
-
"Expected not to #{matcher.description}".squeeze(" ")
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
refute matcher.matches?(subject), msg
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
module Expectations
|
|
29
|
-
infect_an_assertion :assert_must, :must, :reverse
|
|
30
|
-
infect_an_assertion :assert_wont, :wont, :reverse
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
class MiniTest::Spec
|
|
35
|
-
def must(*args, &block)
|
|
36
|
-
subject.must(*args, &block)
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def wont(*args, &block)
|
|
40
|
-
subject.wont(*args, &block)
|
|
41
|
-
end
|
|
42
|
-
end
|