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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ea89da5a0f2aba7252ea69be567591284bfcc1f53aa089e4824eb54773881b0b
4
- data.tar.gz: b9bb01188ce657b918cdffe80cb962fd4e3c011fa9a4556b832d49eeed8fef5d
3
+ metadata.gz: 9c1fb5f44f3dd5d049cd6775120712a614f7016a20c7f87d771043642ceb7bb6
4
+ data.tar.gz: '04591bad578ad4351de07ab07467378663cea9e0de2d40930aea5d4a3d132bac'
5
5
  SHA512:
6
- metadata.gz: 6b1539eeef25d6343a411a05afbfcff6143d9f33798fb5f3d13dbf8f3d742ea79247ced5c5da1a994bc0d77b41787ec8c7477ed06b26664ef30987007291ad26
7
- data.tar.gz: c5e5ebe81739839785eab40d24a3d4e529d7c33f0d2ac5fd5cc20bf2984b65849d6b99f18b46848f6d17d362dfdc95fb16ae7d0f3403b77913a6b182b0f1fc9a
6
+ metadata.gz: 718b38f0a0fc35339bdaae214baf115de1ee8d4a94bb20d157f102af5caf08a763580e2946976504443e3b45211fc5d8776668b353c9a9c07e5ed9abddca03e3
7
+ data.tar.gz: 4784ee059e028d9d8a7c6ed23d864182e280ced00d56e502b87d31b032212bde623b50b66fed087583f0ee24eda939900915d8d25fe9081bdf33b020930b7423
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.3.0
6
+
7
+ - Add RBS support.
8
+ - Add CLI help.
9
+ - Fix CLI to aware absolute paths.
10
+
5
11
  ## 0.2.0
6
12
 
7
13
  - Add many matchers.
data/README.md CHANGED
@@ -1,10 +1,11 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/easytest.svg)](https://badge.fury.io/rb/easytest)
2
+ [![CI](https://github.com/ybiquitous/easytest/actions/workflows/ci.yml/badge.svg)](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
- $ bundle exec easytest
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
- $ bundle exec easytest
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
@@ -3,6 +3,6 @@
3
3
  $LOAD_PATH << File.expand_path("../lib", __dir__)
4
4
  $LOAD_PATH << File.join(Dir.pwd, "test")
5
5
 
6
- require "easytest"
6
+ require "easytest/cli"
7
7
 
8
8
  exit Easytest::CLI.new(ARGV).run
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 run
15
- Easytest.start
16
- setup
17
- successful = Easytest.run
18
- successful ? SUCCESS : FAILURE
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
- private
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
- .filter { |file| argv.empty? || argv.any? { |pattern| file.include?(pattern) } }
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
@@ -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(exception_class)
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: exception_class, negate: negate).match!
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
@@ -30,7 +30,7 @@ module Easytest
30
30
  when Regexp
31
31
  actual.message.match? expected
32
32
  else
33
- raise TypeError.new "Class, String, or Regexp is allowed: #{expected}"
33
+ false
34
34
  end
35
35
  end
36
36
  end
@@ -39,10 +39,12 @@ module Easytest
39
39
  end
40
40
 
41
41
  if no_tests?
42
- puts Rainbow("Oops. No tests found!").red.bright
43
- puts ""
44
- puts "Write `#{Easytest.test_files_location}` files to include at least one `test` block,"
45
- puts "or specify a matching pattern to the `easytest` command."
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 ""
@@ -1,3 +1,3 @@
1
1
  module Easytest
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/easytest.rb CHANGED
@@ -4,7 +4,6 @@ require "rainbow"
4
4
  require_relative "easytest/version"
5
5
 
6
6
  require_relative "easytest/case"
7
- require_relative "easytest/cli"
8
7
  require_relative "easytest/dsl"
9
8
  require_relative "easytest/errors"
10
9
  require_relative "easytest/expectation"
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.2.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-05 00:00:00.000000000 Z
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