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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3836cb64ba6fddf811e5b16322fbde63e449e8dc5296b4e76d6f122121610cab
4
- data.tar.gz: 3059642e22ce113637f983dc35ab0ad32f358b3c119008218f216b234289f492
3
+ metadata.gz: 433e59a89a64cfe80aab86e0f409e38bed62dab5a8158015f293dd6019fdeb9e
4
+ data.tar.gz: '0197210d9d2f37246668daff52fa510c7ec3490541babb91cfe1f7a59a449c2a'
5
5
  SHA512:
6
- metadata.gz: 76a21298e887a4cc6ca6bc317a8e5508cf2e6910edb4214b0d59072ddae0f36fc0d6f494e3da52eba418ca9b3ed0fbbc85ebf0dff8313f2ebd1add569b4521ad
7
- data.tar.gz: 27f679fb52f4104fc7a90fcda96574fd530b8f30775b9cda7735884523f0ec259ae667d58db76a4d2d568bc2e65785a5daa7ad17e3d3875fd01bfea8765eed02
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
@@ -6,6 +6,7 @@ require "faker"
6
6
  require "active_support/core_ext/object/inclusion"
7
7
 
8
8
  require "rspice/version"
9
+ require "rspice/errors"
9
10
 
10
11
  require "rspice/rspec_configuration"
11
12
  require "rspice/custom_matchers"
@@ -6,3 +6,4 @@ require "rspice/custom_matchers/have_error_on_attribute"
6
6
  require "rspice/custom_matchers/include_module"
7
7
  require "rspice/custom_matchers/inherit_from"
8
8
  require "rspice/custom_matchers/not_change"
9
+ require "rspice/custom_matchers/validate"
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # RSpec matcher that tests tests inheritance of [Classes](https://apidock.com/ruby/Class)
3
+ # RSpec matcher that tests inheritance of [Classes](https://apidock.com/ruby/Class)
4
4
  #
5
5
  # class Klass < ApplicationRecord; end
6
6
  #
@@ -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
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rspice
4
+ class IncompleteMatcherError < StandardError; end
5
+ end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Rspice
4
4
  # This constant is managed by spicerack
5
- VERSION = "0.7.1"
5
+ VERSION = "0.7.2"
6
6
  end
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.1
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-04-24 00:00:00.000000000 Z
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
- rubygems_version: 3.0.3
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