Skip to content

Commit

Permalink
Fixed incorrect regexp matchers in specs / AdapterProxy integration spec
Browse files Browse the repository at this point in the history
  • Loading branch information
Rustam Ibragimov committed Apr 12, 2018
1 parent 46fc549 commit 4d9744d
Show file tree
Hide file tree
Showing 6 changed files with 208 additions and 140 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ Style/CommentedKeyword:
Style/EvalWithLocation:
Enabled: false

Style/RegexpLiteral:
EnforcedStyle: mixed

Lint/AmbiguousRegexpLiteral:
Enabled: false

Expand Down
190 changes: 137 additions & 53 deletions spec/integration/event_broadcasting_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ def count
end

EvilEvents::Config.setup_adapters do |adapters|
adapters.register(:sidekiq, build_adapter_class.new)
adapters.register(:sidekiq, build_adapter_class.new)
adapters.register(:redis, build_adapter_class.new)
adapters.register(:rabbit, build_adapter_class.new)
adapters.register(:background, build_adapter_class.new)
end
end

Expand Down Expand Up @@ -228,43 +231,43 @@ def count

# check log output of the first event data
expect(silent_output.string).to match(
Regexp.union(
/\[EvilEvents:EventEmitted\(memory_sync\)\]\s/,
/ID:\s[a-z0-9\-]\s::\s/,
/TYPE:\smatch_lost\s::\s/,
/PAYLOAD:\s#{match_lost_attrs[:payload]}\s::\s/,
/METADATA:\s#{match_lost_attrs[:metadata]}/
)
%r{
\[EvilEvents:EventEmitted\(memory_sync\)\]:\s
ID:\s[a-z0-9]{8}\-[a-z0-9]{4}\-[a-z0-9]{4}\-[a-z0-9]{4}\-[a-z0-9]{12}\s::\s
TYPE:\smatch_lost\s::\s
PAYLOAD:\s#{Regexp.escape(match_lost_attrs[:payload].to_s)}\s::\s
METADATA:\s#{Regexp.escape(match_lost_attrs[:metadata].to_s)}
}x
)

# check log output for the second event data
expect(silent_output.string).to match(
Regexp.union(
/\[EvilEvents:EventEmitted\(sidekiq\)\]\s/,
/ID:\s[a-z0-9\-]\s::\s/,
/TYPE:\soverwatch_released\s::\s/,
/PAYLOAD:\s#{overwatch_released_attrs[:payload]}\s::\s/,
/METADATA:\s#{overwatch_released_attrs[:metadata]}/
)
%r{
\[EvilEvents:EventEmitted\(sidekiq\)\]:\s
ID:\s[a-z0-9]{8}\-[a-z0-9]{4}\-[a-z0-9]{4}\-[a-z0-9]{4}\-[a-z0-9]{12}\s::\s
TYPE:\soverwatch_released\s::\s
PAYLOAD:\s#{Regexp.escape(overwatch_released_attrs[:payload].to_s)}\s::\s
METADATA:\s#{Regexp.escape(overwatch_released_attrs[:metadata].to_s)}
}x
)

# check log output for the notifier activity
[ElasticSearchStub, EventStoreStub, EventCounter].each do |subscriber|
expect(silent_output.string).to match(
Regexp.union(
/\[EvilEvents:EventProcessed\(match_lost\)\s/,
/EVENT_ID:\s[a-z0-9\-]\s::\s/,
/STATUS:\ssuccessful\s::\s/,
/SUBSCRIBER:\s#{subscriber.to_s}/
)
%r{
\[EvilEvents:EventProcessed\(match_lost\)\]:\s
EVENT_ID:\s[a-z0-9]{8}\-[a-z0-9]{4}\-[a-z0-9]{4}\-[a-z0-9]{4}\-[a-z0-9]{12}\s::\s
STATUS:\ssuccessful\s::\s
SUBSCRIBER:\s#{Regexp.escape(subscriber.to_s)}
}x
)
expect(silent_output.string).to match(
Regexp.union(
/\[EvilEvents:EventProcessed\(overwatch_released\)\s/,
/EVENT_ID:\s[a-z0-9\-]\s::\s/,
/STATUS:\ssuccessful\s::\s/,
/SUBSCRIBER:\s#{subscriber.to_s}/
)
%r{
\[EvilEvents:EventProcessed\(overwatch_released\)\]:\s
EVENT_ID:\s[a-z0-9]{8}\-[a-z0-9]{4}\-[a-z0-9]{4}\-[a-z0-9]{4}\-[a-z0-9]{12}\s::\s
STATUS:\ssuccessful\s::\s
SUBSCRIBER:\s#{Regexp.escape(subscriber.to_s)}
}x
)
end

Expand Down Expand Up @@ -332,45 +335,126 @@ def count

# check log output of the first event data
expect(silent_output.string).to match(
Regexp.union(
/\[EvilEvents:EventEmitted\(memory_sync\)\]\s/,
/ID:\s#{class_method_match_lost_attrs[:id]}\s::\s/,
/TYPE:\smatch_lost\s::\s/,
/PAYLOAD:\s#{class_method_match_lost_attrs[:payload]}\s::\s/,
/METADATA:\s#{class_method_match_lost_attrs[:metadata]}/
)
%r{
\[EvilEvents:EventEmitted\(memory_sync\)\]:\s
ID:\s#{Regexp.escape(class_method_match_lost_attrs[:id].to_s)}\s::\s
TYPE:\smatch_lost\s::\s
PAYLOAD:\s#{Regexp.escape(class_method_match_lost_attrs[:payload].to_s)}\s::\s
METADATA:\s#{Regexp.escape(class_method_match_lost_attrs[:metadata].to_s)}
}x
)

# check log output for the second event data
expect(silent_output.string).to match(
Regexp.union(
/\[EvilEvents:EventEmitted\(sidekiq\)\]\s/,
/ID:\s#{class_method_overwatch_released_attrs[:id]}\s::\s/,
/TYPE:\soverwatch_released\s::\s/,
/PAYLOAD:\s#{class_method_overwatch_released_attrs[:payload]}\s::\s/,
/METADATA:\s#{class_method_overwatch_released_attrs[:metadata]}/
)
%r{
\[EvilEvents:EventEmitted\(sidekiq\)\]:\s
ID:\s#{Regexp.escape(class_method_overwatch_released_attrs[:id].to_s)}\s::\s
TYPE:\soverwatch_released\s::\s
PAYLOAD:\s#{Regexp.escape(class_method_overwatch_released_attrs[:payload].to_s)}\s::\s
METADATA:\s#{Regexp.escape(class_method_overwatch_released_attrs[:metadata].to_s)}
}x
)

# check log output for the notifier activity
[ElasticSearchStub, EventStoreStub, EventCounter].each do |subscriber|
expect(silent_output.string).to match(
Regexp.union(
/\[EvilEvents:EventProcessed\(match_lost\)\s/,
/EVENT_ID:\s#{class_method_match_lost_attrs[:id]}\s::\s/,
/STATUS:\ssuccessful\s::\s/,
/SUBSCRIBER:\s#{subscriber.to_s}/
)
%r{
\[EvilEvents:EventProcessed\(match_lost\)\]:\s
EVENT_ID:\s#{Regexp.escape(class_method_match_lost_attrs[:id].to_s)}\s::\s
STATUS:\ssuccessful\s::\s
SUBSCRIBER:\s#{Regexp.escape(subscriber.to_s)}
}x
)
expect(silent_output.string).to match(
Regexp.union(
/\[EvilEvents:EventProcessed\(overwatch_released\)\s/,
/EVENT_ID:\s#{class_method_overwatch_released_attrs[:id]}\s::\s/,
/STATUS:\ssuccessful\s::\s/,
/SUBSCRIBER:\s#{subscriber.to_s}/
)
%r{
\[EvilEvents:EventProcessed\(overwatch_released\)\]:\s
EVENT_ID:\s#{Regexp.escape(class_method_overwatch_released_attrs[:id].to_s)}\s::\s
STATUS:\ssuccessful\s::\s
SUBSCRIBER:\s#{Regexp.escape(subscriber.to_s)}
}x
)
end

# BROADCASTING: broadcast via explicitly defined adapter
EvilEvents::Emitter.emit(
'match_lost', adapter: :background, **class_method_match_lost_attrs
)
EvilEvents::Emitter.emit(
'overwatch_released', adapter: :rabbit, **class_method_overwatch_released_attrs
)
match_event.emit!(adapter: :rabbit)
overwatch_event.emit!(adapter: :background)

# check state of subscriber
expect(EventCounter.count).to eq(10)

# check state of subscriber
# check consistency
expect(EventStoreStub.events).to contain_exactly(
a_kind_of(OverwatchReleased),
a_kind_of(MatchLost),
a_kind_of(OverwatchReleased),
a_kind_of(MatchLost),
a_kind_of(OverwatchReleased), # old event
a_kind_of(MatchLost), # old event
a_kind_of(OverwatchReleased), # old event
a_kind_of(MatchLost), # old event
overwatch_event, # old event
match_event # old event
)

# check state of subscriber
# check consistency
expect(ElasticSearchStub.event_store).to contain_exactly(
a_kind_of(OverwatchReleased),
a_kind_of(MatchLost),
a_kind_of(OverwatchReleased),
a_kind_of(MatchLost),
a_kind_of(OverwatchReleased), # old event
a_kind_of(MatchLost), # old event
a_kind_of(OverwatchReleased), # old event
a_kind_of(MatchLost), # old event
overwatch_event, # old event
match_event # old event
)

# match_lost event log with explicitly defined adapter :background
expect(silent_output.string).to match(
%r{
\[EvilEvents:EventEmitted\(background\)\]:\s
ID:\s#{Regexp.escape(class_method_match_lost_attrs[:id].to_s)}\s::\s
TYPE:\smatch_lost\s::\s
PAYLOAD:\s#{Regexp.escape(class_method_match_lost_attrs[:payload].to_s)}\s::\s
METADATA:\s#{Regexp.escape(class_method_match_lost_attrs[:metadata].to_s)}
}x
)
# match_lost event log with explicitly defined adapter :rabbit
expect(silent_output.string).to include(
'[EvilEvents:EventEmitted(rabbit)]: ' \
"ID: #{match_event.id} :: " \
'TYPE: match_lost :: ' \
"PAYLOAD: #{match_event.payload} :: " \
"METADATA: #{match_event.metadata}"
)

# overwatch_released event log with explicitly defined adapter :rabbit
expect(silent_output.string).to match(
%r{
\[EvilEvents:EventEmitted\(rabbit\)\]:\s
ID:\s#{Regexp.escape(class_method_overwatch_released_attrs[:id].to_s)}\s::\s
TYPE:\soverwatch_released\s::\s
PAYLOAD:\s#{Regexp.escape(class_method_overwatch_released_attrs[:payload].to_s)}\s::\s
METADATA:\s#{Regexp.escape(class_method_overwatch_released_attrs[:metadata].to_s)}
}x
)
# match_lost event log with explicitly defined adapter :background
expect(silent_output.string).to include(
'[EvilEvents:EventEmitted(background)]: ' \
"ID: #{overwatch_event.id} :: " \
'TYPE: overwatch_released :: ' \
"PAYLOAD: #{overwatch_event.payload} :: " \
"METADATA: #{overwatch_event.metadata}"
)
end

specify 'event callbacks' do
Expand Down
26 changes: 11 additions & 15 deletions spec/support/shared_examples/notifier/logging_interface.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: ture
# frozen_string_literal: true

shared_examples 'notifier logging interface' do
describe 'logging interface logic', :stub_event_system do
Expand All @@ -16,26 +16,22 @@
specify '#log_failure' do
loggable.log_failure(event, subscriber)

expect(silent_output.string).to match(
Regexp.union(
/\[EvilEvents::EventProcessed\(#{event.type}\)\]\s/,
/EVENT_ID:\s#{event.id}\s::\s/,
/STATUS:\sfailed\s::\s/,
/SUBSCRIBER:\s#{subscriber.source_object.to_s}/
)
expect(silent_output.string).to include(
"[EvilEvents:EventProcessed(#{event.type})]: " \
"EVENT_ID: #{event.id} :: " \
'STATUS: failed :: ' \
"SUBSCRIBER: #{subscriber.source_object}"
)
end

specify '#log_success' do
loggable.log_success(event, subscriber)

expect(silent_output.string).to match(
Regexp.union(
/\[EvilEvents::EventProcessed\(#{event.type}\)\]\s/,
/EVENT_ID:\s#{event.id}\s::\s/,
/STATUS:\ssuccessful\s::\s/,
/SUBSCRIBER:\s#{subscriber.source_object.to_s}/
)
expect(silent_output.string).to include(
"[EvilEvents:EventProcessed(#{event.type})]: " \
"EVENT_ID: #{event.id} :: " \
'STATUS: successful :: ' \
"SUBSCRIBER: #{subscriber.source_object}"
)
end
end
Expand Down
42 changes: 0 additions & 42 deletions spec/support/shared_examples/notifier_logging_interface.rb

This file was deleted.

Loading

0 comments on commit 4d9744d

Please sign in to comment.