Class: RuboCop::Cop::Carwow::NoStubbingBusinessEvent

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/carwow/no_stubbing_business_event.rb

Overview

Never mock (or double) the BusinessEvent class, it won’t validate the schema and it reduces the quality of your tests!

[See discussion](carwow.discourse.team/t/schema-validations-for-business-events/414)

Examples:

# bad
expect(BusinessEvent).to have_received(:publish).with(:topic, :event, payload: payload)

# good - preferred
expect { subject }.to have_published_event(:topic, :event).with(payload)

# good
expect(topic: :event).to have_been_published.with(payload)

# bad
expect(BusinessEvent).not_to have_received(:publish)

# good - preferred
expect { subject }.not_to have_published_event

# good
expect(topic: :event).not_to have_been_published

Constant Summary collapse

RESTRICT_ON_SEND =

optimization: don’t call ‘on_send` unless the method name is in this list

i[allow expect].freeze
MSG =
'Stub BusinessEvent is discouraged!'

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



41
42
43
44
45
# File 'lib/rubocop/cop/carwow/no_stubbing_business_event.rb', line 41

def on_send(node)
  stub_on_business_event?(node) do
    add_offense(node)
  end
end