-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract
#with_events_disabled
helper for reuse
In a subsequent commit we want to use this outside of the reporting subscriber tests.
- Loading branch information
1 parent
10b19f0
commit 666dcbd
Showing
3 changed files
with
29 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 1 addition & 21 deletions
22
spec/subscribers/super_good/solidus_taxjar/spree/reporting_subscriber_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module SolidusEventsHelper | ||
# We can use this helper method to ensure that events are not run until after | ||
# the test setup has been completed. This helps us more easily test side | ||
# effects from events or control unintended side effects when attempting to | ||
# test functionality that is not event-driven but would otherwise emit events. | ||
# | ||
# @yield Any test setup you'd like to run without events being emitted. | ||
# @return The return value of the test setup in your block. | ||
def with_events_disabled(&block) | ||
if SolidusSupport::LegacyEventCompat.using_legacy? | ||
allow(Spree::Event).to receive(:fire).and_return(nil) | ||
else | ||
allow(Spree::Bus).to receive(:publish).and_return(nil) | ||
end | ||
|
||
object = yield block | ||
|
||
if SolidusSupport::LegacyEventCompat.using_legacy? | ||
allow(Spree::Event).to receive(:fire).and_call_original | ||
else | ||
allow(Spree::Bus).to receive(:publish).and_call_original | ||
end | ||
|
||
object | ||
end | ||
end |