Git Product home page Git Product logo

wisper-testing's Introduction

Wisper::Testing

Build Status

Helpers for testing Wisper publisher/subscribers.

Installation

gem 'wisper-testing'

Usage

Using fake! and fake prevents any events from being broadcast.

Instead each event is recorded and can be inspected.

Wisper::Testing.fake!

Wisper::Testing.fake do
  # ...
end

Wisper::Testing.events # => [...]

Inline

Using inline! and inline ensures all events are broadcast using the default broadcaster, meaning any subscribers which are subscribed with async: true will not be called asynchronously, but synchronously.

Wisper::Testing.inline!

Wisper::Testing.inline do
  # ...
end

Restore

Using restore! will turn off fake! and inline! and restore the original configuration.

It is not nessesary to call this if you are using the block variations fake and inline.

Wisper::Testing.restore!

Enabled

Wisper::Testing.enabled? # => true/false

Development

ls **/*.rb | entr -c bundle exec rspec

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/krisleech/wisper-testing.

This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

wisper-testing's People

Contributors

bryanhickerson avatar krisleech avatar textgoeshere avatar zlw avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

wisper-testing's Issues

`fake` and friends don't work on existing subscriptions

Just following up on #6.

If the subscription already exists then its registration is already assigned a (real) listener. Calling fake only affects subsequent registrations. This is particularly a challenge where you are working with global listeners because you can't usually control their load order to get the fake in before the subscription.

Here's a failing spec that illustrates the issue: https://gist.github.com/14d09819e2c0ccb1bd23.

Assuming this isn't by design ;), do you like the idea of adding a step to walk over the existing registrations, memoize their broadcasters, and replace them with FakeBroadcaster? And reversing that on restore.

Disable global subscriptions during a block

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.