Module: Plushie::Test::RSpec

Defined in:
lib/plushie/test/rspec.rb

Overview

RSpec integration for Plushie app testing.

Include this module in an RSpec example group to get the full Plushie test DSL (click, find!, assert_text, model, etc.) with automatic session setup and teardown via before/after hooks.

Mirrors the lifecycle provided by Case for Minitest, so tests are interchangeable between frameworks.

Examples:

Basic usage

RSpec.describe Counter do
  include Plushie::Test::RSpec
  plushie_app Counter

  it "increments" do
    click("#increment")
    expect(text(find!("#count"))).to eq("Count: 1")
  end
end

Nested groups inherit the app declaration

RSpec.describe Counter do
  include Plushie::Test::RSpec
  plushie_app Counter

  context "after three clicks" do
    it "shows 3" do
      3.times { click("#increment") }
      expect(text(find!("#count"))).to eq("Count: 3")
    end
  end
end

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Class Method Details

.included(base)

This method returns an undefined value.

Hook called when the module is included into an RSpec example group. Wires up Helpers, ClassMethods, and before/after lifecycle hooks.

Parameters:

  • base (Class)

    the including example group class



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/plushie/test/rspec.rb', line 43

def self.included(base)
  base.include Helpers
  base.extend ClassMethods

  base.before(:each) do
    app_class = self.class.plushie_app_class
    raise "No app declared. Add `plushie_app MyApp` to your describe block." unless app_class

    pool = Plushie::Test.pool
    session_id = pool.register
    @_plushie_session = Session.new(app_class, pool: pool, session_id: session_id)
    Thread.current[:_plushie_test_session] = @_plushie_session
  end

  base.after(:each) do
    @_plushie_session&.stop
    Thread.current[:_plushie_test_session] = nil
  end
end