easytest 0.2.0 → 0.3.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 +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +7 -4
- data/exe/easytest +1 -1
- data/lib/easytest/cli.rb +77 -7
- data/lib/easytest/expectation.rb +16 -13
- data/lib/easytest/matcher/raise.rb +1 -1
- data/lib/easytest/runner.rb +6 -4
- data/lib/easytest/version.rb +1 -1
- data/lib/easytest.rb +0 -1
- data/sig/easytest.rbs +37 -0
- 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: 9c1fb5f44f3dd5d049cd6775120712a614f7016a20c7f87d771043642ceb7bb6
|
4
|
+
data.tar.gz: '04591bad578ad4351de07ab07467378663cea9e0de2d40930aea5d4a3d132bac'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 718b38f0a0fc35339bdaae214baf115de1ee8d4a94bb20d157f102af5caf08a763580e2946976504443e3b45211fc5d8776668b353c9a9c07e5ed9abddca03e3
|
7
|
+
data.tar.gz: 4784ee059e028d9d8a7c6ed23d864182e280ced00d56e502b87d31b032212bde623b50b66fed087583f0ee24eda939900915d8d25fe9081bdf33b020930b7423
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
[](https://badge.fury.io/rb/easytest)
|
2
|
+
[](https://github.com/ybiquitous/easytest/actions/workflows/ci.yml)
|
2
3
|
|
3
4
|
# Easytest
|
4
5
|
|
5
6
|
> makes you write tests easily
|
6
7
|
|
7
|
-
Easytest is a tiny testing framework with a familiar DSL.
|
8
|
+
Easytest is a tiny testing framework for Ruby with a familiar DSL.
|
8
9
|
|
9
10
|
## Installation
|
10
11
|
|
@@ -39,7 +40,7 @@ end
|
|
39
40
|
Then, run `easytest`:
|
40
41
|
|
41
42
|
```console
|
42
|
-
$
|
43
|
+
$ easytest
|
43
44
|
FAIL test/addition_test.rb
|
44
45
|
● addition (should equal)
|
45
46
|
|
@@ -63,11 +64,13 @@ Oops. Let's fix the failure:
|
|
63
64
|
Then, run it again:
|
64
65
|
|
65
66
|
```console
|
66
|
-
$
|
67
|
+
$ easytest
|
67
68
|
PASS test/addition_test.rb
|
68
69
|
|
69
70
|
Tests: 1 passed, 1 total (1 files)
|
70
71
|
Time: 0.00077 seconds
|
71
72
|
```
|
72
73
|
|
73
|
-
The test passes! 🎉
|
74
|
+
The test now passes! 🎉
|
75
|
+
|
76
|
+
For more, try `easytest --help`.
|
data/exe/easytest
CHANGED
data/lib/easytest/cli.rb
CHANGED
@@ -1,7 +1,23 @@
|
|
1
|
+
require "easytest"
|
2
|
+
require "optparse"
|
3
|
+
|
1
4
|
module Easytest
|
2
5
|
class CLI
|
3
6
|
SUCCESS = 0
|
4
7
|
FAILURE = 1
|
8
|
+
FATAL = 2
|
9
|
+
|
10
|
+
def run
|
11
|
+
exit_code = parse_options
|
12
|
+
return exit_code if exit_code
|
13
|
+
|
14
|
+
Easytest.start
|
15
|
+
setup
|
16
|
+
successful = Easytest.run
|
17
|
+
successful ? SUCCESS : FAILURE
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
5
21
|
|
6
22
|
attr_reader :argv
|
7
23
|
attr_reader :start_time
|
@@ -11,18 +27,72 @@ module Easytest
|
|
11
27
|
@start_time = Time.now
|
12
28
|
end
|
13
29
|
|
14
|
-
def
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
30
|
+
def parse_options
|
31
|
+
options = {}
|
32
|
+
|
33
|
+
parser = OptionParser.new do |p|
|
34
|
+
p.program_name = "easytest"
|
35
|
+
p.version = "#{p.program_name} #{Easytest::VERSION}"
|
36
|
+
|
37
|
+
p.on "--help" do
|
38
|
+
options[:help] = true
|
39
|
+
end
|
40
|
+
|
41
|
+
p.on "--version" do
|
42
|
+
options[:version] = true
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
begin
|
47
|
+
parser.parse!(argv)
|
48
|
+
|
49
|
+
if options[:help]
|
50
|
+
puts help(parser)
|
51
|
+
return SUCCESS
|
52
|
+
end
|
53
|
+
|
54
|
+
if options[:version]
|
55
|
+
puts parser.version
|
56
|
+
return SUCCESS
|
57
|
+
end
|
58
|
+
|
59
|
+
nil
|
60
|
+
rescue OptionParser::ParseError => error
|
61
|
+
$stderr.puts Rainbow(error.message).red
|
62
|
+
FATAL
|
63
|
+
end
|
19
64
|
end
|
20
65
|
|
21
|
-
|
66
|
+
def help(parser)
|
67
|
+
<<~MSG
|
68
|
+
#{Rainbow("USAGE").bright}
|
69
|
+
#{parser.program_name} [options] [...<file, directory, or pattern>]
|
70
|
+
|
71
|
+
#{Rainbow("OPTIONS").bright}
|
72
|
+
--help Show help
|
73
|
+
--version Show version
|
74
|
+
|
75
|
+
#{Rainbow("EXAMPLES").bright}
|
76
|
+
# Run all tests (test/**/*_test.rb)
|
77
|
+
$ easytest
|
78
|
+
|
79
|
+
# Run only test files
|
80
|
+
$ easytest test/example_test.rb
|
81
|
+
|
82
|
+
# Run only test files in specified directories
|
83
|
+
$ easytest test/example
|
84
|
+
|
85
|
+
# Run only test files that matches specified patterns
|
86
|
+
$ easytest example
|
87
|
+
MSG
|
88
|
+
end
|
22
89
|
|
23
90
|
def setup
|
24
91
|
Dir.glob(Easytest.test_files_location)
|
25
|
-
.
|
92
|
+
.map { |file| File.absolute_path(file) }
|
93
|
+
.filter do |file|
|
94
|
+
argv.empty? || argv.any? { |pattern| file.include?(pattern) }
|
95
|
+
end
|
26
96
|
.each { |test_file| load test_file }
|
27
97
|
end
|
28
98
|
end
|
data/lib/easytest/expectation.rb
CHANGED
@@ -1,16 +1,5 @@
|
|
1
1
|
module Easytest
|
2
2
|
class Expectation
|
3
|
-
attr_reader :actual
|
4
|
-
attr_reader :block
|
5
|
-
attr_reader :negate
|
6
|
-
alias negate? negate
|
7
|
-
|
8
|
-
def initialize(actual, negate: false, &block)
|
9
|
-
@actual = actual
|
10
|
-
@block = block
|
11
|
-
@negate = negate
|
12
|
-
end
|
13
|
-
|
14
3
|
def not
|
15
4
|
self.class.new(actual, negate: true, &block)
|
16
5
|
end
|
@@ -48,11 +37,12 @@ module Easytest
|
|
48
37
|
Matcher::InstanceOf.new(actual: actual, expected: expected, negate: negate).match!
|
49
38
|
end
|
50
39
|
|
51
|
-
def to_raise(
|
40
|
+
def to_raise(expected)
|
52
41
|
raise FatalError, "`to_raise` requires a block like `expect { ... }.to_raise`" unless block
|
53
42
|
raise FatalError, "`not.to_raise` can cause a false positive, so use `to_not_raise` instead" if negate?
|
43
|
+
raise FatalError, "`to_raise` requires a Class, String, or Regexp" unless [Class, String, Regexp].any? { expected.is_a? _1 }
|
54
44
|
|
55
|
-
Matcher::Raise.new(actual: block, expected:
|
45
|
+
Matcher::Raise.new(actual: block, expected: expected, negate: negate).match!
|
56
46
|
end
|
57
47
|
|
58
48
|
def to_not_raise
|
@@ -60,5 +50,18 @@ module Easytest
|
|
60
50
|
|
61
51
|
Matcher::NotRaise.new(actual: block).match!
|
62
52
|
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
attr_reader :actual
|
57
|
+
attr_reader :block
|
58
|
+
attr_reader :negate
|
59
|
+
alias negate? negate
|
60
|
+
|
61
|
+
def initialize(actual, negate: false, &block)
|
62
|
+
@actual = actual
|
63
|
+
@block = block
|
64
|
+
@negate = negate
|
65
|
+
end
|
63
66
|
end
|
64
67
|
end
|
data/lib/easytest/runner.rb
CHANGED
@@ -39,10 +39,12 @@ module Easytest
|
|
39
39
|
end
|
40
40
|
|
41
41
|
if no_tests?
|
42
|
-
puts
|
43
|
-
|
44
|
-
|
45
|
-
|
42
|
+
$stderr.puts <<~MSG
|
43
|
+
#{Rainbow("Oops. No tests found!").red.bright}
|
44
|
+
|
45
|
+
#{Rainbow("Put `#{Easytest.test_files_location}` files to include at least one test case.").red}
|
46
|
+
#{Rainbow("Or specify a pattern that matches an existing test file.").red}
|
47
|
+
MSG
|
46
48
|
false
|
47
49
|
else
|
48
50
|
puts ""
|
data/lib/easytest/version.rb
CHANGED
data/lib/easytest.rb
CHANGED
data/sig/easytest.rbs
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
module Easytest
|
2
|
+
VERSION: String
|
3
|
+
|
4
|
+
module DSL
|
5
|
+
end
|
6
|
+
|
7
|
+
class Expectation
|
8
|
+
def not: () -> instance
|
9
|
+
|
10
|
+
def to_eq: (untyped expected) -> void
|
11
|
+
alias to_equal to_eq
|
12
|
+
|
13
|
+
def to_be: (untyped expected) -> untyped
|
14
|
+
|
15
|
+
def to_be_nil: () -> void
|
16
|
+
|
17
|
+
def to_be_a: (Class expected) -> void
|
18
|
+
def to_be_kind_of: (Class expected) -> void
|
19
|
+
def to_be_instance_of: (Class expected) -> void
|
20
|
+
|
21
|
+
def to_be_false: () -> void
|
22
|
+
def to_be_true: () -> void
|
23
|
+
|
24
|
+
def to_raise: ((Class | String | Regexp) expected) -> void
|
25
|
+
def to_not_raise: () -> void
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
module Kernel
|
30
|
+
def expect: (untyped actual) -> Easytest::Expectation
|
31
|
+
| { () -> void } -> Easytest::Expectation
|
32
|
+
end
|
33
|
+
|
34
|
+
# polyfill
|
35
|
+
class Object
|
36
|
+
def using: (Module target) -> void
|
37
|
+
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.3.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-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rainbow
|
@@ -57,6 +57,7 @@ files:
|
|
57
57
|
- lib/easytest/runner.rb
|
58
58
|
- lib/easytest/utils.rb
|
59
59
|
- lib/easytest/version.rb
|
60
|
+
- sig/easytest.rbs
|
60
61
|
homepage: https://github.com/ybiquitous/easytest
|
61
62
|
licenses:
|
62
63
|
- MIT
|