rspice 0.7.1 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/rspice.rb +1 -0
- data/lib/rspice/custom_matchers.rb +1 -0
- data/lib/rspice/custom_matchers/inherit_from.rb +1 -1
- data/lib/rspice/custom_matchers/not_change.rb +16 -0
- data/lib/rspice/custom_matchers/validate.rb +53 -0
- data/lib/rspice/errors.rb +5 -0
- data/lib/rspice/version.rb +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 433e59a89a64cfe80aab86e0f409e38bed62dab5a8158015f293dd6019fdeb9e
|
4
|
+
data.tar.gz: '0197210d9d2f37246668daff52fa510c7ec3490541babb91cfe1f7a59a449c2a'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d8fb6f73405cf0796150e6a96d0d336795d7aafd28b105b710ff39dc180d5adc0e2790d94b84256a9bbc5cde04577d019bcf66551d111acdb13a2b003adabf5
|
7
|
+
data.tar.gz: 1054cd43b84d8f5d3fe0ce2640694eb956a0ca67b82acf2428823842558495b9ebd3228740e12416d49f1497f25066653c301903844860e0aa9336cc5ffc2d68
|
data/README.md
CHANGED
@@ -47,6 +47,8 @@ require 'rspice'
|
|
47
47
|
* [have_error_on_attribute](lib/rspice/custom_matchers/have_error_on_attribute.rb) tests usages of [ActiveModel::Errors](https://api.rubyonrails.org/classes/ActiveModel/Errors.html)
|
48
48
|
* [include_module](lib/rspice/custom_matchers/include_module.rb) tests usages of [Module#include](https://apidock.com/ruby/Module/include)
|
49
49
|
* [inherit_from](lib/rspice/custom_matchers/inherit_from.rb) tests inheritance of [Classes](https://apidock.com/ruby/Class)
|
50
|
+
* [not_change](lib/rspice/custom_matchers/not_change.rb) negated `change` matcher
|
51
|
+
* [validate](lib/rspice/custom_matchers/validate.rb) tests application and configuration of custom validators
|
50
52
|
|
51
53
|
## Shared Context
|
52
54
|
|
data/lib/rspice.rb
CHANGED
@@ -1,3 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# RSpec matcher that tests that an object does not change.
|
4
|
+
# Because of how RSpec's `change` matcher works, this is required
|
5
|
+
# to chain multiple negated change matchers.
|
6
|
+
#
|
7
|
+
# def noop
|
8
|
+
# # I don't do anything!
|
9
|
+
# end
|
10
|
+
#
|
11
|
+
# describe "#noop" do
|
12
|
+
# it "doesn't change anything in the database" do
|
13
|
+
# expect { noop }.
|
14
|
+
# not_to change { User.count }.
|
15
|
+
# and not_change { Article.count }
|
16
|
+
# end
|
17
|
+
# end
|
18
|
+
|
3
19
|
RSpec::Matchers.define_negated_matcher(:not_change, :change)
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# RSpec matcher that tests application of a custom validator to a spefific attribute
|
4
|
+
#
|
5
|
+
# describe User do
|
6
|
+
# # With no options:
|
7
|
+
# it { is_expected.to validate(:an_attribute).with(CustomValidator) }
|
8
|
+
#
|
9
|
+
# # With options:
|
10
|
+
# it { is_expected.to validate(:an_attribute).with(CustomValidator).with_options(aliased_as: :a_property) }
|
11
|
+
# end
|
12
|
+
|
13
|
+
RSpec::Matchers.define :validate do |attribute|
|
14
|
+
match do |subject|
|
15
|
+
raise Rspice::IncompleteMatcherError, "validator class not provided" unless @expected_validator.present?
|
16
|
+
|
17
|
+
@validator = subject.class.validators.find do |validator|
|
18
|
+
next unless validator.respond_to?(:attributes)
|
19
|
+
|
20
|
+
validator.attributes.include?(attribute.to_sym) && validator.class == @expected_validator
|
21
|
+
end
|
22
|
+
|
23
|
+
@validator.present? && options_matching?
|
24
|
+
end
|
25
|
+
|
26
|
+
def options_matching?
|
27
|
+
if @options.present?
|
28
|
+
@options.keys.all? { |option| @validator.options[option] == @options[option] }
|
29
|
+
else
|
30
|
+
true
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
chain :with do |validator|
|
35
|
+
@expected_validator = validator
|
36
|
+
end
|
37
|
+
|
38
|
+
chain :with_options do |options|
|
39
|
+
@options = options
|
40
|
+
end
|
41
|
+
|
42
|
+
description do
|
43
|
+
"validate with #{@validator.class}#{" with options #{@options}" if @options.present?}"
|
44
|
+
end
|
45
|
+
|
46
|
+
failure_message do
|
47
|
+
"expected to validate #{attribute} with #{@expected_validator}#{" with options #{@options}" if @options.present?}"
|
48
|
+
end
|
49
|
+
|
50
|
+
failure_message_when_negated do
|
51
|
+
"not expected to validate #{attribute} with #{@expected_validator}#{" with options #{@options}" if @options.present?}"
|
52
|
+
end
|
53
|
+
end
|
data/lib/rspice/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspice
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Garside
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-05-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -56,6 +56,8 @@ files:
|
|
56
56
|
- lib/rspice/custom_matchers/include_module.rb
|
57
57
|
- lib/rspice/custom_matchers/inherit_from.rb
|
58
58
|
- lib/rspice/custom_matchers/not_change.rb
|
59
|
+
- lib/rspice/custom_matchers/validate.rb
|
60
|
+
- lib/rspice/errors.rb
|
59
61
|
- lib/rspice/rspec_configuration.rb
|
60
62
|
- lib/rspice/shared_context.rb
|
61
63
|
- lib/rspice/shared_context/with_an_example_descendant_class.rb
|
@@ -88,7 +90,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
88
90
|
- !ruby/object:Gem::Version
|
89
91
|
version: '0'
|
90
92
|
requirements: []
|
91
|
-
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 2.7.6
|
92
95
|
signing_key:
|
93
96
|
specification_version: 4
|
94
97
|
summary: An `RSpec` utility gem of custom matchers, shared contexts and examples
|