Skip to content

Commit

Permalink
Merge pull request #85 from krisleech/remove-rspec-helpers
Browse files Browse the repository at this point in the history
remove rspec matchers and stubbing (moved to wisper-rspec gem)
  • Loading branch information
krisleech committed Oct 27, 2014
2 parents c0ffd22 + 6ff775b commit 3e04590
Show file tree
Hide file tree
Showing 6 changed files with 2 additions and 188 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Unreleased (!!contains breaking changes!!)

* remove deprecated methods
* remove rspec matcher and stubbing (moved to [wisper-rspec](https://github.com/krisleech/wisper-rspec))

## 1.6.0 (25 Oct 2014)

Expand Down
77 changes: 1 addition & 76 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,82 +257,7 @@ You could also alias the method within your listener, as such

## 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

Expand Down
57 changes: 0 additions & 57 deletions lib/wisper/rspec/matchers.rb

This file was deleted.

12 changes: 0 additions & 12 deletions lib/wisper/rspec/stub_wisper_publisher.rb

This file was deleted.

17 changes: 0 additions & 17 deletions spec/lib/wisper/rspec/matchers_spec.rb

This file was deleted.

26 changes: 0 additions & 26 deletions spec/lib/wisper/rspec/stub_wisper_publisher_spec.rb

This file was deleted.

0 comments on commit 3e04590

Please sign in to comment.