matchi 2.0.2 → 2.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fbd646c1f880291334b1f98426cfdedab736a2f87bbb44e149e81bcb5f8affce
4
- data.tar.gz: 9e285052b96848df8be1c22c2033032d2dcbe143ac4d84fa26e9e61b42ac8ee4
3
+ metadata.gz: c15a21ea2bcdc3ea9c43344bb1ff12216a384bc3d19a996c39a1138c28d18150
4
+ data.tar.gz: d023d2472ced57399fd14aea2a35cd36b75f7a9ac3705efd48985ccc03a6b9df
5
5
  SHA512:
6
- metadata.gz: d81a615fca3627cf424226c015e63ab09419be15059b83e926afa3d99819153ced25afca5adfe1421d85bbffcaf4048f2c36531b14b6a9f4920a1f7edf9efd61
7
- data.tar.gz: e80cd7a69eef70a3ca0fc80bb4bf94468c14de22a9309d4bf736ea050e5feeeadf69216eadddc6e4ee678c08ccf64949729a3ef830ed9e1b4b3ca3d5ba23d0f7
6
+ metadata.gz: be27946a8a1aa3d24b978603be5efc2ce29eea9a18455dba435276329388fd1448c8e0f770b649ca34ad0cfce711a4b34939d665254741406f4bfa7602342475
7
+ data.tar.gz: dcdf2ece3a08c3dd266a9f01ebcb76013f3ab6e699b2bb8205656f7e3cd3ba76f786921c68516efc940404e72862a0bd5df9a021bb8c0c0b80720048e2738cc8
data/README.md CHANGED
@@ -3,7 +3,6 @@
3
3
  [![Build Status](https://api.travis-ci.org/fixrb/matchi.svg?branch=main)][travis]
4
4
  [![Code Climate](https://codeclimate.com/github/fixrb/matchi/badges/gpa.svg)][codeclimate]
5
5
  [![Gem Version](https://badge.fury.io/rb/matchi.svg)][gem]
6
- [![Inline docs](https://inch-ci.org/github/fixrb/matchi.svg?branch=main)][inchpages]
7
6
  [![Documentation](https://img.shields.io/:yard-docs-38c800.svg)][rubydoc]
8
7
 
9
8
  > Collection of expectation matchers for Ruby 🤹
@@ -18,11 +17,15 @@ gem "matchi"
18
17
 
19
18
  And then execute:
20
19
 
21
- $ bundle
20
+ ```sh
21
+ bundle
22
+ ```
22
23
 
23
24
  Or install it yourself as:
24
25
 
25
- $ gem install matchi
26
+ ```sh
27
+ gem install matchi
28
+ ```
26
29
 
27
30
  ## Usage
28
31
 
@@ -77,6 +80,13 @@ be_nil = Matchi::Matcher::BeNil.new
77
80
  be_nil.matches? { nil } # => true
78
81
  ```
79
82
 
83
+ **Type/class** matcher:
84
+
85
+ ```ruby
86
+ be_an_instance_of = Matchi::Matcher::BeAnInstanceOf.new(String)
87
+ be_an_instance_of.matches? { "foo" } # => true
88
+ ```
89
+
80
90
  ### Custom matchers
81
91
 
82
92
  Custom matchers can easily be defined for expressing expectations. They can be any Ruby class that responds to `matches?`, `to_s` and `to_h` instance methods.
@@ -164,5 +174,4 @@ The [gem](https://rubygems.org/gems/matchi) is available as open source under th
164
174
  [gem]: https://rubygems.org/gems/matchi
165
175
  [travis]: https://travis-ci.org/fixrb/matchi
166
176
  [codeclimate]: https://codeclimate.com/github/fixrb/matchi
167
- [inchpages]: https://inch-ci.org/github/fixrb/matchi
168
177
  [rubydoc]: https://rubydoc.info/gems/matchi/frames
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "base"
4
+
5
+ module Matchi
6
+ module Matcher
7
+ # *Type/class* matcher.
8
+ class BeAnInstanceOf < ::Matchi::Matcher::Base
9
+ # Initialize the matcher with an object.
10
+ #
11
+ # @example A string matcher
12
+ # Matchi::Matcher::BeAnInstanceOf.new(String)
13
+ #
14
+ # @param expected [Class] An expected class.
15
+ def initialize(expected)
16
+ super()
17
+ @expected = expected
18
+ end
19
+
20
+ # Boolean comparison between the class of the actual value and the
21
+ # expected class.
22
+ #
23
+ # @example Is it an instance of string?
24
+ # be_an_instance_of = Matchi::Matcher::BeInstanceOf.new(String)
25
+ # be_an_instance_of.matches? { "foo" } # => true
26
+ #
27
+ # @yieldreturn [#class] the actual value to compare to the expected one.
28
+ #
29
+ # @return [Boolean] Comparison between actual and expected values.
30
+ def matches?(*, **)
31
+ expected.equal?(yield.class)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -4,7 +4,7 @@ require_relative "base"
4
4
 
5
5
  module Matchi
6
6
  module Matcher
7
- # **Untruth** matcher.
7
+ # *Untruth* matcher.
8
8
  class BeFalse < ::Matchi::Matcher::Base
9
9
  # Boolean comparison between the actual value and the expected value.
10
10
  #
@@ -4,7 +4,7 @@ require_relative "base"
4
4
 
5
5
  module Matchi
6
6
  module Matcher
7
- # **Nil** matcher.
7
+ # *Nil* matcher.
8
8
  class BeNil < ::Matchi::Matcher::Base
9
9
  # Boolean comparison between the actual value and the expected value.
10
10
  #
@@ -4,7 +4,7 @@ require_relative "base"
4
4
 
5
5
  module Matchi
6
6
  module Matcher
7
- # **Truth** matcher.
7
+ # *Truth* matcher.
8
8
  class BeTrue < ::Matchi::Matcher::Base
9
9
  # Boolean comparison between the actual value and the expected value.
10
10
  #
@@ -4,7 +4,7 @@ require_relative "base"
4
4
 
5
5
  module Matchi
6
6
  module Matcher
7
- # **Equivalence** matcher.
7
+ # *Equivalence* matcher.
8
8
  class Eql < ::Matchi::Matcher::Base
9
9
  # Initialize the matcher with an object.
10
10
  #
@@ -4,7 +4,7 @@ require_relative "base"
4
4
 
5
5
  module Matchi
6
6
  module Matcher
7
- # **Identity** matcher.
7
+ # *Identity* matcher.
8
8
  class Equal < ::Matchi::Matcher::Base
9
9
  # Initialize the matcher with an object.
10
10
  #
@@ -4,7 +4,7 @@ require_relative "base"
4
4
 
5
5
  module Matchi
6
6
  module Matcher
7
- # **Regular expressions** matcher.
7
+ # *Regular expressions* matcher.
8
8
  class Match < ::Matchi::Matcher::Base
9
9
  # Initialize the matcher with an instance of Regexp.
10
10
  #
@@ -4,7 +4,7 @@ require_relative "base"
4
4
 
5
5
  module Matchi
6
6
  module Matcher
7
- # **Expecting errors** matcher.
7
+ # *Expecting errors* matcher.
8
8
  class RaiseException < ::Matchi::Matcher::Base
9
9
  # Initialize the matcher with a descendant of class Exception.
10
10
  #
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: matchi
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cyril Kato
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-07 00:00:00.000000000 Z
11
+ date: 2021-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -134,6 +134,7 @@ files:
134
134
  - lib/matchi/helper.rb
135
135
  - lib/matchi/matcher.rb
136
136
  - lib/matchi/matcher/base.rb
137
+ - lib/matchi/matcher/be_an_instance_of.rb
137
138
  - lib/matchi/matcher/be_false.rb
138
139
  - lib/matchi/matcher/be_nil.rb
139
140
  - lib/matchi/matcher/be_true.rb