Skip to content

Commit

Permalink
add a spec and fix rspec matcher [wip]
Browse files Browse the repository at this point in the history
  • Loading branch information
Kris Leech committed Jul 4, 2014
1 parent cfdc665 commit 78af2e2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/wisper/rspec/matchers.rb
Expand Up @@ -7,7 +7,7 @@ def initialize(publisher, event)
@event = event
end

def matches?(block)
def matches?(&block)
published = false
@publisher.on(@event) { published = true }

Expand All @@ -34,4 +34,4 @@ def publish_event(publisher, event)

RSpec::configure do |config|
config.include(WisperMatchers)
end
end
37 changes: 37 additions & 0 deletions spec/lib/wisper/rspec/matchers_spec.rb
@@ -0,0 +1,37 @@
require 'spec_helper'
require 'wisper/rspec/matchers'

describe WisperMatchers::ShouldPublish do
let(:publisher) do
Class.new do
include Wisper::Publisher

def execute
broadcast(:it_happened)
end
end.new
end

describe '#matches?' do
it 'returns false when event not broadcast' do
matcher = WisperMatchers::ShouldPublish.new(publisher, :it_happened)
result = matcher.matches? { publisher }
expect(result).to be_falsey
end

it 'returns true when event broadcast' do
matcher = WisperMatchers::ShouldPublish.new(publisher, :it_happened)
result = matcher.matches? { publisher.execute }

expect(result).to be_truthy
end
end

describe 'full example' do
it 'expects event to be publisher when published' do
expect(publisher).to publish_event(publisher, :it_happened)

publisher.execute
end
end
end

0 comments on commit 78af2e2

Please sign in to comment.