Sha256: 8d941eb971b6af84a5004dd3fcb3c04915915fdf505d0fdd58e67ddd1e8da116

Contents?: true

Size: 1.3 KB

Versions: 6

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

RSpec.shared_examples 'an event which synchronously dispatches' do |dispatcher_klass|
  specify do
    reactors = Eventsimple::EventDispatcher.rules.for(described_class.new)

    expect(reactors.sync).to include(dispatcher_klass)
  end
end

RSpec.shared_examples 'an event which asynchronously dispatches' do |dispatcher_klass|
  specify do
    reactors = Eventsimple::EventDispatcher.rules.for(described_class.new)

    expect(reactors.async).to include(dispatcher_klass)
  end
end

RSpec.shared_examples 'an event in invalid state' do
  it 'raises an InvalidTransition error' do
    expect { event.save }.to raise_error(Eventsimple::InvalidTransition).and not_change(
      event.class, :count
    )
  end
end

RSpec.shared_examples 'an event in invalid state that is rescued' do
  context 'when save' do
    it 'does not InvalidTransition error on save' do
      expect { event.save }.not_to raise_error
    end

    it 'does not write event on save' do
      expect { event.save }.not_to change(event.class, :count)
    end
  end

  context 'when save!' do
    it 'does not InvalidTransition error on save!' do
      expect { event.save! }.not_to raise_error
    end

    it 'does not write event on save!' do
      expect { event.save! }.not_to change(event.class, :count)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
eventsimple-1.2.0 lib/eventsimple/support/spec_helpers.rb
eventsimple-1.1.3 lib/eventsimple/support/spec_helpers.rb
eventsimple-1.1.2 lib/eventsimple/support/spec_helpers.rb
eventsimple-1.1.1 lib/eventsimple/support/spec_helpers.rb
eventsimple-1.1.0 lib/eventsimple/support/spec_helpers.rb
eventsimple-1.0.0 lib/eventsimple/support/spec_helpers.rb