mongoid-rspec 4.2.0 → 4.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.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +132 -3
  3. data/Rakefile +4 -2
  4. data/lib/matchers/accept_nested_attributes.rb +2 -0
  5. data/lib/matchers/allow_mass_assignment.rb +2 -0
  6. data/lib/matchers/associations.rb +27 -9
  7. data/lib/matchers/be_covered_query.rb +75 -0
  8. data/lib/matchers/be_dynamic_document.rb +2 -0
  9. data/lib/matchers/be_mongoid_document.rb +2 -0
  10. data/lib/matchers/be_stored_in.rb +2 -0
  11. data/lib/matchers/execute_mongodb_command.rb +127 -0
  12. data/lib/matchers/have_field.rb +15 -3
  13. data/lib/matchers/have_timestamps.rb +5 -3
  14. data/lib/matchers/indexes/have_index_for.rb +2 -0
  15. data/lib/matchers/indexes/v3/have_index_for.rb +3 -1
  16. data/lib/matchers/indexes/v4/have_index_for.rb +3 -1
  17. data/lib/matchers/validations/absence_of.rb +2 -0
  18. data/lib/matchers/validations/acceptance_of.rb +2 -0
  19. data/lib/matchers/validations/associated.rb +2 -0
  20. data/lib/matchers/validations/confirmation_of.rb +2 -0
  21. data/lib/matchers/validations/custom_validation_of.rb +14 -12
  22. data/lib/matchers/validations/exclusion_of.rb +15 -11
  23. data/lib/matchers/validations/format_of.rb +19 -15
  24. data/lib/matchers/validations/inclusion_of.rb +13 -9
  25. data/lib/matchers/validations/length_of.rb +77 -36
  26. data/lib/matchers/validations/numericality_of.rb +13 -11
  27. data/lib/matchers/validations/presence_of.rb +2 -0
  28. data/lib/matchers/validations/uniqueness_of.rb +19 -17
  29. data/lib/matchers/validations.rb +41 -22
  30. data/lib/mongoid/rspec/version.rb +3 -1
  31. data/lib/mongoid/rspec.rb +4 -0
  32. data/lib/mongoid-rspec.rb +2 -0
  33. metadata +10 -8
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Mongoid
2
4
  module Matchers
3
5
  module Validations
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Mongoid
2
4
  module Matchers
3
5
  module Validations
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Mongoid
2
4
  module Matchers
3
5
  module Validations
@@ -11,23 +13,23 @@ module Mongoid
11
13
  self
12
14
  end
13
15
 
14
- def matches?(actual)
15
- return false unless (@result = super(actual))
16
- check_custom_validator if @custom_validator
17
-
18
- @result
19
- end
20
-
21
16
  def description
22
- options_desc = []
23
- options_desc << " with custom validator #{@custom_validator.name}" if @validator
24
- "validate field #{@field.inspect}" << options_desc.to_sentence
17
+ options_desc = +"validate field #{@field.inspect}"
18
+ options_desc << " with custom validator #{@custom_validator.name}" if @custom_validator
19
+ options_desc
25
20
  end
26
21
 
27
22
  private
28
23
 
29
- def check_custom_validator
30
- if @validator.is_a? @custom_validator
24
+ def check_validator(actual, validator)
25
+ return false unless (@result = super)
26
+ check_custom_validator(validator) if @custom_validator
27
+
28
+ @result
29
+ end
30
+
31
+ def check_custom_validator(validator)
32
+ if validator.is_a? @custom_validator
31
33
  @positive_result_message << " with custom validator of type #{@custom_validator.name}"
32
34
  else
33
35
  @negative_result_message << " with custom validator not of type #{@custom_validator.name}"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Mongoid
2
4
  module Matchers
3
5
  module Validations
@@ -11,11 +13,19 @@ module Mongoid
11
13
  self
12
14
  end
13
15
 
14
- def matches?(actual)
15
- return false unless result = super(actual)
16
+ def description
17
+ options_desc = []
18
+ options_desc << " not allowing the ff. values: #{@not_allowed_values}" if @not_allowed_values
19
+ super << options_desc.to_sentence
20
+ end
21
+
22
+ private
23
+
24
+ def check_validator(actual, validator)
25
+ return false unless (result = super)
16
26
 
17
27
  if @not_allowed_values
18
- raw_validator_not_allowed_values = @validator.options[:in]
28
+ raw_validator_not_allowed_values = validator.options[:in]
19
29
 
20
30
  validator_not_allowed_values = case raw_validator_not_allowed_values
21
31
  when Range then raw_validator_not_allowed_values.to_a
@@ -24,21 +34,15 @@ module Mongoid
24
34
 
25
35
  allowed_values = @not_allowed_values - validator_not_allowed_values
26
36
  if allowed_values.empty?
27
- @positive_result_message = @positive_result_message << ' not allowing all values mentioned'
37
+ @positive_result_message << ' not allowing all values mentioned'
28
38
  else
29
- @negative_result_message = @negative_result_message << " allowing the following the ff. values: #{allowed_values.inspect}"
39
+ @negative_result_message << " allowing the following the ff. values: #{allowed_values.inspect}"
30
40
  result = false
31
41
  end
32
42
  end
33
43
 
34
44
  result
35
45
  end
36
-
37
- def description
38
- options_desc = []
39
- options_desc << " not allowing the ff. values: #{@not_allowed_values}" if @not_allowed_values
40
- super << options_desc.to_sentence
41
- end
42
46
  end
43
47
 
44
48
  def validate_exclusion_of(field)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Mongoid
2
4
  module Matchers
3
5
  module Validations
@@ -21,20 +23,30 @@ module Mongoid
21
23
  self
22
24
  end
23
25
 
24
- def matches?(actual)
25
- return false unless result = super(actual)
26
+ def description
27
+ options_desc = []
28
+ options_desc << " with format #{@format.inspect}" if @format
29
+ options_desc << " allowing the value #{@valid_value.inspect}" if @valid_value
30
+ options_desc << " not allowing the value #{@invalid_value.inspect}" if @invalid_value
31
+ super << options_desc.to_sentence
32
+ end
33
+
34
+ private
35
+
36
+ def check_validator(actual, validator)
37
+ return false unless result = super
26
38
 
27
39
  if @format
28
- if @validator.options[:with] == @format
29
- @positive_result_message = @positive_result_message << " with format #{@validator.options[:format].inspect}"
40
+ if validator.options[:with] == @format
41
+ @positive_result_message = @positive_result_message << " with format #{validator.options[:format].inspect}"
30
42
  else
31
- @negative_result_message = @negative_result_message << " with format #{@validator.options[:format].inspect}"
43
+ @negative_result_message = @negative_result_message << " with format #{validator.options[:format].inspect}"
32
44
  result = false
33
45
  end
34
46
  end
35
47
 
36
48
  if @valid_value
37
- if @validator.options[:with] =~ @valid_value
49
+ if validator.options[:with] =~ @valid_value
38
50
  @positive_result_message = @positive_result_message << " with #{@valid_value.inspect} as a valid value"
39
51
  else
40
52
  @negative_result_message = @negative_result_message << " with #{@valid_value.inspect} as an invalid value"
@@ -43,7 +55,7 @@ module Mongoid
43
55
  end
44
56
 
45
57
  if @invalid_value
46
- if @invalid_value !~ @validator.options[:with]
58
+ if @invalid_value !~ validator.options[:with]
47
59
  @positive_result_message = @positive_result_message << " with #{@invalid_value.inspect} as an invalid value"
48
60
  else
49
61
  @negative_result_message = @negative_result_message << " with #{@invalid_value.inspect} as a valid value"
@@ -53,14 +65,6 @@ module Mongoid
53
65
 
54
66
  result
55
67
  end
56
-
57
- def description
58
- options_desc = []
59
- options_desc << " with format #{@format.inspect}" if @format
60
- options_desc << " allowing the value #{@valid_value.inspect}" if @valid_value
61
- options_desc << " not allowing the value #{@invalid_value.inspect}" if @invalid_value
62
- super << options_desc.to_sentence
63
- end
64
68
  end
65
69
 
66
70
  def validate_format_of(field)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Mongoid
2
4
  module Matchers
3
5
  module Validations
@@ -11,11 +13,19 @@ module Mongoid
11
13
  self
12
14
  end
13
15
 
14
- def matches?(actual)
15
- return false unless result = super(actual)
16
+ def description
17
+ options_desc = []
18
+ options_desc << " allowing these values: #{@allowed_values}" if @allowed_values
19
+ super << options_desc.to_sentence
20
+ end
21
+
22
+ private
23
+
24
+ def check_validator(actual, validator)
25
+ return false unless result = super
16
26
 
17
27
  if @allowed_values
18
- raw_validator_allowed_values = @validator.options[:in]
28
+ raw_validator_allowed_values = validator.options[:in]
19
29
 
20
30
  validator_allowed_values = case raw_validator_allowed_values
21
31
  when Range then raw_validator_allowed_values.to_a
@@ -33,12 +43,6 @@ module Mongoid
33
43
 
34
44
  result
35
45
  end
36
-
37
- def description
38
- options_desc = []
39
- options_desc << " allowing these values: #{@allowed_values}" if @allowed_values
40
- super << options_desc.to_sentence
41
- end
42
46
  end
43
47
 
44
48
  def validate_inclusion_of(field)
@@ -1,9 +1,24 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Mongoid
2
4
  module Matchers
3
5
  module Validations
4
6
  class ValidateLengthOfMatcher < HaveValidationMatcher
5
7
  def initialize(name)
6
8
  super(name, :length)
9
+ @allowed_options = {}
10
+ end
11
+
12
+ def to_allow(options)
13
+ aliases = { nil: :allow_nil, blank: :allow_blank, allow_nil: :allow_nil, allow_blank: :allow_blank }
14
+ unless options.is_a?(Hash) && options.any? &&
15
+ options.all? { |key, value| aliases.key?(key) && (value.equal?(true) || value.equal?(false)) } &&
16
+ options.keys.map { |key| aliases[key] }.uniq.size == options.size
17
+ raise ArgumentError, 'validate_length_of#to_allow requires a non-empty Hash of nil, blank, allow_nil, or allow_blank keys with boolean values and no duplicate aliases'
18
+ end
19
+
20
+ options.each { |key, value| @allowed_options[aliases[key]] = value }
21
+ self
7
22
  end
8
23
 
9
24
  def with_maximum(value)
@@ -30,72 +45,102 @@ module Mongoid
30
45
  end
31
46
  alias is as_exactly
32
47
 
33
- def matches?(actual)
34
- return false unless @result = super(actual)
35
-
36
- check_maximum if @maximum
37
- check_minimum if @minimum
38
- check_range if @within
39
- check_exact if @is
40
-
41
- @result
42
- end
43
-
44
48
  def description
45
49
  options_desc = []
46
50
  options_desc << "with minimum of #{@minimum}" if @minimum
47
51
  options_desc << "with maximum of #{@maximum}" if @maximum
48
52
  options_desc << "within the range of #{@within}" if @within
49
53
  options_desc << "as exactly #{@is}" if @is
54
+ @allowed_options.each { |key, value| options_desc << "with #{key} #{value.inspect}" }
50
55
  super << " #{options_desc.to_sentence}"
51
56
  end
52
57
 
53
58
  private
54
59
 
55
- def check_maximum
56
- if actual_max.nil?
60
+ def check_validator(actual, validator)
61
+ return false unless @result = super
62
+
63
+ check_maximum(validator) if @maximum
64
+ check_minimum(validator) if @minimum
65
+ check_range(validator) if @within
66
+ check_exact(validator) if @is
67
+ check_allowed_options(validator)
68
+
69
+ @result
70
+ end
71
+
72
+ def select_validator(validators)
73
+ validators.detect do |validator|
74
+ (!@minimum || actual_min(validator) == @minimum) &&
75
+ (!@maximum || actual_max(validator) == @maximum) &&
76
+ (!@within || @within.minmax == [actual_min(validator), actual_max(validator)]) &&
77
+ (!@is || validator.options[:is] == @is) &&
78
+ (!@expected_message || validator.options[:message] == @expected_message) &&
79
+ @allowed_options.all? { |key, value| validator.options[key] == value }
80
+ end || super
81
+ end
82
+
83
+ def check_allowed_options(validator)
84
+ @allowed_options.each do |key, value|
85
+ actual_value = validator.options[key]
86
+ if actual_value == value
87
+ @positive_result_message << " with #{key} #{value.inspect}"
88
+ else
89
+ @negative_result_message << " with #{key} #{actual_value.inspect}"
90
+ @result = false
91
+ end
92
+ end
93
+ end
94
+
95
+ def check_maximum(validator)
96
+ maximum = actual_max(validator)
97
+ if maximum.nil?
57
98
  @negative_result_message << ' with no maximum'
58
99
  @result = false
59
- elsif actual_max == @maximum
100
+ elsif maximum == @maximum
60
101
  @positive_result_message << " with maximum of #{@maximum}"
61
102
  else
62
- @negative_result_message << " with maximum of #{actual_max}"
103
+ @negative_result_message << " with maximum of #{maximum}"
63
104
  @result = false
64
105
  end
65
106
  end
66
107
 
67
- def check_minimum
68
- if actual_min.nil?
108
+ def check_minimum(validator)
109
+ minimum = actual_min(validator)
110
+ if minimum.nil?
69
111
  @negative_result_message << ' with no minimum'
70
112
  @result = false
71
- elsif actual_min == @minimum
113
+ elsif minimum == @minimum
72
114
  @positive_result_message << " with minimum of #{@minimum}"
73
115
  else
74
- @negative_result_message << " with minimum of #{actual_min}"
116
+ @negative_result_message << " with minimum of #{minimum}"
75
117
  @result = false
76
118
  end
77
119
  end
78
120
 
79
- def check_range
121
+ def check_range(validator)
80
122
  min, max = @within.minmax
81
- if !actual_min.nil? && actual_max.nil?
82
- @negative_result_message << " with no minimum but with maximum of #{actual_max}"
123
+ minimum = actual_min(validator)
124
+ maximum = actual_max(validator)
125
+ if !minimum.nil? && maximum.nil?
126
+ @negative_result_message << " with no minimum but with maximum of #{maximum}"
83
127
  @result = false
84
- elsif actual_min.nil? && !actual_max.nil?
85
- @negative_result_message << " with minimum_of #{actual_min} but no maximum"
128
+ elsif minimum.nil? && !maximum.nil?
129
+ @negative_result_message << " with minimum_of #{minimum} but no maximum"
86
130
  @result = false
87
- elsif actual_min.nil? && actual_max.nil?
131
+ elsif minimum.nil? && maximum.nil?
88
132
  @negative_result_message << ' with no minimum and maximum'
89
133
  @result = false
90
- elsif actual_min == min && actual_max == max
134
+ elsif minimum == min && maximum == max
91
135
  @positive_result_message << " within the range of #{@within.inspect}"
92
136
  else
93
- @negative_result_message << " within the range of #{(actual_min..actual_max).inspect}"
137
+ @negative_result_message << " within the range of #{(minimum..maximum).inspect}"
94
138
  @result = false
95
139
  end
96
140
  end
97
141
 
98
- def check_exact
142
+ def check_exact(validator)
143
+ actual_is = validator.options[:is]
99
144
  if actual_is == @is
100
145
  @positive_result_message << " as exactly #{@is}"
101
146
  else
@@ -104,16 +149,12 @@ module Mongoid
104
149
  end
105
150
  end
106
151
 
107
- def actual_is
108
- actual_is = @validator.options[:is]
109
- end
110
-
111
- def actual_min
112
- @validator.options[:minimum] || (@validator.options[:in] || @validator.options[:within]).try(&:min)
152
+ def actual_min(validator)
153
+ validator.options[:minimum] || (validator.options[:in] || validator.options[:within]).try(&:min)
113
154
  end
114
155
 
115
- def actual_max
116
- @validator.options[:maximum] || (@validator.options[:in] || @validator.options[:within]).try(&:max)
156
+ def actual_max(validator)
157
+ validator.options[:maximum] || (validator.options[:in] || validator.options[:within]).try(&:max)
117
158
  end
118
159
  end
119
160
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Mongoid
2
4
  module Matchers
3
5
  module Validations
@@ -36,24 +38,24 @@ module Mongoid
36
38
  self
37
39
  end
38
40
 
39
- def matches?(actual)
40
- return false unless result = super(actual)
41
+ def description
42
+ super << options_message(@options)
43
+ end
44
+
45
+ protected
46
+
47
+ def check_validator(actual, validator)
48
+ return false unless result = super
41
49
 
42
50
  @options.each do |comparator, expected_value|
43
- result &= (@validator.options[comparator] == expected_value)
51
+ result &= (validator.options[comparator] == expected_value)
44
52
  end
45
53
 
46
- @positive_result_message <<= options_message(@validator.options)
47
- @negative_result_message <<= options_message(@validator.options)
54
+ @positive_result_message <<= options_message(validator.options)
55
+ @negative_result_message <<= options_message(validator.options)
48
56
  result
49
57
  end
50
58
 
51
- def description
52
- super << options_message(@options)
53
- end
54
-
55
- protected
56
-
57
59
  def options_message(options)
58
60
  type_msg = []
59
61
  comp_msg = []
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Mongoid
2
4
  module Matchers
3
5
  module Validations
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Mongoid
2
4
  module Matchers
3
5
  module Validations
@@ -22,16 +24,6 @@ module Mongoid
22
24
  self
23
25
  end
24
26
 
25
- def matches?(actual)
26
- return false unless @result = super(actual)
27
-
28
- check_scope if @scope
29
- check_allow_blank if @allow_blank
30
- check_case_sensitivity if @case_insensitive
31
-
32
- @result
33
- end
34
-
35
27
  def description
36
28
  options_desc = []
37
29
  options_desc << " scoped to #{@scope.inspect}" if @scope
@@ -42,8 +34,18 @@ module Mongoid
42
34
 
43
35
  private
44
36
 
45
- def check_allow_blank
46
- if @validator.options[:allow_blank] == @allow_blank
37
+ def check_validator(actual, validator)
38
+ return false unless @result = super
39
+
40
+ check_scope(validator) if @scope
41
+ check_allow_blank(validator) if @allow_blank
42
+ check_case_sensitivity(validator) if @case_insensitive
43
+
44
+ @result
45
+ end
46
+
47
+ def check_allow_blank(validator)
48
+ if validator.options[:allow_blank] == @allow_blank
47
49
  @positive_result_message << ' with blank values allowed'
48
50
  else
49
51
  @negative_result_message << ' with no blank values allowed'
@@ -51,9 +53,9 @@ module Mongoid
51
53
  end
52
54
  end
53
55
 
54
- def check_scope
55
- message = " scope to #{@validator.options[:scope]}"
56
- if [@validator.options[:scope]].flatten.map(&:to_sym) == @scope
56
+ def check_scope(validator)
57
+ message = " scope to #{validator.options[:scope]}"
58
+ if [validator.options[:scope]].flatten.map(&:to_sym) == @scope
57
59
  @positive_result_message << message
58
60
  else
59
61
  @negative_result_message << message
@@ -61,8 +63,8 @@ module Mongoid
61
63
  end
62
64
  end
63
65
 
64
- def check_case_sensitivity
65
- if @validator.options[:case_sensitive] == false
66
+ def check_case_sensitivity(validator)
67
+ if validator.options[:case_sensitive] == false
66
68
  @positive_result_message << ' with case insensitive values'
67
69
  else
68
70
  @negative_result_message << ' without case insensitive values'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Mongoid
2
4
  module Matchers
3
5
  module Validations
@@ -11,22 +13,20 @@ module Mongoid
11
13
  def matches?(actual)
12
14
  @klass = actual.is_a?(Class) ? actual : actual.class
13
15
 
14
- @validator = @klass.validators_on(@field).detect do |v|
16
+ validators = @klass.validators_on(@field).lazy.select do |v|
15
17
  (v.kind.to_s == @type) && (!v.options[:on] || on_options_matches?(v)) &&
16
18
  if_condition_matches?(actual, v) && unless_condition_matches?(actual, v)
17
19
  end
20
+ validator = select_validator(validators)
18
21
 
19
- if @validator
20
- @negative_result_message = "#{@type.inspect} validator on #{@field.inspect}"
21
- @positive_result_message = "#{@type.inspect} validator on #{@field.inspect}"
22
+ if validator
23
+ @negative_result_message = +"#{@type.inspect} validator on #{@field.inspect}"
24
+ @positive_result_message = +"#{@type.inspect} validator on #{@field.inspect}"
22
25
  else
23
- @negative_result_message = "no #{@type.inspect} validator on #{@field.inspect}"
26
+ @negative_result_message = +"no #{@type.inspect} validator on #{@field.inspect}"
24
27
  return false
25
28
  end
26
- @result = true
27
- check_on if @options[:on]
28
- check_expected_message if @expected_message
29
- @result
29
+ check_validator(actual, validator)
30
30
  end
31
31
 
32
32
  def failure_message_for_should
@@ -41,10 +41,9 @@ module Mongoid
41
41
  alias failure_message_when_negated failure_message_for_should_not
42
42
 
43
43
  def description
44
- desc = "have #{@type.inspect} validator on #{@field.inspect}"
44
+ desc = +"have #{@type.inspect} validator on #{@field.inspect}"
45
45
  desc << " on #{@options[:on]}" if @options[:on]
46
46
  desc << " with message #{@expected_message.inspect}" if @expected_message
47
-
48
47
  desc
49
48
  end
50
49
 
@@ -58,40 +57,60 @@ module Mongoid
58
57
  self
59
58
  end
60
59
 
60
+ def check_conditions
61
+ @check_conditions = true
62
+ self
63
+ end
64
+
61
65
  private
62
66
 
67
+ def check_validator(_actual, validator)
68
+ @result = true
69
+ check_on(validator) if @options[:on]
70
+ check_expected_message(validator) if @expected_message
71
+ @result
72
+ end
73
+
74
+ def select_validator(validators)
75
+ validators.first
76
+ end
77
+
63
78
  def if_condition_matches?(actual, validator)
79
+ return true unless @check_conditions
64
80
  return true unless validator.options[:if]
65
81
 
66
- check_condition actual, validator.options[:if]
82
+ check_condition(actual, validator.options[:if])
67
83
  end
68
84
 
69
85
  def unless_condition_matches?(actual, validator)
86
+ return true unless @check_conditions
70
87
  return true unless validator.options[:unless]
71
88
 
72
- !check_condition actual, validator.options[:unless]
89
+ !check_condition(actual, validator.options[:unless])
73
90
  end
74
91
 
75
92
  def check_condition(actual, filter)
76
- raise ArgumentError, 'Spec subject must be object instance when testing validators with if/unless condition.' if actual.is_a?(Class)
93
+ raise ArgumentError, 'Spec subject must be an instance when using .check_conditions' if actual.is_a?(Class)
77
94
 
78
95
  case filter
79
96
  when Symbol
80
- actual.send filter
97
+ actual.send(filter)
81
98
  when ::Proc
82
- actual.instance_exec(&filter)
99
+ filter.arity.zero? ? actual.instance_exec(&filter) : filter.call(actual)
100
+ when Array
101
+ filter.all? { |f| check_condition(actual, f) }
83
102
  else
84
103
  raise ArgumentError, "Unexpected filter: #{filter.inspect}"
85
104
  end
86
105
  end
87
106
 
88
- def check_on
89
- validator_on_methods = [@validator.options[:on]].flatten
107
+ def check_on(validator)
108
+ validator_on_methods = [validator.options[:on]].flatten
90
109
 
91
110
  if validator_on_methods.any?
92
- message = " on methods: #{validator_on_methods}"
111
+ message = +" on methods: #{validator_on_methods}"
93
112
 
94
- if on_options_covered_by?(@validator)
113
+ if on_options_covered_by?(validator)
95
114
  @positive_result_message << message
96
115
  else
97
116
  @negative_result_message << message
@@ -108,8 +127,8 @@ module Mongoid
108
127
  ([@options[:on]].flatten - [validator.options[:on]].flatten).empty?
109
128
  end
110
129
 
111
- def check_expected_message
112
- actual_message = @validator.options[:message]
130
+ def check_expected_message(validator)
131
+ actual_message = validator.options[:message]
113
132
  if actual_message.nil?
114
133
  @negative_result_message << ' with no custom message'
115
134
  @result = false
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Mongoid
2
4
  module RSpec
3
- VERSION = '4.2.0'.freeze
5
+ VERSION = '4.4.0'
4
6
  end
5
7
  end
data/lib/mongoid/rspec.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
4
 
3
5
  require 'mongoid'
@@ -29,7 +31,9 @@ require 'matchers/validations/absence_of'
29
31
  require 'matchers/be_mongoid_document'
30
32
  require 'matchers/be_dynamic_document'
31
33
  require 'matchers/be_stored_in'
34
+ require 'matchers/be_covered_query'
32
35
  require 'matchers/have_field'
36
+ require 'matchers/execute_mongodb_command'
33
37
  require 'matchers/indexes/have_index_for'
34
38
  if Mongoid::Compatibility::Version.mongoid3?
35
39
  require 'matchers/indexes/v3/have_index_for'
data/lib/mongoid-rspec.rb CHANGED
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'mongoid/rspec'