easytest 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +17 -4
- data/lib/easytest/case.rb +11 -8
- data/lib/easytest/dsl.rb +9 -2
- data/lib/easytest/expectation.rb +8 -4
- data/lib/easytest/matcher/match.rb +13 -0
- data/lib/easytest/matcher/{not_raise.rb → raise_nothing.rb} +2 -2
- data/lib/easytest/runner.rb +12 -4
- data/lib/easytest/utils.rb +10 -0
- data/lib/easytest/version.rb +1 -1
- data/lib/easytest.rb +2 -1
- data/sig/easytest.rbs +7 -5
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b72dfc70d7a8d0661cc8db8f80722598819cd167ff8eaeceeb15804088df94f0
|
4
|
+
data.tar.gz: 9e3fa802e2efb674630998420f726c32a24021b9eb5bac8df77696ed9e3aeb23
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 956aa6d38ccbbca19cde275ecd821453c8858ff7ce2652528233a480563304ec71c0c1ace5337904a0895287a26aa088e0bd5a5622d602a43e89bd82e402078c
|
7
|
+
data.tar.gz: ab7b14d3296cf0b37c517ff61f57b5b46b5697c9fd01af278f2fb1ca44ebe11b6f085a14565f8094ea41660a5eebfc7ef123b5d1b542ddfd6281ceef2a4a48e5
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,12 @@
|
|
2
2
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
|
5
|
+
## 0.5.0
|
6
|
+
|
7
|
+
- [Breaking] Rename `to_not_raise` to `to_raise_nothing`.
|
8
|
+
- Add `to_match` matcher.
|
9
|
+
- Add `only` to run only any cases.
|
10
|
+
|
5
11
|
## 0.4.0
|
6
12
|
|
7
13
|
- Add `skip` and `test` without block for todo.
|
data/README.md
CHANGED
@@ -75,19 +75,32 @@ The test now passes! 🎉
|
|
75
75
|
|
76
76
|
### Skip
|
77
77
|
|
78
|
-
If you want to skip
|
78
|
+
If you want to skip any cases, you can change `test` to `skip`:
|
79
79
|
|
80
80
|
```diff
|
81
81
|
-test "addition" do
|
82
82
|
+skip "addition" do
|
83
|
-
expect(1 + 2).to_eq 2
|
84
|
-
end
|
85
83
|
```
|
86
84
|
|
85
|
+
Skipped cases will be reported as "skipped".
|
86
|
+
|
87
|
+
### Only
|
88
|
+
|
89
|
+
If you want to run only any cases, you can use `test` to `only`:
|
90
|
+
|
91
|
+
```diff
|
92
|
+
-test "addition" do
|
93
|
+
+only "addition" do
|
94
|
+
```
|
95
|
+
|
96
|
+
Only cases with `only` will be run, and other cases will be skipped.
|
97
|
+
|
87
98
|
### To-do
|
88
99
|
|
89
|
-
If you want to write
|
100
|
+
If you want to write to-do cases, you can use `test` without a block:
|
90
101
|
|
91
102
|
```ruby
|
92
103
|
test "addition"
|
93
104
|
```
|
105
|
+
|
106
|
+
To-do cases will be reported as "todo".
|
data/lib/easytest/case.rb
CHANGED
@@ -4,27 +4,30 @@ module Easytest
|
|
4
4
|
attr_reader :file
|
5
5
|
attr_reader :block
|
6
6
|
attr_reader :skipped
|
7
|
+
attr_reader :only
|
8
|
+
|
7
9
|
alias skipped? skipped
|
10
|
+
alias only? only
|
8
11
|
|
9
|
-
def initialize(name:, file:, skipped: false, &block)
|
12
|
+
def initialize(name:, file:, skipped: false, only: false, &block)
|
10
13
|
@name = name
|
11
14
|
@file = file
|
12
15
|
@block = block
|
13
16
|
@skipped = skipped
|
17
|
+
@only = only
|
14
18
|
end
|
15
19
|
|
16
20
|
def todo?
|
17
21
|
block.nil?
|
18
22
|
end
|
19
23
|
|
20
|
-
def
|
21
|
-
|
22
|
-
|
23
|
-
end
|
24
|
+
def skip!
|
25
|
+
@skipped = true
|
26
|
+
end
|
24
27
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
+
def run
|
29
|
+
return [:todo, Reporter.new(name).report_todo] if todo?
|
30
|
+
return [:skipped, Reporter.new(name).report_skip] if skipped?
|
28
31
|
|
29
32
|
block.call
|
30
33
|
[:passed, nil]
|
data/lib/easytest/dsl.rb
CHANGED
@@ -2,19 +2,26 @@ module Easytest
|
|
2
2
|
module DSL
|
3
3
|
refine Kernel do
|
4
4
|
def test(name, &block)
|
5
|
-
|
5
|
+
Utils.raise_if_no_test_name(name, method: "test")
|
6
6
|
|
7
7
|
file = caller_locations(1, 1).first.absolute_path
|
8
8
|
Easytest.add_case Case.new(name: name, file: file, &block)
|
9
9
|
end
|
10
10
|
|
11
11
|
def skip(name, &block)
|
12
|
-
|
12
|
+
Utils.raise_if_no_test_name(name, method: "skip")
|
13
13
|
|
14
14
|
file = caller_locations(1, 1).first.absolute_path
|
15
15
|
Easytest.add_case Case.new(name: name, file: file, skipped: true, &block)
|
16
16
|
end
|
17
17
|
|
18
|
+
def only(name, &block)
|
19
|
+
Utils.raise_if_no_test_name(name, method: "only")
|
20
|
+
|
21
|
+
file = caller_locations(1, 1).first.absolute_path
|
22
|
+
Easytest.add_case Case.new(name: name, file: file, only: true, &block)
|
23
|
+
end
|
24
|
+
|
18
25
|
def expect(actual = nil, &block)
|
19
26
|
Expectation.new(actual, &block)
|
20
27
|
end
|
data/lib/easytest/expectation.rb
CHANGED
@@ -41,18 +41,22 @@ module Easytest
|
|
41
41
|
Matcher::Include.new(actual: actual, expected: expected, negate: negate).match!
|
42
42
|
end
|
43
43
|
|
44
|
+
def to_match(expected)
|
45
|
+
Matcher::Match.new(actual: actual, expected: expected, negate: negate).match!
|
46
|
+
end
|
47
|
+
|
44
48
|
def to_raise(expected)
|
45
49
|
raise FatalError, "`to_raise` requires a block like `expect { ... }.to_raise`" unless block
|
46
|
-
raise FatalError, "`not.to_raise` can cause a false positive, so use `
|
50
|
+
raise FatalError, "`not.to_raise` can cause a false positive, so use `to_raise_nothing` instead" if negate?
|
47
51
|
raise FatalError, "`to_raise` requires a Class, String, or Regexp" unless [Class, String, Regexp].any? { expected.is_a? _1 }
|
48
52
|
|
49
53
|
Matcher::Raise.new(actual: block, expected: expected, negate: negate).match!
|
50
54
|
end
|
51
55
|
|
52
|
-
def
|
53
|
-
raise FatalError, "`
|
56
|
+
def to_raise_nothing
|
57
|
+
raise FatalError, "`to_raise_nothing` requires a block like `expect { ... }.to_raise_nothing`" unless block
|
54
58
|
|
55
|
-
Matcher::
|
59
|
+
Matcher::RaiseNothing.new(actual: block).match!
|
56
60
|
end
|
57
61
|
|
58
62
|
private
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Easytest
|
2
2
|
module Matcher
|
3
|
-
class
|
3
|
+
class RaiseNothing < Base
|
4
4
|
def initialize(actual:)
|
5
5
|
super(actual: actual, expected: nil)
|
6
6
|
end
|
@@ -20,7 +20,7 @@ module Easytest
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def message
|
23
|
-
"
|
23
|
+
"raise nothing"
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
data/lib/easytest/runner.rb
CHANGED
@@ -17,13 +17,19 @@ module Easytest
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def run
|
20
|
-
|
21
|
-
|
20
|
+
include_only_case = cases.any?(&:only?)
|
21
|
+
|
22
|
+
cases.group_by(&:file).each do |file, cases_per_file|
|
22
23
|
self.file_count += 1
|
23
24
|
|
24
25
|
reports = []
|
25
26
|
|
26
|
-
|
27
|
+
|
28
|
+
cases_per_file.each do |c|
|
29
|
+
if include_only_case && !c.only?
|
30
|
+
c.skip!
|
31
|
+
end
|
32
|
+
|
27
33
|
result, report = c.run
|
28
34
|
|
29
35
|
case result
|
@@ -123,7 +129,9 @@ module Easytest
|
|
123
129
|
end
|
124
130
|
|
125
131
|
list << Rainbow("#{passed_count} passed").green.bright
|
126
|
-
|
132
|
+
|
133
|
+
files_text = "#{file_count} #{Utils.pluralize("file", file_count)}"
|
134
|
+
list << "#{total_count} total #{Rainbow("(#{files_text})").dimgray}"
|
127
135
|
|
128
136
|
list.join(", ")
|
129
137
|
end
|
data/lib/easytest/utils.rb
CHANGED
@@ -10,5 +10,15 @@ module Easytest
|
|
10
10
|
# https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda
|
11
11
|
"\e]8;;file://#{path}\e\\#{Rainbow(dir).dimgray}#{base}\e]8;;\e\\"
|
12
12
|
end
|
13
|
+
|
14
|
+
def raise_if_no_test_name(name, method:)
|
15
|
+
if name.nil? || name.empty?
|
16
|
+
raise FatalError.new("`#{method}` requires a name")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def pluralize(singular, count)
|
21
|
+
count == 1 ? singular : "#{singular}s"
|
22
|
+
end
|
13
23
|
end
|
14
24
|
end
|
data/lib/easytest/version.rb
CHANGED
data/lib/easytest.rb
CHANGED
@@ -20,9 +20,10 @@ require_relative "easytest/matcher/false"
|
|
20
20
|
require_relative "easytest/matcher/include"
|
21
21
|
require_relative "easytest/matcher/instance_of"
|
22
22
|
require_relative "easytest/matcher/kind_of"
|
23
|
+
require_relative "easytest/matcher/match"
|
23
24
|
require_relative "easytest/matcher/nil"
|
24
|
-
require_relative "easytest/matcher/not_raise"
|
25
25
|
require_relative "easytest/matcher/raise"
|
26
|
+
require_relative "easytest/matcher/raise_nothing"
|
26
27
|
require_relative "easytest/matcher/true"
|
27
28
|
|
28
29
|
module Easytest
|
data/sig/easytest.rbs
CHANGED
@@ -11,20 +11,20 @@ module Easytest
|
|
11
11
|
alias to_equal to_eq
|
12
12
|
|
13
13
|
def to_be: (untyped expected) -> untyped
|
14
|
-
|
15
14
|
def to_be_nil: () -> void
|
15
|
+
def to_be_false: () -> void
|
16
|
+
def to_be_true: () -> void
|
16
17
|
|
17
18
|
def to_be_a: (Class expected) -> void
|
18
19
|
def to_be_kind_of: (Class expected) -> void
|
19
20
|
def to_be_instance_of: (Class expected) -> void
|
20
21
|
|
21
|
-
def to_be_false: () -> void
|
22
|
-
def to_be_true: () -> void
|
23
|
-
|
24
22
|
def to_include: (untyped expected) -> void
|
25
23
|
|
24
|
+
def to_match: (untyped expected) -> void
|
25
|
+
|
26
26
|
def to_raise: ((Class | String | Regexp) expected) -> void
|
27
|
-
def
|
27
|
+
def to_raise_nothing: () -> void
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
@@ -34,6 +34,8 @@ module Kernel
|
|
34
34
|
|
35
35
|
def skip: (String name) { () -> void } -> void
|
36
36
|
|
37
|
+
def only: (String name) { () -> void } -> void
|
38
|
+
|
37
39
|
def expect: (untyped actual) -> Easytest::Expectation
|
38
40
|
| { () -> void } -> Easytest::Expectation
|
39
41
|
end
|
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.
|
4
|
+
version: 0.5.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-
|
11
|
+
date: 2022-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rainbow
|
@@ -50,9 +50,10 @@ files:
|
|
50
50
|
- lib/easytest/matcher/include.rb
|
51
51
|
- lib/easytest/matcher/instance_of.rb
|
52
52
|
- lib/easytest/matcher/kind_of.rb
|
53
|
+
- lib/easytest/matcher/match.rb
|
53
54
|
- lib/easytest/matcher/nil.rb
|
54
|
-
- lib/easytest/matcher/not_raise.rb
|
55
55
|
- lib/easytest/matcher/raise.rb
|
56
|
+
- lib/easytest/matcher/raise_nothing.rb
|
56
57
|
- lib/easytest/matcher/true.rb
|
57
58
|
- lib/easytest/reporter.rb
|
58
59
|
- lib/easytest/runner.rb
|