easytest 0.5.2 → 0.7.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: 5f45ff0adb716aa609a9fce9fd5eaefab60b8d56e4b2708a26b56d63189c3b78
4
+ data.tar.gz: 93b56e1770e0cd3a7d233580eddbd72737e56de4c5ebe405f244c6ca300f1ab9
5
5
  SHA512:
6
- metadata.gz: dfa65af3175c00de2306f78a3698940ba2cc0080d5de9f95b626e75f6630ecae5f80225683176aeac261f2f3e6eb2b6ca488e080b6570ff46785d7219e832626
7
- data.tar.gz: 36cc84ea3f72fe2cda5f12084471a75694205ee86522abd45e7220b9926c19e2efa1061778b617c15c18d371ef37ce5e2dbdb9e82128b6cc55ecf1bb9a195017
6
+ metadata.gz: 14fe72a70136f6aeca4f044bee8c4616d6b3ac8ee32f43bb46b1c888dd70823e73574204c32a91dd48b5df73233e217adfc9b19d6a05c2181a4df2974a4cdb1b
7
+ data.tar.gz: 90bd1e9e0c2e30905e1c2b4875c29fdc93b861da2ae26cd3df8441bdd5b5bb973b27a9830fe9c5597593ca398362ebeb2b26e96dcb65d0f4a93c1ae76a56e7ac
data/CHANGELOG.md CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ ## 0.7.0
6
+
7
+ - Add `to_be_empty` matcher.
8
+ - Avoid unstable `Enumerable#sort_by` method.
9
+
10
+ ## 0.6.0
11
+
12
+ - Add `to_contain_exactly` matcher.
13
+ - Allow `to_raise` to receive the second argument.
14
+
5
15
  ## 0.5.2
6
16
 
7
17
  - Fix `homepage` in gemspec.
@@ -14,15 +14,15 @@ module Easytest
14
14
  end
15
15
 
16
16
  def to_be_nil
17
- Matcher::Nil.new(actual: actual, negate: negate).match!
17
+ Matcher::Nil.new(actual: actual, expected: nil, negate: negate).match!
18
18
  end
19
19
 
20
20
  def to_be_true
21
- Matcher::True.new(actual: actual, negate: negate).match!
21
+ Matcher::True.new(actual: actual, expected: true, negate: negate).match!
22
22
  end
23
23
 
24
24
  def to_be_false
25
- Matcher::False.new(actual: actual, negate: negate).match!
25
+ Matcher::False.new(actual: actual, expected: false, negate: negate).match!
26
26
  end
27
27
 
28
28
  def to_be_a(expected)
@@ -37,6 +37,10 @@ module Easytest
37
37
  Matcher::InstanceOf.new(actual: actual, expected: expected, negate: negate).match!
38
38
  end
39
39
 
40
+ def to_be_empty
41
+ Matcher::Empty.new(actual: actual, expected: nil, negate: negate).match!
42
+ end
43
+
40
44
  def to_include(expected)
41
45
  Matcher::Include.new(actual: actual, expected: expected, negate: negate).match!
42
46
  end
@@ -45,12 +49,16 @@ module Easytest
45
49
  Matcher::Match.new(actual: actual, expected: expected, negate: negate).match!
46
50
  end
47
51
 
48
- def to_raise(expected)
52
+ def to_contain_exactly(*expected_items)
53
+ Matcher::ContainExactly.new(actual: actual, expected: expected_items, negate: negate).match!
54
+ end
55
+
56
+ def to_raise(expected, with_message = nil)
49
57
  raise FatalError, "`to_raise` requires a block like `expect { ... }.to_raise`" unless block
50
58
  raise FatalError, "`not.to_raise` can cause a false positive, so use `to_raise_nothing` instead" if negate?
51
59
  raise FatalError, "`to_raise` requires a Class, String, or Regexp" unless [Class, String, Regexp].any? { expected.is_a? _1 }
52
60
 
53
- Matcher::Raise.new(actual: block, expected: expected, negate: negate).match!
61
+ Matcher::Raise.new(actual: block, expected: expected, negate: negate, with_message: with_message).match!
54
62
  end
55
63
 
56
64
  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
@@ -0,0 +1,13 @@
1
+ module Easytest
2
+ module Matcher
3
+ class Empty < Base
4
+ def match?
5
+ actual.empty?
6
+ end
7
+
8
+ def message
9
+ "empty"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,10 +1,6 @@
1
1
  module Easytest
2
2
  module Matcher
3
3
  class False < Base
4
- def initialize(actual:, negate:)
5
- super(actual: actual, expected: false, negate: negate)
6
- end
7
-
8
4
  def match?
9
5
  actual == expected
10
6
  end
@@ -1,10 +1,6 @@
1
1
  module Easytest
2
2
  module Matcher
3
3
  class Nil < Base
4
- def initialize(actual:, negate:)
5
- super(actual: actual, expected: nil, negate: negate)
6
- end
7
-
8
4
  def match?
9
5
  actual.nil?
10
6
  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,10 +1,6 @@
1
1
  module Easytest
2
2
  module Matcher
3
3
  class True < Base
4
- def initialize(actual:, negate:)
5
- super(actual: actual, expected: true, negate: negate)
6
- end
7
-
8
4
  def match?
9
5
  actual == expected
10
6
  end
@@ -24,7 +24,6 @@ module Easytest
24
24
 
25
25
  reports = []
26
26
 
27
-
28
27
  cases_per_file.each do |c|
29
28
  if include_only_case && !c.only?
30
29
  c.skip!
@@ -56,19 +55,7 @@ module Easytest
56
55
  puts "#{Rainbow(" FAIL ").bright.bg(:red)} #{link}"
57
56
  end
58
57
 
59
- reports
60
- .sort_by do |result, _|
61
- case result
62
- when :skipped, :todo
63
- 0
64
- else
65
- 1
66
- end
67
- end
68
- .each do |result, report|
69
- puts report.gsub(/^/, " ").gsub(/^\s+$/, "")
70
- puts "" if result == :failed
71
- end
58
+ print_reports(reports)
72
59
  end
73
60
 
74
61
  if no_tests?
@@ -109,6 +96,20 @@ module Easytest
109
96
  total_count == 0
110
97
  end
111
98
 
99
+ def print_reports(reports)
100
+ unexecuted = [:skipped, :todo]
101
+ indent = " "
102
+
103
+ reports.each do |result, report|
104
+ puts Utils.indent_text(report, indent) if unexecuted.include?(result)
105
+ end
106
+
107
+ reports.each do |result, report|
108
+ puts Utils.indent_text(report, indent) unless unexecuted.include?(result)
109
+ puts "" if result == :failed
110
+ end
111
+ end
112
+
112
113
  def elapsed_time
113
114
  Time.now - start_time
114
115
  end
@@ -20,5 +20,9 @@ module Easytest
20
20
  def pluralize(singular, count)
21
21
  count == 1 ? singular : "#{singular}s"
22
22
  end
23
+
24
+ def indent_text(text, indent_string)
25
+ text.gsub(/^(.+)/, "#{indent_string}\\1")
26
+ end
23
27
  end
24
28
  end
@@ -1,3 +1,3 @@
1
1
  module Easytest
2
- VERSION = "0.5.2"
2
+ VERSION = "0.7.0"
3
3
  end
data/lib/easytest.rb CHANGED
@@ -15,6 +15,8 @@ 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"
19
+ require_relative "easytest/matcher/empty"
18
20
  require_relative "easytest/matcher/equal"
19
21
  require_relative "easytest/matcher/false"
20
22
  require_relative "easytest/matcher/include"
data/sig/easytest.rbs CHANGED
@@ -37,14 +37,21 @@ module Easytest
37
37
  # Expect to be an instance of the given class (module).
38
38
  def to_be_instance_of: (Module expected) -> void
39
39
 
40
+ # Expect to be empty.
41
+ def to_be_empty: () -> void
42
+
40
43
  # Expect to include the given object.
41
44
  def to_include: (untyped expected) -> void
42
45
 
43
46
  # Expect to match the given object.
44
47
  def to_match: (untyped expected) -> void
45
48
 
49
+ # Expect to contain all the given items regardless of order.
50
+ def to_contain_exactly: (*untyped expected_items) -> void
51
+
46
52
  # Expect to raise the given exception or an exception with the given message.
47
- def to_raise: ((Class | String | Regexp) expected) -> void
53
+ def to_raise: (Class expected, ?(String | Regexp) with_message) -> void
54
+ | ((String | Regexp) expected) -> void
48
55
 
49
56
  # Expect to raise nothing.
50
57
  def to_raise_nothing: () -> void
metadata CHANGED
@@ -1,14 +1,14 @@
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.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masafumi Koba
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-10-07 00:00:00.000000000 Z
11
+ date: 2022-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rainbow
@@ -45,6 +45,8 @@ 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
49
+ - lib/easytest/matcher/empty.rb
48
50
  - lib/easytest/matcher/equal.rb
49
51
  - lib/easytest/matcher/false.rb
50
52
  - lib/easytest/matcher/include.rb