megatest 0.5.0 → 0.6.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: b0be0dcf9dd26312cec897081522ae6ac404db5447b26d50286ccc8720422743
4
- data.tar.gz: 2580f85814d9469dfd1df3c8d3601c8b5ac89b4e4faaf706b4af47154d3c9bdb
3
+ metadata.gz: 10f2e6b7fd746d7e66164d84868f0314d06f403f649f5a985baaa8db9eb239c4
4
+ data.tar.gz: 9e6691bc050c0fd73647697e600f20c693d670c1f8982b779545e8d3140a9ef9
5
5
  SHA512:
6
- metadata.gz: ef25ab7ecc09133635d0ffaef659ce02574f01fd558f2437c187fd3f4f362b40cd13dfcb6d6ac455e0a1462b507dfb6e27efd74e72d18ed57e68f8c1434b25e2
7
- data.tar.gz: 68b8dc14b4869a5dea9d51f2c507287acb5bbcce709b1514c965f2b0cc9a0d8edd4da82a89b8e120427e63ece0c159a2f4f27d92362f1b25ded3f9cbdd05c402
6
+ metadata.gz: e03b691bdf5d28c09575c4c3c2d0995e067f3a7e88159f640d5d1dc0c92010470ec36c20bfb52c3cbf63b4edaf3d09afd24cc5799a5d8c9bf1a5dbd206ae3b86
7
+ data.tar.gz: b742c4c6d8656cf04ba801112bcf913e1224eef13f8256b5ef7c950deaf9c1a24958c7c294f76c477b01a1017adbf849358e5ff0dcea7761dc8b1c18468288f6
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.6.0] - 2025-01-17
4
+
5
+ - Allow defining setup and teardown with method names.
6
+ - Allow multiple `setup`, `around` and `teardown` blocks in the same test suite.
7
+
3
8
  ## [0.5.0] - 2025-01-17
4
9
 
5
10
  - Adds `megatest/autorun`
@@ -4,18 +4,6 @@
4
4
 
5
5
  module Megatest
6
6
  module Compat
7
- unless Enumerable.method_defined?(:filter_map) # RUBY_VERSION >= "2.7"
8
- module FilterMap
9
- refine Enumerable do
10
- def filter_map(&block)
11
- result = map(&block)
12
- result.compact!
13
- result
14
- end
15
- end
16
- end
17
- end
18
-
19
7
  unless Symbol.method_defined?(:start_with?) # RUBY_VERSION >= "2.7"
20
8
  module StartWith
21
9
  refine Symbol do
data/lib/megatest/dsl.rb CHANGED
@@ -136,8 +136,14 @@ module Megatest
136
136
  end
137
137
 
138
138
  # Registers a block to be invoked before every test cases.
139
- def setup(&block)
140
- ::Megatest.registry.suite(self).on_setup(block)
139
+ def setup(*methods, &block)
140
+ suite = ::Megatest.registry.suite(self)
141
+ methods.each do |m|
142
+ suite.on_setup(-> { send(m) })
143
+ end
144
+ if block
145
+ suite.on_setup(block)
146
+ end
141
147
  end
142
148
 
143
149
  # Registers a block to be invoked around every test cases.
@@ -157,8 +163,14 @@ module Megatest
157
163
 
158
164
  # Registers a block to be invoked after every test cases,
159
165
  # regardless of whether it passed or failed.
160
- def teardown(&block)
161
- ::Megatest.registry.suite(self).on_teardown(block)
166
+ def teardown(*methods, &block)
167
+ suite = ::Megatest.registry.suite(self)
168
+ methods.each do |m|
169
+ suite.on_teardown(-> { send(m) })
170
+ end
171
+ if block
172
+ suite.on_teardown(block)
173
+ end
162
174
  end
163
175
  end
164
176
  end
@@ -28,14 +28,14 @@ module Megatest
28
28
  using Compat::StartWith unless Symbol.method_defined?(:start_with?)
29
29
 
30
30
  class Suite
31
- attr_reader :setup_callback, :teardown_callback, :around_callback
31
+ attr_reader :setup_callbacks, :teardown_callbacks, :around_callbacks
32
32
 
33
33
  def initialize(registry)
34
34
  @registry = registry
35
35
  @tags = nil
36
- @setup_callback = nil
37
- @teardown_callback = nil
38
- @around_callback = nil
36
+ @setup_callbacks = []
37
+ @teardown_callbacks = []
38
+ @around_callbacks = []
39
39
  @current_context = nil
40
40
  @current_tags = nil
41
41
  end
@@ -87,26 +87,21 @@ module Megatest
87
87
  end
88
88
 
89
89
  def on_setup(block)
90
- raise Error, "The setup block is already defined" if @setup_callback
91
90
  raise Error, "setup blocks can't be defined in context blocks" if @current_context
92
91
 
93
- @setup_callback = block
92
+ @setup_callbacks.unshift(block)
94
93
  end
95
94
 
96
95
  def on_around(block)
97
- raise Error, "The around block is already defined" if @around_callback
98
96
  raise Error, "around blocks can't be defined in context blocks" if @current_context
99
97
 
100
- @around_callback = block
98
+ @around_callbacks << block
101
99
  end
102
100
 
103
101
  def on_teardown(block)
104
- if @teardown_callback
105
- raise Error, "The teardown block was already defined as #{@teardown_callback}"
106
- end
107
102
  raise Error, "teardown blocks can't be defined in context blocks" if @current_context
108
103
 
109
- @teardown_callback = block
104
+ @teardown_callbacks << block
110
105
  end
111
106
  end
112
107
 
@@ -370,21 +365,19 @@ module Megatest
370
365
  cmp || 0
371
366
  end
372
367
 
373
- def each_setup_callback
368
+ def each_setup_callback(&block)
374
369
  @test_suite.ancestors.reverse_each do |test_suite|
375
- yield test_suite.setup_callback if test_suite.setup_callback
370
+ test_suite.setup_callbacks.each(&block)
376
371
  end
377
372
  end
378
373
 
379
- using Compat::FilterMap unless Enumerable.method_defined?(:filter_map)
380
-
381
374
  def around_callbacks
382
- @test_suite.ancestors.filter_map(&:around_callback)
375
+ @test_suite.ancestors.flat_map(&:around_callbacks)
383
376
  end
384
377
 
385
- def each_teardown_callback
378
+ def each_teardown_callback(&block)
386
379
  @test_suite.ancestors.each do |test_suite|
387
- yield test_suite.teardown_callback if test_suite.teardown_callback
380
+ test_suite.teardown_callbacks.each(&block)
388
381
  end
389
382
  end
390
383
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Megatest
4
- VERSION = "0.5.0"
4
+ VERSION = "0.6.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: megatest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean Boussier