smartest 0.3.3.alpha4 → 0.5.0.alpha1

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: 75e3f0538afd3f490c37121ae4eee497a4691f35926ff50201e035acb64d2314
4
- data.tar.gz: 53fea3bdbbb788167d13c6a7b6c18a9258de42b971c4f2a1f36906176f75813a
3
+ metadata.gz: 967084d2b9e35152ef0f03e3ac524e92378e23b946dd919328d95f751553451a
4
+ data.tar.gz: b4df54be2c78b6a7341cedf0dc2b95bec0e52f6f51734fe3769bf005bfdfff00
5
5
  SHA512:
6
- metadata.gz: ba646897bc5994e7caf30fc9b1127a1ad72f2545a4ed8734820c5eeeca3e5e1e7e0302394b38916fbc9d9c153dccfdae96496093dce1f23af172fa74a01cbd75
7
- data.tar.gz: 5c12f0c3532da8eb44c3e832d28e479b1f8a54f5797a4c67c61c865bbbedf31e2225fe441c1f433d8de6ce3b2246c374de998d2aae9b2cfa8a7ea63f043ed949
6
+ metadata.gz: c0c2f5f9a2d79ae06e2391a8b1a8138337f175f0a36b25f3969d5cab2e1f05bf90dfd85c734fdf581fdf15c7110338d3e6af7f52550259d24b5650dd0eb553ce
7
+ data.tar.gz: 67b85ab5f35b8d9844efacad366b549abe2fab44505266e60f0e10c3495e36b6009581508da0e647cafddb5c03bc13c95884a709565ce26cb7ccc29e3b37d09e
data/CHANGELOG.md CHANGED
@@ -1,19 +1,24 @@
1
1
  # Changelog
2
2
 
3
- ## 0.1.0 - Unreleased
4
-
5
- - Add the initial Smartest test runner.
6
- - Support top-level `test` definitions.
7
- - Support class-based fixtures through `Smartest::Fixture`.
8
- - Support required keyword-argument fixture injection and fixture dependencies.
9
- - Support per-test fixture caching and cleanup.
10
- - Support suite-scoped fixtures through `suite_fixture`.
11
- - Support `eq`, `include`, `start_with`, `end_with`, `be_nil`, `raise_error`, and `change` matchers.
12
- - Support custom matcher modules through `use_matcher`.
13
- - Generate an opt-in `PredicateMatcher` custom matcher for `be_<predicate>` calls.
14
- - Add the `smartest` CLI.
15
- - Add `--help` and `--version` CLI options.
16
- - Use `smartest/**/*_test.rb` as the default CLI glob so Smartest can coexist with Minitest files under `test/`.
17
- - Add gem packaging metadata and release tasks.
18
- - Add Docusaurus documentation.
19
- - Add `smartest --init-browser` with a Playwright init scaffold, fixture setup, matcher generation, and dependency installation.
3
+ ## 0.5.0 - Unreleased
4
+
5
+ ### Breaking Changes
6
+
7
+ - Rename the fixture teardown registration API from `cleanup` to
8
+ `on_teardown`. The old `cleanup` method is no longer available.
9
+ - Rename teardown failure output from cleanup terminology to teardown
10
+ terminology.
11
+
12
+ ## 0.4.0
13
+
14
+ ### New Features
15
+
16
+ - Add fixture-scoped method stub helpers: `simple_stub_any_instance_of` and
17
+ `simple_stub`.
18
+ - Add `with_stub_const` for block-scoped constant stubbing in test bodies,
19
+ `around_test`, and `around_suite`.
20
+ - Support Ruby 2.7 and newer.
21
+
22
+ ## 0.1.0 - 0.3.2
23
+
24
+ - Initial release.
data/DEVELOPMENT.md CHANGED
@@ -13,7 +13,7 @@ Smartest is a Ruby test runner focused on:
13
13
  - top-level test definitions
14
14
  - class-based fixtures
15
15
  - explicit keyword-argument fixture dependencies
16
- - optional cleanup for fixtures that need teardown
16
+ - optional teardown for fixtures that need teardown
17
17
  - suite-scoped fixtures for expensive shared resources
18
18
  - a small internal architecture that is easy to reason about
19
19
 
@@ -224,7 +224,7 @@ Responsibilities:
224
224
  - class-level `suite_fixture` DSL for suite-scoped fixtures
225
225
  - stores fixture definitions
226
226
  - supports inheritance
227
- - exposes `cleanup` to fixture blocks
227
+ - exposes `on_teardown` to fixture blocks
228
228
  - optionally delegates helper methods to `ExecutionContext`
229
229
  - does not delegate `skip` or `pending` to fixture blocks
230
230
 
@@ -293,8 +293,8 @@ Responsibilities:
293
293
  - find fixture definitions
294
294
  - resolve fixture dependencies
295
295
  - cache fixture values for its scope
296
- - collect cleanup blocks
297
- - run cleanup blocks in reverse order
296
+ - collect teardown blocks
297
+ - run teardown blocks in reverse order
298
298
  - detect duplicate fixture names
299
299
  - detect circular dependencies
300
300
 
@@ -332,9 +332,9 @@ Responsibilities:
332
332
  - create a fresh `FixtureSet` per test
333
333
  - resolve test keyword fixtures
334
334
  - run test body
335
- - run cleanup in `ensure`
335
+ - run teardown in `ensure`
336
336
  - track skipped and pending test state
337
- - run suite fixture cleanup after all tests
337
+ - run suite fixture teardown after all tests
338
338
  - produce `TestResult`
339
339
  - notify reporter
340
340
 
@@ -373,7 +373,7 @@ rescue Exception => error
373
373
  TestResult.failed(test_case, error)
374
374
  end
375
375
  ensure
376
- fixture_set&.run_cleanups
376
+ fixture_set&.run_teardowns
377
377
  end
378
378
  ```
379
379
 
@@ -424,7 +424,7 @@ end
424
424
 
425
425
  fixture :server do
426
426
  server = TestServer.start
427
- cleanup { server.stop }
427
+ on_teardown { server.stop }
428
428
  server
429
429
  end
430
430
 
@@ -456,12 +456,12 @@ resolve :logged_in_client
456
456
  evaluate logged_in_client
457
457
  cache logged_in_client
458
458
  run test body
459
- run cleanup stack
459
+ run teardown stack
460
460
  ```
461
461
 
462
- ## Cleanup behavior
462
+ ## Teardown behavior
463
463
 
464
- Fixture cleanup is optional.
464
+ Fixture teardown is optional.
465
465
 
466
466
  Fixture without teardown:
467
467
 
@@ -476,33 +476,33 @@ Fixture with teardown:
476
476
  ```ruby
477
477
  fixture :server do
478
478
  server = TestServer.start
479
- cleanup { server.stop }
479
+ on_teardown { server.stop }
480
480
 
481
481
  server.wait_until_ready!
482
482
  server
483
483
  end
484
484
  ```
485
485
 
486
- `cleanup` should register a block on the current fixture set. Regular fixture
487
- cleanups run after the test. `suite_fixture` cleanups run after all tests.
486
+ `on_teardown` should register a block on the current fixture set. Regular fixture
487
+ teardown blocks run after the test. `suite_fixture` teardown blocks run after all tests.
488
488
 
489
- Cleanup blocks must run:
489
+ Teardown blocks must run:
490
490
 
491
491
  - after the test body
492
492
  - after the suite for suite-scoped fixtures
493
493
  - after failed tests
494
- - after fixture setup errors, if cleanup was already registered
494
+ - after fixture setup errors, if teardown was already registered
495
495
  - in reverse registration order
496
496
 
497
497
  Implementation:
498
498
 
499
499
  ```ruby
500
- def add_cleanup(&block)
501
- @cleanups << block
500
+ def add_teardown(&block)
501
+ @teardowns << block
502
502
  end
503
503
 
504
- def run_cleanups
505
- @cleanups.reverse_each(&:call)
504
+ def run_teardowns
505
+ @teardowns.reverse_each(&:call)
506
506
  end
507
507
  ```
508
508
 
@@ -621,17 +621,17 @@ A practical approach:
621
621
  - recursive fixture resolution
622
622
  - per-test caching
623
623
 
624
- ### Phase 4: Cleanup
624
+ ### Phase 4: Teardown
625
625
 
626
- - `cleanup { ... }`
627
- - cleanup stack on `FixtureSet`
628
- - cleanup in `ensure`
626
+ - `on_teardown { ... }`
627
+ - teardown stack on `FixtureSet`
628
+ - teardown in `ensure`
629
629
 
630
630
  ### Phase 5: Suite-scoped fixtures
631
631
 
632
632
  - `suite_fixture :name do ... end`
633
633
  - suite-level fixture cache
634
- - suite cleanup after all tests
634
+ - suite teardown after all tests
635
635
  - test fixtures may depend on suite fixtures
636
636
  - suite fixtures may not depend on test fixtures
637
637
 
@@ -648,6 +648,10 @@ A practical approach:
648
648
  - `exe/smartest`
649
649
  - load files from ARGV
650
650
  - default glob `smartest/**/*_test.rb`
651
+ - print scaffold guidance and exit 1 when the default run is requested before
652
+ `smartest/` exists
653
+ - expand directory path arguments such as `smartest/` to `**/*_test.rb` files
654
+ under that directory
651
655
  - support `path:line` and `path:start-end` filters that run tests whose `test`
652
656
  blocks contain or intersect the lines
653
657
  - add `smartest/` to the load path before loading tests
@@ -658,14 +662,14 @@ A practical approach:
658
662
 
659
663
  - `around_suite do |suite| ... end`
660
664
  - run hooks around the full suite body
661
- - include suite fixture cleanup inside the wrapped body
665
+ - include suite fixture teardown inside the wrapped body
662
666
  - report hook failures as suite failures
663
667
 
664
668
  ### Phase 8: Test hooks
665
669
 
666
670
  - `around_test do |test| ... end`
667
671
  - snapshot file-local hooks when each test is registered
668
- - run hooks around fixture setup, test body, and fixture cleanup
672
+ - run hooks around fixture setup, test body, and fixture teardown
669
673
  - expose `use_fixture` and `use_matcher` only inside hook contexts
670
674
  - make `around_test` registered from `around_suite` suite-wide
671
675
 
@@ -716,7 +720,7 @@ end
716
720
  ```
717
721
 
718
722
  ```ruby
719
- cleanup { ... }
723
+ on_teardown { ... }
720
724
  ```
721
725
 
722
726
  ```ruby
@@ -839,6 +843,22 @@ Before releasing:
839
843
  - run a sample project against the installed gem
840
844
  - push the release tag
841
845
 
846
+ ### Changelog updates
847
+
848
+ Update `CHANGELOG.md` from the actual diff between released versions, not from
849
+ commit messages. For an already tagged release, compare the previous release tag
850
+ to the release tag and inspect the code/docs changes, for example:
851
+
852
+ ```bash
853
+ git diff --stat 0.4.0..0.5.0
854
+ git diff 0.4.0..0.5.0
855
+ ```
856
+
857
+ Before the new tag exists, compare the latest release tag to the release branch
858
+ or working tree and inspect the same kind of diff. Only document breaking
859
+ changes and notable new features. Do not copy every commit message or list
860
+ documentation-only maintenance changes unless they materially affect users.
861
+
842
862
  Example commands:
843
863
 
844
864
  ```bash
data/README.md CHANGED
@@ -1,7 +1,10 @@
1
- # Smartest introduces Pytest-style fixtures for Ruby
1
+ # Smartest
2
2
 
3
- Smartest is a small Ruby test runner that brings pytest-style fixture
4
- injection, explicit fixture dependencies, and fixture cleanup to Ruby tests.
3
+ [![Gem Version](https://badge.fury.io/rb/smartest.svg)](https://rubygems.org/gems/smartest)
4
+
5
+ Smartest is a Ruby test runner that brings pytest-style fixtures to Ruby,
6
+ with explicit fixture dependencies, automatic teardown, and Playwright-friendly
7
+ browser testing.
5
8
 
6
9
  Tests request fixtures with Ruby keyword arguments. Fixtures define their own
7
10
  dependencies the same way:
@@ -10,7 +13,7 @@ dependencies the same way:
10
13
  class WebFixture < Smartest::Fixture
11
14
  fixture :server do
12
15
  server = TestServer.start
13
- cleanup { server.stop }
16
+ on_teardown { server.stop }
14
17
  server
15
18
  end
16
19
 
@@ -45,7 +48,7 @@ idea: tests should explicitly declare their dependencies.
45
48
  RSpec `let` is useful when examples need lazy helper methods. Minitest `setup`
46
49
  is simple for xUnit-style setup. Rails fixtures and FactoryBot are great for
47
50
  test data. Smartest is aimed at tests where setup resources, dependency graphs,
48
- and cleanup should be visible in the test signature and fixture definitions.
51
+ and teardown should be visible in the test signature and fixture definitions.
49
52
 
50
53
  ```ruby
51
54
  test("GET /me") do |logged_in_client:|
@@ -67,6 +70,9 @@ end
67
70
 
68
71
  Smartest requires Ruby 2.7 or newer.
69
72
 
73
+ Smartest is published as the `smartest` RubyGem:
74
+ [Smartest on RubyGems](https://rubygems.org/gems/smartest).
75
+
70
76
  Add this line to your application's Gemfile:
71
77
 
72
78
  ```ruby
@@ -123,12 +129,34 @@ bundle exec smartest
123
129
  By default, Smartest loads `smartest/**/*_test.rb`, so a separate `test/`
124
130
  directory can remain available for Minitest.
125
131
 
132
+ If `smartest/` does not exist yet and no explicit paths are passed, Smartest
133
+ prints scaffold commands instead of attempting a default test run:
134
+
135
+ ```text
136
+ No smartest/ directory found.
137
+
138
+ To create a Smartest test scaffold:
139
+ bundle exec smartest --init
140
+
141
+ For browser tests:
142
+ bundle exec smartest --init-browser
143
+
144
+ See all commands:
145
+ bundle exec smartest --help
146
+ ```
147
+
126
148
  You can also pass explicit paths:
127
149
 
128
150
  ```bash
151
+ bundle exec smartest smartest/suite1/
129
152
  bundle exec smartest smartest/**/*_test.rb
153
+ bundle exec smartest smartest/user_test.rb
130
154
  ```
131
155
 
156
+ A directory path is expanded to `**/*_test.rb` under that directory, so
157
+ `bundle exec smartest smartest/suite1/` is equivalent to
158
+ `bundle exec smartest smartest/suite1/**/*_test.rb`.
159
+
132
160
  To run tests by line number, append `:line` or `:start-end` to the file path.
133
161
  Smartest runs tests whose `test` blocks contain or intersect the selected lines:
134
162
 
@@ -152,6 +180,18 @@ bundle exec smartest --help
152
180
  bundle exec smartest --version
153
181
  ```
154
182
 
183
+ The help output lists common commands, including default runs, directory runs,
184
+ single-file runs, line-filtered runs, and scaffold generation:
185
+
186
+ ```bash
187
+ bundle exec smartest
188
+ bundle exec smartest smartest/suite1/
189
+ bundle exec smartest smartest/user_test.rb
190
+ bundle exec smartest smartest/user_test.rb:12
191
+ bundle exec smartest --init
192
+ bundle exec smartest --init-browser
193
+ ```
194
+
155
195
  Output resembles:
156
196
 
157
197
  ```text
@@ -443,7 +483,7 @@ released after the full suite finishes:
443
483
  class BrowserFixture < Smartest::Fixture
444
484
  suite_fixture :browser do
445
485
  browser = Browser.launch
446
- cleanup { browser.close }
486
+ on_teardown { browser.close }
447
487
  browser
448
488
  end
449
489
 
@@ -454,7 +494,7 @@ end
454
494
  ```
455
495
 
456
496
  Suite fixtures are lazy: setup runs the first time a test requests the fixture,
457
- and cleanup runs once after all tests finish. Test-scoped fixtures can depend on
497
+ and teardown runs once after all tests finish. Test-scoped fixtures can depend on
458
498
  suite fixtures, but suite fixtures cannot depend on test-scoped fixtures.
459
499
 
460
500
  ## Suite hooks
@@ -470,8 +510,8 @@ end
470
510
  ```
471
511
 
472
512
  The hook receives a run target and must call `suite.run` exactly once. The block
473
- wraps every test, test-scoped fixture setup and cleanup, suite fixture setup, and
474
- suite fixture cleanup.
513
+ wraps every test, test-scoped fixture setup and teardown, suite fixture setup, and
514
+ suite fixture teardown.
475
515
 
476
516
  Fixture and matcher registrations made before `suite.run` are applied to that
477
517
  run:
@@ -512,7 +552,7 @@ end
512
552
  ```
513
553
 
514
554
  The hook receives a run target and must call `test.run` exactly once. It wraps
515
- fixture setup, the test body, and fixture cleanup.
555
+ fixture setup, the test body, and fixture teardown.
516
556
 
517
557
  `around_test` is file-scoped when it is written directly in a test file. Smartest
518
558
  copies the current file's `around_test` hooks when each `test` is registered, so
@@ -546,20 +586,20 @@ end
546
586
 
547
587
  Fixture classes registered from `around_test` must define only test-scoped
548
588
  fixtures. If a class defines `suite_fixture`, register it from `around_suite`
549
- instead so its cache and cleanup belong to the suite lifecycle.
589
+ instead so its cache and teardown belong to the suite lifecycle.
550
590
 
551
591
  `use_fixture` and `use_matcher` are only available inside `around_suite` or
552
592
  `around_test` blocks. They are not top-level DSL methods.
553
593
 
554
594
  ## Fixtures with teardown
555
595
 
556
- Not every fixture needs teardown. For fixtures that do, use `cleanup`.
596
+ Not every fixture needs teardown. For fixtures that do, use `on_teardown`.
557
597
 
558
598
  ```ruby
559
599
  class WebFixture < Smartest::Fixture
560
600
  fixture :server do
561
601
  server = TestServer.start
562
- cleanup { server.stop }
602
+ on_teardown { server.stop }
563
603
 
564
604
  server.wait_until_ready!
565
605
  server
@@ -571,8 +611,8 @@ class WebFixture < Smartest::Fixture
571
611
  end
572
612
  ```
573
613
 
574
- `cleanup` blocks run after the fixture's scope finishes. For regular fixtures
575
- that means after the test. For `suite_fixture`, cleanup runs after the full
614
+ `on_teardown` blocks run after the fixture's scope finishes. For regular fixtures
615
+ that means after the test. For `suite_fixture`, teardown runs after the full
576
616
  suite.
577
617
 
578
618
  They are executed in reverse order of registration.
@@ -580,7 +620,7 @@ They are executed in reverse order of registration.
580
620
  ```ruby
581
621
  fixture :temp_dir do
582
622
  dir = Dir.mktmpdir
583
- cleanup { FileUtils.rm_rf(dir) }
623
+ on_teardown { FileUtils.rm_rf(dir) }
584
624
 
585
625
  dir
586
626
  end
@@ -591,19 +631,19 @@ Recommended pattern:
591
631
  ```ruby
592
632
  fixture :server do
593
633
  server = TestServer.start
594
- cleanup { server.stop }
634
+ on_teardown { server.stop }
595
635
 
596
636
  server.wait_until_ready!
597
637
  server
598
638
  end
599
639
  ```
600
640
 
601
- Register cleanup immediately after acquiring the resource, before later setup steps that may fail.
641
+ Register teardown immediately after acquiring the resource, before later setup steps that may fail.
602
642
 
603
643
  ## Stubs
604
644
 
605
645
  Use simple stub helpers when a fixture needs to temporarily replace a Ruby
606
- method and reset it during cleanup:
646
+ method and reset it during teardown:
607
647
 
608
648
  ```ruby
609
649
  class PaymentFixture < Smartest::Fixture
@@ -639,13 +679,13 @@ end
639
679
  Use `simple_stub(Time, :now) { fixed_time }` for singleton methods such as class
640
680
  methods.
641
681
 
642
- Use `simple_stub_const("AppConfig::PAYMENT_PROVIDER", "fake") { ... }` for
682
+ Use `with_stub_const("AppConfig::PAYMENT_PROVIDER", "fake") { ... }` for
643
683
  constants in test bodies, `around_test`, or `around_suite`. Constant stubs are
644
684
  process-global; avoid concurrent tests that stub the same constant.
645
685
 
646
686
  The method stub helpers call `Smartest::SimpleStub` internally, apply the stub,
647
- register `cleanup { stub.reset }`, and return the stub object.
648
- `simple_stub_const` records the previous constant value, replaces it, yields to
687
+ register `on_teardown { stub.reset }`, and return the stub object.
688
+ `with_stub_const` records the previous constant value, replaces it, yields to
649
689
  the block, and restores or removes the constant with `ensure`.
650
690
 
651
691
  `Smartest::SimpleStub#apply` and `#reset` are idempotent in the current Fiber.
@@ -661,7 +701,7 @@ the current Fiber, and `reset!` raises
661
701
  class WebFixture < Smartest::Fixture
662
702
  fixture :server do
663
703
  server = TestServer.start
664
- cleanup { server.stop }
704
+ on_teardown { server.stop }
665
705
 
666
706
  server.wait_until_ready!
667
707
  server
@@ -721,7 +761,7 @@ client setup
721
761
  user setup
722
762
  logged_in_client setup
723
763
  test body
724
- server cleanup
764
+ server teardown
725
765
  ```
726
766
 
727
767
  ## Registering fixture classes
@@ -750,15 +790,15 @@ Fixture names must be unique across registered fixture classes.
750
790
 
751
791
  If two fixture classes define the same fixture name, Smartest raises an error.
752
792
 
753
- ## Suite hooks and fixture cleanup
793
+ ## Suite hooks and fixture teardown
754
794
 
755
- Suite hooks are separate from fixture cleanup. Use fixture cleanup for
795
+ Suite hooks are separate from fixture teardown. Use fixture teardown for
756
796
  resource-specific teardown:
757
797
 
758
798
  ```ruby
759
799
  fixture :server do
760
800
  server = TestServer.start
761
- cleanup { server.stop }
801
+ on_teardown { server.stop }
762
802
  server
763
803
  end
764
804
  ```
@@ -815,7 +855,7 @@ Example:
815
855
  class WebFixture < Smartest::Fixture
816
856
  fixture :server do
817
857
  server = TestServer.start
818
- cleanup { server.stop }
858
+ on_teardown { server.stop }
819
859
  server
820
860
  end
821
861
 
@@ -878,7 +918,7 @@ Smartest currently focuses on a small runner API:
878
918
  - class-based fixtures
879
919
  - keyword-argument fixture injection
880
920
  - fixture dependencies through keyword arguments
881
- - fixture cleanup
921
+ - fixture teardown
882
922
  - suite-scoped fixtures through `suite_fixture`
883
923
  - fixture-scoped method stubs and block-scoped constant stubs
884
924
  - suite hooks with `around_suite`