mongoid-rspec 4.2.0 → 4.3.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.
- checksums.yaml +4 -4
- data/README.md +6 -3
- data/Rakefile +2 -0
- data/lib/matchers/accept_nested_attributes.rb +2 -0
- data/lib/matchers/allow_mass_assignment.rb +2 -0
- data/lib/matchers/associations.rb +10 -8
- data/lib/matchers/be_dynamic_document.rb +2 -0
- data/lib/matchers/be_mongoid_document.rb +2 -0
- data/lib/matchers/be_stored_in.rb +2 -0
- data/lib/matchers/have_field.rb +5 -3
- data/lib/matchers/have_timestamps.rb +5 -3
- data/lib/matchers/indexes/have_index_for.rb +2 -0
- data/lib/matchers/indexes/v3/have_index_for.rb +3 -1
- data/lib/matchers/indexes/v4/have_index_for.rb +3 -1
- data/lib/matchers/validations/absence_of.rb +2 -0
- data/lib/matchers/validations/acceptance_of.rb +2 -0
- data/lib/matchers/validations/associated.rb +2 -0
- data/lib/matchers/validations/confirmation_of.rb +2 -0
- data/lib/matchers/validations/custom_validation_of.rb +4 -2
- data/lib/matchers/validations/exclusion_of.rb +5 -3
- data/lib/matchers/validations/format_of.rb +2 -0
- data/lib/matchers/validations/inclusion_of.rb +2 -0
- data/lib/matchers/validations/length_of.rb +2 -0
- data/lib/matchers/validations/numericality_of.rb +2 -0
- data/lib/matchers/validations/presence_of.rb +2 -0
- data/lib/matchers/validations/uniqueness_of.rb +2 -0
- data/lib/matchers/validations.rb +21 -11
- data/lib/mongoid/rspec/version.rb +3 -1
- data/lib/mongoid/rspec.rb +2 -0
- data/lib/mongoid-rspec.rb +2 -0
- metadata +8 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0ff9e91940ac839c482f01b93f825a4f30ed64dcf3f4210053a5cac6a490cbbc
|
|
4
|
+
data.tar.gz: 73b94988e7950e2097427412e1c4af87a1413cf891085a53a71924bbae9466ca
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 14504bfe14678c3c4df1eb85438438ab5b705f22ad36bc209bfd15d1bbeb4cc59ab09c0e8227682f8960f8db6cadc7c8731e8ab617d7f1d075e98f06a1085bdc
|
|
7
|
+
data.tar.gz: 4ae265834c188a9236e6c697345f70c5e16fc27c250076c72486030ae3ebc3cb62f1da00df5fefbf5bfd8dabb4e8dd29c26d80d26a1638e9a7e58d8824c2aa03
|
data/README.md
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
# [mongoid-rspec](https://github.com/mongoid/mongoid-rspec "A collection of RSpec-compatible matchers that help to test Mongoid documents.")
|
|
2
2
|
|
|
3
3
|
[](https://badge.fury.io/rb/mongoid-rspec)
|
|
4
|
-
[](https://github.com/mongoid/mongoid-rspec/actions/workflows/rspec.yml?query=branch%3Amaster)
|
|
5
|
+
[](https://github.com/mongoid/mongoid-rspec/actions/workflows/rubocop.yml?query=branch%3Amaster)
|
|
6
|
+
[](https://coveralls.io/github/mongoid/mongoid-rspec?branch=master)
|
|
7
|
+
|
|
8
|
+
CI collects SimpleCov coverage on Ruby 3.4 with Mongoid 9 and MongoDB 8.0 and submits one report to Coveralls using GitHub's workflow token. To generate a local report, run `COVERAGE=true BUNDLE_GEMFILE=gemfiles/mongoid_9.gemfile bundle install` followed by `COVERAGE=true BUNDLE_GEMFILE=gemfiles/mongoid_9.gemfile bundle exec rake spec`. Reports are written to `coverage/`.
|
|
6
9
|
|
|
7
10
|
The mongoid-rspec library provides a collection of RSpec-compatible matchers that help to test Mongoid documents.
|
|
8
11
|
|
|
9
|
-
[Tested](https://github.com/mongoid/mongoid-
|
|
12
|
+
[Tested](https://github.com/mongoid/mongoid-rspec/actions/workflows/rspec.yml) against:
|
|
10
13
|
- MRI: `2.6.x`, `2.7.x`, `3.0.x`, `3.1.x`, `3.2.x`
|
|
11
14
|
- Mongoid: `4`, `5`, `6`, `7`, `8`, `9`
|
|
12
15
|
|
data/Rakefile
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
if Mongoid::Compatibility::Version.mongoid7_or_newer?
|
|
2
4
|
require 'mongoid/association'
|
|
3
5
|
else
|
|
@@ -30,7 +32,7 @@ module Mongoid
|
|
|
30
32
|
@association = {}
|
|
31
33
|
@association[:name] = name.to_s
|
|
32
34
|
@association[:type] = association_type
|
|
33
|
-
@expectation_message = "#{type_description} #{@association[:name].inspect}"
|
|
35
|
+
@expectation_message = +"#{type_description} #{@association[:name].inspect}"
|
|
34
36
|
@expectation_message << " of type #{@association[:class].inspect}" unless @association[:class].nil?
|
|
35
37
|
end
|
|
36
38
|
|
|
@@ -318,19 +320,19 @@ module Mongoid
|
|
|
318
320
|
type ||= @association[:type]
|
|
319
321
|
case type.name
|
|
320
322
|
when EMBEDS_ONE.name
|
|
321
|
-
(passive ? 'embed' : 'embeds') << ' one'
|
|
323
|
+
+(passive ? 'embed' : 'embeds') << ' one'
|
|
322
324
|
when EMBEDS_MANY.name
|
|
323
|
-
(passive ? 'embed' : 'embeds') << ' many'
|
|
325
|
+
+(passive ? 'embed' : 'embeds') << ' many'
|
|
324
326
|
when EMBEDDED_IN.name
|
|
325
|
-
(passive ? 'be' : 'is') << ' embedded in'
|
|
327
|
+
+(passive ? 'be' : 'is') << ' embedded in'
|
|
326
328
|
when HAS_ONE.name
|
|
327
|
-
(passive ? 'reference' : 'references') << ' one'
|
|
329
|
+
+(passive ? 'reference' : 'references') << ' one'
|
|
328
330
|
when HAS_MANY.name
|
|
329
|
-
(passive ? 'reference' : 'references') << ' many'
|
|
331
|
+
+(passive ? 'reference' : 'references') << ' many'
|
|
330
332
|
when HAS_AND_BELONGS_TO_MANY.name
|
|
331
|
-
(passive ? 'reference' : 'references') << ' and referenced in many'
|
|
333
|
+
+(passive ? 'reference' : 'references') << ' and referenced in many'
|
|
332
334
|
when BELONGS_TO.name
|
|
333
|
-
(passive ? 'be referenced in' : 'referenced in')
|
|
335
|
+
+(passive ? 'be referenced in' : 'referenced in')
|
|
334
336
|
else
|
|
335
337
|
raise format("Unknown association type '%s'", type)
|
|
336
338
|
end
|
data/lib/matchers/have_field.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Mongoid
|
|
2
4
|
module Matchers
|
|
3
5
|
class HaveField # :nodoc:
|
|
@@ -30,7 +32,7 @@ module Mongoid
|
|
|
30
32
|
@errors = []
|
|
31
33
|
@attributes.each do |attr|
|
|
32
34
|
if @klass.fields.include?(attr)
|
|
33
|
-
error = ''
|
|
35
|
+
error = +''
|
|
34
36
|
if @type && (@klass.fields[attr].type != @type)
|
|
35
37
|
error << " of type #{@klass.fields[attr].type}"
|
|
36
38
|
end
|
|
@@ -47,7 +49,7 @@ module Mongoid
|
|
|
47
49
|
error << " with alias #{@klass.fields[attr].options[:as]}"
|
|
48
50
|
end
|
|
49
51
|
|
|
50
|
-
@errors.push("field #{attr.inspect}"
|
|
52
|
+
@errors.push("field #{attr.inspect}#{error}") unless error.blank?
|
|
51
53
|
|
|
52
54
|
if @localized
|
|
53
55
|
unless @klass.fields[attr].localized?
|
|
@@ -74,7 +76,7 @@ module Mongoid
|
|
|
74
76
|
alias failure_message_when_negated failure_message_for_should_not
|
|
75
77
|
|
|
76
78
|
def description
|
|
77
|
-
desc = "have #{@attributes.size > 1 ? 'fields' : 'field'} named #{@attributes.collect(&:inspect).to_sentence}"
|
|
79
|
+
desc = +"have #{@attributes.size > 1 ? 'fields' : 'field'} named #{@attributes.collect(&:inspect).to_sentence}"
|
|
78
80
|
desc << " of type #{@type.inspect}" if @type
|
|
79
81
|
desc << " with alias #{@field_alias}" if @field_alias
|
|
80
82
|
desc << " with default value of #{@default.inspect}" unless @default.nil?
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Mongoid
|
|
2
4
|
module Matchers
|
|
3
5
|
def have_timestamps
|
|
@@ -6,7 +8,7 @@ module Mongoid
|
|
|
6
8
|
|
|
7
9
|
class HaveTimestamps
|
|
8
10
|
def initialize
|
|
9
|
-
@root_module = 'Mongoid::Timestamps'
|
|
11
|
+
@root_module = +'Mongoid::Timestamps'
|
|
10
12
|
end
|
|
11
13
|
|
|
12
14
|
def matches?(actual)
|
|
@@ -15,7 +17,7 @@ module Mongoid
|
|
|
15
17
|
end
|
|
16
18
|
|
|
17
19
|
def for(phase)
|
|
18
|
-
raise('You\'ve already declared
|
|
20
|
+
raise('You\'ve already declared timestamp\'s sub-module via "for" clause') if @submodule
|
|
19
21
|
|
|
20
22
|
case @phase = phase.to_sym
|
|
21
23
|
when :creating then @submodule = 'Created'
|
|
@@ -33,7 +35,7 @@ module Mongoid
|
|
|
33
35
|
end
|
|
34
36
|
|
|
35
37
|
def description
|
|
36
|
-
desc = 'be a Mongoid document with'
|
|
38
|
+
desc = +'be a Mongoid document with'
|
|
37
39
|
desc << ' shorted' if @shortened
|
|
38
40
|
desc << " #{@phase}" if @phase
|
|
39
41
|
desc << ' timestamps'
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Mongoid
|
|
2
4
|
module Matchers
|
|
3
5
|
def have_index_for(index_key)
|
|
@@ -36,7 +38,7 @@ module Mongoid
|
|
|
36
38
|
alias failure_message_when_negated failure_message_for_should_not
|
|
37
39
|
|
|
38
40
|
def description
|
|
39
|
-
desc = "have an index for #{index_key.inspect}"
|
|
41
|
+
desc = +"have an index for #{index_key.inspect}"
|
|
40
42
|
desc << " with options of #{index_options.inspect}" if index_options
|
|
41
43
|
desc
|
|
42
44
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Mongoid
|
|
2
4
|
module Matchers
|
|
3
5
|
def have_index_for(index_key)
|
|
@@ -15,7 +17,7 @@ module Mongoid
|
|
|
15
17
|
end
|
|
16
18
|
|
|
17
19
|
def failure_message
|
|
18
|
-
message = "Expected #{model.inspect} to #{description},"
|
|
20
|
+
message = +"Expected #{model.inspect} to #{description},"
|
|
19
21
|
message << if actual_index.nil?
|
|
20
22
|
' found no index'
|
|
21
23
|
else
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Mongoid
|
|
2
4
|
module Matchers
|
|
3
5
|
module Validations
|
|
@@ -19,9 +21,9 @@ module Mongoid
|
|
|
19
21
|
end
|
|
20
22
|
|
|
21
23
|
def description
|
|
22
|
-
options_desc =
|
|
24
|
+
options_desc = +"validate field #{@field.inspect}"
|
|
23
25
|
options_desc << " with custom validator #{@custom_validator.name}" if @validator
|
|
24
|
-
|
|
26
|
+
options_desc
|
|
25
27
|
end
|
|
26
28
|
|
|
27
29
|
private
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Mongoid
|
|
2
4
|
module Matchers
|
|
3
5
|
module Validations
|
|
@@ -12,7 +14,7 @@ module Mongoid
|
|
|
12
14
|
end
|
|
13
15
|
|
|
14
16
|
def matches?(actual)
|
|
15
|
-
return false unless result = super(actual)
|
|
17
|
+
return false unless (result = super(actual))
|
|
16
18
|
|
|
17
19
|
if @not_allowed_values
|
|
18
20
|
raw_validator_not_allowed_values = @validator.options[:in]
|
|
@@ -24,9 +26,9 @@ module Mongoid
|
|
|
24
26
|
|
|
25
27
|
allowed_values = @not_allowed_values - validator_not_allowed_values
|
|
26
28
|
if allowed_values.empty?
|
|
27
|
-
@positive_result_message
|
|
29
|
+
@positive_result_message << ' not allowing all values mentioned'
|
|
28
30
|
else
|
|
29
|
-
@negative_result_message
|
|
31
|
+
@negative_result_message << " allowing the following the ff. values: #{allowed_values.inspect}"
|
|
30
32
|
result = false
|
|
31
33
|
end
|
|
32
34
|
end
|
data/lib/matchers/validations.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Mongoid
|
|
2
4
|
module Matchers
|
|
3
5
|
module Validations
|
|
@@ -17,10 +19,10 @@ module Mongoid
|
|
|
17
19
|
end
|
|
18
20
|
|
|
19
21
|
if @validator
|
|
20
|
-
@negative_result_message = "#{@type.inspect} validator on #{@field.inspect}"
|
|
21
|
-
@positive_result_message = "#{@type.inspect} validator on #{@field.inspect}"
|
|
22
|
+
@negative_result_message = +"#{@type.inspect} validator on #{@field.inspect}"
|
|
23
|
+
@positive_result_message = +"#{@type.inspect} validator on #{@field.inspect}"
|
|
22
24
|
else
|
|
23
|
-
@negative_result_message = "no #{@type.inspect} validator on #{@field.inspect}"
|
|
25
|
+
@negative_result_message = +"no #{@type.inspect} validator on #{@field.inspect}"
|
|
24
26
|
return false
|
|
25
27
|
end
|
|
26
28
|
@result = true
|
|
@@ -41,10 +43,9 @@ module Mongoid
|
|
|
41
43
|
alias failure_message_when_negated failure_message_for_should_not
|
|
42
44
|
|
|
43
45
|
def description
|
|
44
|
-
desc = "have #{@type.inspect} validator on #{@field.inspect}"
|
|
46
|
+
desc = +"have #{@type.inspect} validator on #{@field.inspect}"
|
|
45
47
|
desc << " on #{@options[:on]}" if @options[:on]
|
|
46
48
|
desc << " with message #{@expected_message.inspect}" if @expected_message
|
|
47
|
-
|
|
48
49
|
desc
|
|
49
50
|
end
|
|
50
51
|
|
|
@@ -58,28 +59,37 @@ module Mongoid
|
|
|
58
59
|
self
|
|
59
60
|
end
|
|
60
61
|
|
|
62
|
+
def check_conditions
|
|
63
|
+
@check_conditions = true
|
|
64
|
+
self
|
|
65
|
+
end
|
|
66
|
+
|
|
61
67
|
private
|
|
62
68
|
|
|
63
69
|
def if_condition_matches?(actual, validator)
|
|
70
|
+
return true unless @check_conditions
|
|
64
71
|
return true unless validator.options[:if]
|
|
65
72
|
|
|
66
|
-
check_condition
|
|
73
|
+
check_condition(actual, validator.options[:if])
|
|
67
74
|
end
|
|
68
75
|
|
|
69
76
|
def unless_condition_matches?(actual, validator)
|
|
77
|
+
return true unless @check_conditions
|
|
70
78
|
return true unless validator.options[:unless]
|
|
71
79
|
|
|
72
|
-
!check_condition
|
|
80
|
+
!check_condition(actual, validator.options[:unless])
|
|
73
81
|
end
|
|
74
82
|
|
|
75
83
|
def check_condition(actual, filter)
|
|
76
|
-
raise ArgumentError, 'Spec subject must be
|
|
84
|
+
raise ArgumentError, 'Spec subject must be an instance when using .check_conditions' if actual.is_a?(Class)
|
|
77
85
|
|
|
78
86
|
case filter
|
|
79
87
|
when Symbol
|
|
80
|
-
actual.send
|
|
88
|
+
actual.send(filter)
|
|
81
89
|
when ::Proc
|
|
82
|
-
actual.instance_exec(&filter)
|
|
90
|
+
filter.arity.zero? ? actual.instance_exec(&filter) : filter.call(actual)
|
|
91
|
+
when Array
|
|
92
|
+
filter.all? { |f| check_condition(actual, f) }
|
|
83
93
|
else
|
|
84
94
|
raise ArgumentError, "Unexpected filter: #{filter.inspect}"
|
|
85
95
|
end
|
|
@@ -89,7 +99,7 @@ module Mongoid
|
|
|
89
99
|
validator_on_methods = [@validator.options[:on]].flatten
|
|
90
100
|
|
|
91
101
|
if validator_on_methods.any?
|
|
92
|
-
message = " on methods: #{validator_on_methods}"
|
|
102
|
+
message = +" on methods: #{validator_on_methods}"
|
|
93
103
|
|
|
94
104
|
if on_options_covered_by?(@validator)
|
|
95
105
|
@positive_result_message << message
|
data/lib/mongoid/rspec.rb
CHANGED
data/lib/mongoid-rspec.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: mongoid-rspec
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 4.
|
|
4
|
+
version: 4.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Evan Sagge
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date:
|
|
12
|
+
date: 2026-10-15 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: appraisal
|
|
@@ -26,19 +26,19 @@ dependencies:
|
|
|
26
26
|
- !ruby/object:Gem::Version
|
|
27
27
|
version: '2.0'
|
|
28
28
|
- !ruby/object:Gem::Dependency
|
|
29
|
-
name:
|
|
29
|
+
name: ostruct
|
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
|
31
31
|
requirements:
|
|
32
|
-
- - "
|
|
32
|
+
- - ">="
|
|
33
33
|
- !ruby/object:Gem::Version
|
|
34
|
-
version: '0
|
|
34
|
+
version: '0'
|
|
35
35
|
type: :development
|
|
36
36
|
prerelease: false
|
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
|
38
38
|
requirements:
|
|
39
|
-
- - "
|
|
39
|
+
- - ">="
|
|
40
40
|
- !ruby/object:Gem::Version
|
|
41
|
-
version: '0
|
|
41
|
+
version: '0'
|
|
42
42
|
- !ruby/object:Gem::Dependency
|
|
43
43
|
name: pry
|
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -186,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
186
186
|
- !ruby/object:Gem::Version
|
|
187
187
|
version: 1.3.6
|
|
188
188
|
requirements: []
|
|
189
|
-
rubygems_version: 3.5.
|
|
189
|
+
rubygems_version: 3.5.16
|
|
190
190
|
signing_key:
|
|
191
191
|
specification_version: 4
|
|
192
192
|
summary: RSpec matchers for Mongoid
|