README.md in wisper-1.6.1 vs README.md in wisper-2.0.0.rc1

- old
+ new

@@ -30,14 +30,14 @@ ### Publishing ```ruby class CancelOrder include Wisper::Publisher - + def call(order_id) order = Order.find_by_id(order_id) - + # business logic... if order.cancelled? broadcast(:cancel_order_successful, order.id) else @@ -47,11 +47,11 @@ end ``` When a publisher broadcasts an event it can include number of arguments. -The `broadcast` method is also aliased as `publish` and `announce`. +The `broadcast` method is also aliased as `publish`. You can also include `Wisper.publisher` instead of `Wisper::Publisher`. ### Subscribing @@ -200,12 +200,12 @@ Temporary Global Listeners are threadsafe. ## Subscribing to selected events By default a listener will get notified of all events it can respond to. You -can limit which events a listener is notified of by passing an event or array -of events to `on:`. +can limit which events a listener is notified of by passing an string, symbol, +array or regular expression to `on`: ```ruby post_creater.subscribe(PusherListener.new, on: :create_post_successful) ``` @@ -222,11 +222,11 @@ listeners would receive `on_post_created`. You can also pass `true` which will use the default prefix, "on". ## Mapping an event to a different method -By default the method called on the subscriber is the same as the event +By default the method called on the listener is the same as the event broadcast. However it can be mapped to a different method using `with:`. ```ruby report_creator.subscribe(MailResponder.new, with: :successful) ``` @@ -255,85 +255,10 @@ You could also alias the method within your listener, as such `alias successful create_report_successful`. ## RSpec -### Broadcast Matcher - -```ruby -require 'wisper/rspec/matchers' - -RSpec::configure do |config| - config.include(Wisper::RSpec::BroadcastMatcher) -end - -expect { publisher.execute }.to broadcast(:an_event) -``` - -### Using message expections - -If you need to assert on the arguments broadcast you can subscribe a double -with a [message expection](https://github.com/rspec/rspec-mocks#message-expectations) -and then use any of the [argument matchers](https://github.com/rspec/rspec-mocks#argument-matchers). - -```ruby -listener = double('Listener') - -expect(listener).to receive(:an_event).with(some_args) - -publisher.subscribe(listener) - -publisher.execute -``` - -### Stubbing publishers - -You can stub publishers and their events in unit (isolated) tests that only care about reacting to events. - -Given this piece of code: - -```ruby -class MyController - def create - publisher = MyPublisher.new - - publisher.on(:some_event) do |variable| - return "Hello with #{variable}!" - end - - publisher.execute - end -end -``` - -You can test it like this: - -```ruby -require 'wisper/rspec/stub_wisper_publisher' - -describe MyController do - context "on some_event" do - before do - stub_wisper_publisher("MyPublisher", :execute, :some_event, "foo") - end - - it "renders" do - response = MyController.new.create - expect(response).to eq "Hello with foo!" - end - end -end -``` - -This is useful when testing Rails controllers in isolation from the business logic. - -You can use any number of args to pass to the event: - -```ruby -stub_wisper_publisher("MyPublisher", :execute, :some_event, "foo1", "foo2", ...) -``` - -See `spec/lib/rspec_extensions_spec.rb` for a runnable example. +Please see [wisper-rspec](https://github.com/krisleech/wisper-rspec). ## Clearing Global Listeners If you use global listeners in non-feature tests you _might_ want to clear them in a hook to prevent global subscriptions persisting between tests.