easytest 0.4.0 → 0.5.1

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: e87217a9622ad5c57a2b97d64fc8e0a6cf32c264b53901644740b4727363d1bf
4
- data.tar.gz: 5703988217fdf9bc1e0aad99c2c5609a6e159e80d546124f0108ba4414dc1638
3
+ metadata.gz: 8fe89003a399189c3dd7be356b251a1b1e153e235aa2bc4419553cec6c7f84e2
4
+ data.tar.gz: 4ad8a1cf831976b0d79bb433500737826f74baef0204b6ee203c23dce5b6d17c
5
5
  SHA512:
6
- metadata.gz: 98e353f726337a6d5b2b9aaad59a4bca8801f06885dc2e9f8f5c0dce6655e2d8e5ab178ede9f7d3b229e2e4f92b8896a5895454d211c8222570cf8e81ababea5
7
- data.tar.gz: 88eff8410c841dffd3457beb20a3f78aaba46347ce724a680d9420f0e7831ce37d1ddcef9233a29758049a8b5e336f183781dc572b89531cd7472276984e5bb5
6
+ metadata.gz: 4e2f0f400c9db1e4bd7b67dc8fbe48deb432d08ecf43c1698c7468f96120845d77d40a2a7d5c157a52d92ae5053d6492a9b25e3c96fd602cdf13294c0924f799
7
+ data.tar.gz: cdc76fce7cee5a8f12a1c8781c8aa3791a1f0d9e36aa6853187e7f32a9d49b50620bf8a7caa7a24c2033bcb83744f80108d9926dece7366466901f497bd4dac3
data/CHANGELOG.md CHANGED
@@ -2,6 +2,17 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ ## 0.5.1
6
+
7
+ - Add RDoc to RBS.
8
+ - Publish the official website.
9
+
10
+ ## 0.5.0
11
+
12
+ - **[Breaking]** Rename `to_not_raise` to `to_raise_nothing`.
13
+ - Add `to_match` matcher.
14
+ - Add `only` to run only any cases.
15
+
5
16
  ## 0.4.0
6
17
 
7
18
  - Add `skip` and `test` without block for todo.
data/README.md CHANGED
@@ -9,18 +9,22 @@ Easytest is a tiny testing framework for Ruby with a familiar DSL.
9
9
 
10
10
  ## Installation
11
11
 
12
- via Bundler:
12
+ Add this line to your `Gemfile` for Bundler:
13
13
 
14
- ```shell
15
- bundle add easytest
14
+ ```ruby
15
+ gem "easytest"
16
16
  ```
17
17
 
18
- via gem:
18
+ Or install it via `gem`:
19
19
 
20
20
  ```shell
21
21
  gem install easytest
22
22
  ```
23
23
 
24
+ ## Documentation
25
+
26
+ You can read more about Easytest on the [official website](https://ybiquitous.github.io/easytest/).
27
+
24
28
  ## Usage
25
29
 
26
30
  Here is a very easy example.
@@ -75,19 +79,32 @@ The test now passes! 🎉
75
79
 
76
80
  ### Skip
77
81
 
78
- If you want to skip a case, you can change `test` to `skip`:
82
+ If you want to skip any cases, you can change `test` to `skip`:
83
+
84
+ ```diff
85
+ - test "addition" do
86
+ + skip "addition" do
87
+ ```
88
+
89
+ Skipped cases will be reported as "skipped".
90
+
91
+ ### Only
92
+
93
+ If you want to run only any cases, you can use `test` to `only`:
79
94
 
80
95
  ```diff
81
- -test "addition" do
82
- +skip "addition" do
83
- expect(1 + 2).to_eq 2
84
- end
96
+ - test "addition" do
97
+ + only "addition" do
85
98
  ```
86
99
 
100
+ Only cases with `only` will be run, and other cases will be skipped.
101
+
87
102
  ### To-do
88
103
 
89
- If you want to write a to-do case, you can use `test` without a block:
104
+ If you want to write to-do cases, you can use `test` without a block:
90
105
 
91
106
  ```ruby
92
107
  test "addition"
93
108
  ```
109
+
110
+ 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 run
21
- if todo?
22
- return [:todo, Reporter.new(name).report_todo]
23
- end
24
+ def skip!
25
+ @skipped = true
26
+ end
24
27
 
25
- if skipped?
26
- return [:skipped, Reporter.new(name).report_skip]
27
- end
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
- raise FatalError, "`test` requires a name" if name.nil? || name.empty?
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
- raise FatalError, "`skip` requires a name" if name.nil? || name.empty?
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
@@ -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 `to_not_raise` instead" if negate?
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 to_not_raise
53
- raise FatalError, "`to_not_raise` requires a block like `expect { ... }.to_not_raise`" unless block
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::NotRaise.new(actual: block).match!
59
+ Matcher::RaiseNothing.new(actual: block).match!
56
60
  end
57
61
 
58
62
  private
@@ -0,0 +1,13 @@
1
+ module Easytest
2
+ module Matcher
3
+ class Match < Base
4
+ def match?
5
+ actual.match? expected
6
+ end
7
+
8
+ def message
9
+ "match"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,6 +1,6 @@
1
1
  module Easytest
2
2
  module Matcher
3
- class NotRaise < Base
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
- "not raise"
23
+ "raise nothing"
24
24
  end
25
25
  end
26
26
  end
@@ -17,13 +17,19 @@ module Easytest
17
17
  end
18
18
 
19
19
  def run
20
- cases_by_file = cases.group_by { |c| c.file }
21
- cases_by_file.each do |file, cases|
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
- cases.each do |c|
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
- list << "#{total_count} total #{Rainbow("(#{file_count} files)").dimgray}"
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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Easytest
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.1"
3
3
  end
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
@@ -1,30 +1,53 @@
1
+ # A easy testing framework.
1
2
  module Easytest
3
+ # The Easytest version.
2
4
  VERSION: String
3
5
 
6
+ # Define methods for the Easytest DSL.
4
7
  module DSL
5
8
  end
6
9
 
10
+ # Define methods for the Easytest DSL.
7
11
  class Expectation
12
+ # Negate an expectation.
8
13
  def not: () -> instance
9
14
 
15
+ # Expect to equal the given object.
10
16
  def to_eq: (untyped expected) -> void
11
17
  alias to_equal to_eq
12
18
 
19
+ # Expect to be the same as the given object.
13
20
  def to_be: (untyped expected) -> untyped
14
21
 
22
+ # Expect to be `nil`. Same as `to_be(nil)`.
15
23
  def to_be_nil: () -> void
16
24
 
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
-
25
+ # Expect to be `false`. Same as `to_be(false)`.
21
26
  def to_be_false: () -> void
27
+
28
+ # Expect to be `true`. Same as `to_be(true)`.
22
29
  def to_be_true: () -> void
23
30
 
31
+ # Expect to be an instance of the given class (module) or its subclasses.
32
+ def to_be_a: (Module expected) -> void
33
+
34
+ # Expect to be an instance of the given class (module) or its subclasses.
35
+ def to_be_kind_of: (Module expected) -> void
36
+
37
+ # Expect to be an instance of the given class (module).
38
+ def to_be_instance_of: (Module expected) -> void
39
+
40
+ # Expect to include the given object.
24
41
  def to_include: (untyped expected) -> void
25
42
 
43
+ # Expect to match the given object.
44
+ def to_match: (untyped expected) -> void
45
+
46
+ # Expect to raise the given exception or an exception with the given message.
26
47
  def to_raise: ((Class | String | Regexp) expected) -> void
27
- def to_not_raise: () -> void
48
+
49
+ # Expect to raise nothing.
50
+ def to_raise_nothing: () -> void
28
51
  end
29
52
  end
30
53
 
@@ -32,8 +55,13 @@ module Kernel
32
55
  # TODO: Can we avoid `RBS::DuplicatedMethodDefinitionError` "::Kernel#test has duplicated definitions"?
33
56
  # def test: (String name) ?{ () -> void } -> void
34
57
 
58
+ # Skip the given test case.
35
59
  def skip: (String name) { () -> void } -> void
36
60
 
61
+ # Run only the given test case.
62
+ def only: (String name) { () -> void } -> void
63
+
64
+ # Expect the given object or block to satisfy some criterion.
37
65
  def expect: (untyped actual) -> Easytest::Expectation
38
66
  | { () -> void } -> Easytest::Expectation
39
67
  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.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masafumi Koba
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-10-06 00:00:00.000000000 Z
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
@@ -67,7 +68,7 @@ metadata:
67
68
  source_code_uri: https://github.com/ybiquitous/easytest
68
69
  changelog_uri: https://github.com/ybiquitous/easytest/blob/main/CHANGELOG.md
69
70
  rubygems_mfa_required: 'true'
70
- post_install_message:
71
+ post_install_message:
71
72
  rdoc_options: []
72
73
  require_paths:
73
74
  - lib
@@ -83,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
84
  version: '0'
84
85
  requirements: []
85
86
  rubygems_version: 3.3.7
86
- signing_key:
87
+ signing_key:
87
88
  specification_version: 4
88
89
  summary: Easy testing for Ruby.
89
90
  test_files: []