matchi 2.0.2 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -4
- data/lib/matchi/matcher/be_an_instance_of.rb +35 -0
- data/lib/matchi/matcher/be_false.rb +1 -1
- data/lib/matchi/matcher/be_nil.rb +1 -1
- data/lib/matchi/matcher/be_true.rb +1 -1
- data/lib/matchi/matcher/eql.rb +1 -1
- data/lib/matchi/matcher/equal.rb +1 -1
- data/lib/matchi/matcher/match.rb +1 -1
- data/lib/matchi/matcher/raise_exception.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c15a21ea2bcdc3ea9c43344bb1ff12216a384bc3d19a996c39a1138c28d18150
|
4
|
+
data.tar.gz: d023d2472ced57399fd14aea2a35cd36b75f7a9ac3705efd48985ccc03a6b9df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
20
|
+
```sh
|
21
|
+
bundle
|
22
|
+
```
|
22
23
|
|
23
24
|
Or install it yourself as:
|
24
25
|
|
25
|
-
|
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
|
data/lib/matchi/matcher/eql.rb
CHANGED
data/lib/matchi/matcher/equal.rb
CHANGED
data/lib/matchi/matcher/match.rb
CHANGED
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
|
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-
|
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
|