Module: Acta::Testing
- Defined in:
- lib/acta/testing.rb,
lib/acta/testing/dsl.rb
Defined Under Namespace
Modules: DSL, ProjectionWritesHelpers
Constant Summary collapse
- DEFAULT_ACTOR_ATTRIBUTES =
{ type: "system", id: "rspec", source: "test" }.freeze
Class Method Summary collapse
-
.default_actor!(config, **attributes) ⇒ Object
Configures RSpec to set Acta::Current.actor before every example, so specs that emit (directly or via a command) don’t trip Acta::MissingActor.
-
.projection_writes_helper!(config) ⇒ Object
Includes ‘with_projection_writes` into every RSpec example.
-
.test_mode ⇒ Object
Runs the given block with ActiveJob’s :inline adapter, so async reactors run synchronously in the caller’s thread.
Class Method Details
.default_actor!(config, **attributes) ⇒ Object
Configures RSpec to set Acta::Current.actor before every example, so specs that emit (directly or via a command) don’t trip Acta::MissingActor. Resets Acta::Current after each example so state doesn’t leak.
# spec/rails_helper.rb
require "acta/testing"
RSpec.configure do |config|
Acta::Testing.default_actor!(config)
end
Override the default actor’s attributes per project:
Acta::Testing.default_actor!(config, type: "user", id: "test-user-1", source: "spec")
Individual specs can still override Acta::Current.actor inline (or use Acta::Testing::DSL#with_actor for a scoped override).
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/acta/testing.rb', line 58 def default_actor!(config, **attributes) attrs = DEFAULT_ACTOR_ATTRIBUTES.merge(attributes) config.before(:each) do Acta::Current.actor = Acta::Actor.new(**attrs) end config.after(:each) do Acta::Current.reset end end |
.projection_writes_helper!(config) ⇒ Object
Includes ‘with_projection_writes` into every RSpec example. The helper forwards to `Acta::Projection.applying!`, so blocks under it pass the `acta_managed!` write guard. See ProjectionWritesHelpers.
# spec/rails_helper.rb
require "acta/testing"
RSpec.configure do |config|
Acta::Testing.projection_writes_helper!(config)
end
79 80 81 |
# File 'lib/acta/testing.rb', line 79 def projection_writes_helper!(config) config.include(ProjectionWritesHelpers) end |
.test_mode ⇒ Object
Runs the given block with ActiveJob’s :inline adapter, so async reactors run synchronously in the caller’s thread. Restores the original adapter when the block returns (or raises).
34 35 36 37 38 39 40 |
# File 'lib/acta/testing.rb', line 34 def test_mode original = ActiveJob::Base.queue_adapter ActiveJob::Base.queue_adapter = :inline yield ensure ActiveJob::Base.queue_adapter = original end |