Skip to content
This repository has been archived by the owner on Apr 2, 2019. It is now read-only.

Commit

Permalink
Merge pull request #47 from simplybusiness/better-rspec-matcher
Browse files Browse the repository at this point in the history
Clear TestingSupport.published_events when running the spec
  • Loading branch information
PeterWuMC committed Apr 19, 2016
2 parents 3bac165 + 73b54e9 commit 7dd6d57
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
8 changes: 4 additions & 4 deletions example/non_rails_app/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ../../
specs:
rabbit_feed (2.4.2)
rabbit_feed (2.4.3)
activemodel (>= 3.2.0, < 5.0.0)
activesupport (>= 3.2.0, < 5.0.0)
avro (>= 1.5.4, < 1.8.0)
Expand All @@ -11,10 +11,10 @@ PATH
GEM
remote: https://rubygems.org/
specs:
activemodel (4.2.5.1)
activesupport (= 4.2.5.1)
activemodel (4.2.6)
activesupport (= 4.2.6)
builder (~> 3.1)
activesupport (4.2.5.1)
activesupport (4.2.6)
i18n (~> 0.7)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
Expand Down
2 changes: 1 addition & 1 deletion example/rails_app/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ../../
specs:
rabbit_feed (2.4.2)
rabbit_feed (2.4.3)
activemodel (>= 3.2.0, < 5.0.0)
activesupport (>= 3.2.0, < 5.0.0)
avro (>= 1.5.4, < 1.8.0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def matches?(given_proc, negative_expectation = false)
end

begin
TestingSupport.published_events.clear
given_proc.call
rescue
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rabbit_feed/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module RabbitFeed
VERSION = '2.4.2'
VERSION = '2.4.3'
end
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,20 @@ module RSpecMatchers
end
end

context 'when the expectation is met' do
it 'clears any existing published_events' do
10.times.each do
RabbitFeed::Producer.publish_event event_name, event_payload
end

expect do
expect {
RabbitFeed::Producer.publish_event event_name, event_payload
}.to publish_event(event_name, event_payload)
end.to change { TestingSupport.published_events.count }.from(10).to(1)

end

context 'when the expectation is met' do
it 'validates' do
expect {
RabbitFeed::Producer.publish_event event_name, event_payload
Expand Down

0 comments on commit 7dd6d57

Please sign in to comment.