easytest 0.5.2 → 0.6.0

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: a95c7799e7ef8d865ab340077539fe1025fdc390733417dfc1e1563acef4a0c2
4
- data.tar.gz: db722ee94a1805cee7db8381b2f892f7eb7dd5ac5ddf44ae0f36f85f9f6280c3
3
+ metadata.gz: b604c00c58f93e811ba779e0581b57b8eed7df6ef57504bea9239083663af42c
4
+ data.tar.gz: 8912feb299336ea7e242d1f7349fca2cb089af40f751f6c4478c535594eb6269
5
5
  SHA512:
6
- metadata.gz: dfa65af3175c00de2306f78a3698940ba2cc0080d5de9f95b626e75f6630ecae5f80225683176aeac261f2f3e6eb2b6ca488e080b6570ff46785d7219e832626
7
- data.tar.gz: 36cc84ea3f72fe2cda5f12084471a75694205ee86522abd45e7220b9926c19e2efa1061778b617c15c18d371ef37ce5e2dbdb9e82128b6cc55ecf1bb9a195017
6
+ metadata.gz: 0f423c20fe3812b906a37498275cd46c5fe5ac9996b8296f0c3ae7e8889d8a73f643310a82d2e2ffbaee48c393f5a94debe3c2e20b71c1d0710fe1f16491009c
7
+ data.tar.gz: 267b8496e9faea80de95d311bb5d1abb48959499b9765ff37cf588e600950f6a8a5e20b13a21af90818180ad8509d5d7ca74cd1962dc3b3e5eb0fe541f43e8f5
data/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ ## 0.6.0
6
+
7
+ - Add `to_contain_exactly` matcher.
8
+ - Allow `to_raise` to receive the second argument.
9
+
5
10
  ## 0.5.2
6
11
 
7
12
  - Fix `homepage` in gemspec.
@@ -45,12 +45,16 @@ module Easytest
45
45
  Matcher::Match.new(actual: actual, expected: expected, negate: negate).match!
46
46
  end
47
47
 
48
- def to_raise(expected)
48
+ def to_contain_exactly(*expected_items)
49
+ Matcher::ContainExactly.new(actual: actual, expected: expected_items, negate: negate).match!
50
+ end
51
+
52
+ def to_raise(expected, with_message = nil)
49
53
  raise FatalError, "`to_raise` requires a block like `expect { ... }.to_raise`" unless block
50
54
  raise FatalError, "`not.to_raise` can cause a false positive, so use `to_raise_nothing` instead" if negate?
51
55
  raise FatalError, "`to_raise` requires a Class, String, or Regexp" unless [Class, String, Regexp].any? { expected.is_a? _1 }
52
56
 
53
- Matcher::Raise.new(actual: block, expected: expected, negate: negate).match!
57
+ Matcher::Raise.new(actual: block, expected: expected, negate: negate, with_message: with_message).match!
54
58
  end
55
59
 
56
60
  def to_raise_nothing
@@ -0,0 +1,13 @@
1
+ module Easytest
2
+ module Matcher
3
+ class ContainExactly < Base
4
+ def match?
5
+ (actual.to_a - expected).empty?
6
+ end
7
+
8
+ def message
9
+ "contain exactly"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,13 +1,20 @@
1
1
  module Easytest
2
2
  module Matcher
3
3
  class Raise < Base
4
+ attr_reader :with_message
5
+
6
+ def initialize(**kwargs)
7
+ @with_message = kwargs.delete(:with_message)
8
+ super(**kwargs)
9
+ end
10
+
4
11
  def match?
5
12
  begin
6
13
  actual.call
7
14
  false
8
15
  rescue => error
9
16
  @raised_error = error
10
- match_error?(actual: error, expected: expected)
17
+ match_error?(error)
11
18
  end
12
19
  end
13
20
 
@@ -21,14 +28,19 @@ module Easytest
21
28
 
22
29
  private
23
30
 
24
- def match_error?(actual:, expected:)
31
+ def match_error?(error)
25
32
  case expected
26
33
  when Class
27
- actual.class == expected
34
+ matched = error.class == expected
35
+ if with_message
36
+ matched && error.message.match?(with_message)
37
+ else
38
+ matched
39
+ end
28
40
  when String
29
- actual.message == expected
41
+ error.message == expected
30
42
  when Regexp
31
- actual.message.match? expected
43
+ error.message.match? expected
32
44
  else
33
45
  false
34
46
  end
@@ -1,3 +1,3 @@
1
1
  module Easytest
2
- VERSION = "0.5.2"
2
+ VERSION = "0.6.0"
3
3
  end
data/lib/easytest.rb CHANGED
@@ -15,6 +15,7 @@ require_relative "easytest/utils"
15
15
  require_relative "easytest/matcher/base"
16
16
  require_relative "easytest/matcher/be"
17
17
  require_relative "easytest/matcher/be_a"
18
+ require_relative "easytest/matcher/contain_exactly"
18
19
  require_relative "easytest/matcher/equal"
19
20
  require_relative "easytest/matcher/false"
20
21
  require_relative "easytest/matcher/include"
data/sig/easytest.rbs CHANGED
@@ -43,8 +43,12 @@ module Easytest
43
43
  # Expect to match the given object.
44
44
  def to_match: (untyped expected) -> void
45
45
 
46
+ # Expect to contain all the given items regardless of order.
47
+ def to_contain_exactly: (*untyped expected_items) -> void
48
+
46
49
  # Expect to raise the given exception or an exception with the given message.
47
- def to_raise: ((Class | String | Regexp) expected) -> void
50
+ def to_raise: (Class expected, ?(String | Regexp) with_message) -> void
51
+ | ((String | Regexp) expected) -> void
48
52
 
49
53
  # Expect to raise nothing.
50
54
  def to_raise_nothing: () -> void
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easytest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masafumi Koba
@@ -45,6 +45,7 @@ files:
45
45
  - lib/easytest/matcher/base.rb
46
46
  - lib/easytest/matcher/be.rb
47
47
  - lib/easytest/matcher/be_a.rb
48
+ - lib/easytest/matcher/contain_exactly.rb
48
49
  - lib/easytest/matcher/equal.rb
49
50
  - lib/easytest/matcher/false.rb
50
51
  - lib/easytest/matcher/include.rb