Skip to content

Disable global subscriptions during a block #11

@Mathiou04

Description

@Mathiou04

Hey @krisleech,

First, thanks for the great work with the wisper gem.

I just started using it for one of my project and I am facing an issue I didn't find a solution to.

I am using a global subscriber that is in an initializer of a Rails project.
The thing is I would like most of my rspec test to not depend on this subscription. I could use Wisper.clear for that but then, I cannot run the full test suite properly because I need the subscriptions for my system tests.

I had a look at this gem, and tried to use the fake method.
Unfortunately the fake method doesn't work well with wisper-rspec meaning that in this case, the broadcast matcher won't work anymore (given how the matcher is implemented).

I think that in my case what I would like to do is disable the listeners for the duration of a block.
Currently I implemented a dirty hack that basically does this:

 registrations = Wisper::GlobalListeners.registrations.clone # save the global listeners
 Wisper.clear # clear the global listeners
 example.run
 Wisper::GlobalListeners.instance.instance_eval { @registrations = registrations } # restore the global listeners

Do you think such a feature could makes sense? Or am I taking this the wrong way and there is a better approach?

Thanks again for all this work!
Best

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions