Module: ModelTimeline::RSpec

Defined in:
lib/model_timeline/rspec.rb,
lib/model_timeline/rspec/matchers.rb

Overview

Helper module that configures RSpec to work with ModelTimeline

This module provides RSpec configuration for ModelTimeline, including:

  • Disabling timeline recording by default for faster tests

  • Enabling timeline recording only when specifically requested

  • Including custom RSpec matchers for testing timeline entries

Examples:

Including in RSpec configuration

# In spec_helper.rb or rails_helper.rb
RSpec.configure do |config|
  config.include ModelTimelineHelper
end

Running a test with timeline recording enabled

# Use the :with_timeline metadata to enable recording
describe User, :with_timeline do
  it "records timeline entries when updated" do
    user.update(name: "New Name")
    expect(user).to have_timeline_entry_change(:name)
  end
end

Defined Under Namespace

Modules: Matchers

Class Method Summary collapse

Class Method Details

.included(config) ⇒ void

This method returns an undefined value.

Configures RSpec with ModelTimeline hooks when included

Parameters:

  • config (RSpec::Core::Configuration)

    The RSpec configuration object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/model_timeline/rspec.rb', line 31

def self.included(config)
  # Reset timeline state before each example
  config.before(:each) do |example|
    ModelTimeline.disable! unless example.[:with_timeline]
  end

  # Enable timeline when the :with_timeline metadata is present
  config.around(:each, :with_timeline) do |example|
    ModelTimeline.enable!
    example.run
  ensure
    ModelTimeline.disable!
  end

  # Include custom RSpec matchers for testing timeline entries
  config.include ModelTimeline::RSpec::Matchers
end