You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Marten::Spec provides excellent test helpers (client, delivered_emails, DB flush, etc.) but is currently hard-wired to Crystal's built-in Spec framework. The lifecycle is registered in src/marten/spec.cr via:
This means Marten apps cannot currently be tested with alternative Crystal test frameworks such as minitest.cr or spectator without losing DB/client/email reset between tests — minitest.cr is a standalone runner with its own lifecycle (before_setup/after_teardown/Minitest.after_run) and does not trigger Crystal Spec's callbacks.
This came up while documenting Marten for Rails developers (see #357), where Minitest is one of two canonical Ruby test frameworks — readers naturally expect a Crystal Minitest port to "just work".
Proposal
Split Marten::Spec into two layers:
Marten::Testing::Lifecycle(new, framework-agnostic)
Pure module containing setup_databases, flush_databases, clear_client, clear_collected_emails, client, delivered_emails. No require "spec", no callback registration.
Marten::Spec(existing, becomes a thin Crystal Spec adapter)
Keeps the current public API by re-exporting from Marten::Testing::Lifecycle, and is the file that require "spec" plus registers the 6 hooks above. No breaking change for current users.
This unblocks community-maintained adapters such as marten-minitest or marten-spectator without forcing Marten to take on extra dependencies.
Open questions for maintainers
Scope: should the refactor land alone (option A), or should an official src/marten/minitest.cr adapter ship alongside it (option B)? Option A keeps Marten's dependency graph unchanged and lets adapters live in separate shards.
Naming: Marten::Testing::Lifecycle, Marten::Test, or another module path?
Backwards compatibility: confirm that the public API (Marten::Spec.client, Marten::Spec.delivered_emails, the Marten::Spec::Client type) must remain stable.
Happy to submit a PR for option A once direction is confirmed.
This discussion was converted from issue #360 on May 04, 2026 02:12.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Context
Marten::Specprovides excellent test helpers (client,delivered_emails, DB flush, etc.) but is currently hard-wired to Crystal's built-inSpecframework. The lifecycle is registered insrc/marten/spec.crvia:This means Marten apps cannot currently be tested with alternative Crystal test frameworks such as minitest.cr or spectator without losing DB/client/email reset between tests — minitest.cr is a standalone runner with its own lifecycle (
before_setup/after_teardown/Minitest.after_run) and does not trigger CrystalSpec's callbacks.This came up while documenting Marten for Rails developers (see #357), where Minitest is one of two canonical Ruby test frameworks — readers naturally expect a Crystal Minitest port to "just work".
Proposal
Split
Marten::Specinto two layers:Marten::Testing::Lifecycle(new, framework-agnostic)Pure module containing
setup_databases,flush_databases,clear_client,clear_collected_emails,client,delivered_emails. Norequire "spec", no callback registration.Marten::Spec(existing, becomes a thin Crystal Spec adapter)Keeps the current public API by re-exporting from
Marten::Testing::Lifecycle, and is the file thatrequire "spec"plus registers the 6 hooks above. No breaking change for current users.This unblocks community-maintained adapters such as
marten-minitestormarten-spectatorwithout forcing Marten to take on extra dependencies.Open questions for maintainers
src/marten/minitest.cradapter ship alongside it (option B)? Option A keeps Marten's dependency graph unchanged and lets adapters live in separate shards.Marten::Testing::Lifecycle,Marten::Test, or another module path?Marten::Spec.client,Marten::Spec.delivered_emails, theMarten::Spec::Clienttype) must remain stable.Happy to submit a PR for option A once direction is confirmed.
Beta Was this translation helpful? Give feedback.
All reactions