wisper-rspec 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8e6d23dd1020653426db699b54fc2a1b42303bc8
4
- data.tar.gz: 456ec8f7f24ec51cb10848addfbb11ebf1ee1737
3
+ metadata.gz: 21502770eb4a955472b6c79fc17e2ef4714ccfc4
4
+ data.tar.gz: 542574ad03f2c399bb665f4dcaf9a7a6488106d3
5
5
  SHA512:
6
- metadata.gz: 40882bd92bd01b9c8be1efd98ba72409c5dab9d0f7b4d1bac38d095db7bb659986c63909b697a8954412d33242a2cb90f48f8eb93b8c522034529a1e17ebbc45
7
- data.tar.gz: 9ed7cd318f57629d129e8175008dd248478033547695cfb7405c60dcb188a38592c77382708bafc58ea560ba3cd59a2752aeff0eb2964bbb32097f65dee60a51
6
+ metadata.gz: f3cf54a835f388971225a8ab3cd0dba450d47a5b242a6f4ae5942f41e3a00ac289fe6e9c35c47539a8d4edb9922308a17252a2be447e8cb14ebec0a4c87cee0d
7
+ data.tar.gz: 207eec7fc007cef723ed80cda2b521b6b57b5600f6dafa68735d6d970a3e77aedefc72e5e11e293767331704e4c44317d44b9aa3f298b65afa26ab148f51f2a9
@@ -0,0 +1,7 @@
1
+ 0.0.2 (8/Jan/2015)
2
+
3
+ * Added support for argument matching [#1] by Gavin Todes (GAV1N)
4
+
5
+ 0.0.1 (27/Oct/2014)
6
+
7
+ * Abstracted rspec from [Wisper](https://github.com/krisleech/wisper) gem.
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # Wisper::Rspec
2
2
 
3
- WIP - This is being extracted from Wisper.
4
-
5
- Rspec matcher and stubbing for Wisper
3
+ Rspec matcher and stubbing for [Wisper](https://github.com/krisleech/wisper).
6
4
 
7
5
  [![Gem Version](https://badge.fury.io/rb/wisper-rspec.png)](http://badge.fury.io/rb/wisper-rspec)
8
6
  [![Build Status](https://travis-ci.org/krisleech/wisper-rspec.png?branch=master)](https://travis-ci.org/krisleech/wisper-rspec)
@@ -28,14 +26,26 @@ end
28
26
  ```
29
27
 
30
28
  In your specs:
31
-
32
29
  ```ruby
33
30
  expect { publisher.execute }.to broadcast(:an_event)
34
31
  ```
32
+ This will match both `broadcast(:an_event)` and `broadcast(:an_event, :arg_1)`.
33
+
34
+
35
+ ```ruby
36
+ # with optional arguments
37
+ expect { publisher.execute }.to broadcast(:another_event, :arg_1, :arg_2)
38
+ ```
39
+
40
+ With event arguments, it matches only if the event is broadcast with those arguments. This assertion matches `broadcast(:another_event, :arg_1, :arg_2)` but not `broadcast(:another_event)`.
41
+
42
+
43
+
44
+
35
45
 
36
46
  ### Using message expections
37
47
 
38
- If you need to assert on the arguments broadcast you can subscribe a double
48
+ If you need to assert on the listener receiving broadcast arguments you can subscribe a double
39
49
  with a [message expection](https://github.com/rspec/rspec-mocks#message-expectations)
40
50
  and then use any of the [argument matchers](https://github.com/rspec/rspec-mocks#argument-matchers).
41
51
 
@@ -59,11 +69,11 @@ Given this piece of code:
59
69
  class MyController
60
70
  def create
61
71
  publisher = MyPublisher.new
62
-
72
+
63
73
  publisher.on(:some_event) do |variable|
64
74
  return "Hello with #{variable}!"
65
75
  end
66
-
76
+
67
77
  publisher.execute
68
78
  end
69
79
  end
@@ -88,7 +98,7 @@ describe MyController do
88
98
  end
89
99
  ```
90
100
 
91
- This is useful when testing Rails controllers in isolation from the business logic.
101
+ This is useful when testing Rails controllers in isolation from the business logic.
92
102
 
93
103
  You can use any number of args to pass to the event:
94
104
 
@@ -12,18 +12,23 @@ module Wisper
12
12
  end
13
13
 
14
14
  def method_missing(method_name, *args, &block)
15
- @broadcast_events << method_name.to_s
15
+ @broadcast_events << [method_name.to_s, *args]
16
16
  end
17
17
 
18
- def broadcast?(event_name)
19
- @broadcast_events.include?(event_name.to_s)
18
+ def broadcast?(event_name, *args)
19
+ if args.size > 0
20
+ @broadcast_events.include?([event_name.to_s, *args])
21
+ else
22
+ @broadcast_events.map(&:first).include?(event_name.to_s)
23
+ end
20
24
  end
21
25
  end
22
26
 
23
27
  module BroadcastMatcher
24
28
  class Matcher
25
- def initialize(event)
29
+ def initialize(event, *args)
26
30
  @event = event
31
+ @args = args
27
32
  end
28
33
 
29
34
  def supports_block_expectations?
@@ -37,20 +42,24 @@ module Wisper
37
42
  block.call
38
43
  end
39
44
 
40
- event_recorder.broadcast?(@event)
45
+ event_recorder.broadcast?(@event, *@args)
41
46
  end
42
47
 
43
48
  def failure_message
44
- "expected publisher to broadcast #{@event} event"
49
+ msg = "expected publisher to broadcast #{@event} event"
50
+ msg += " with args: #{@args.inspect}" if @args.size > 0
51
+ msg
45
52
  end
46
53
 
47
54
  def failure_message_when_negated
48
- "expected publisher not to broadcast #{@event} event"
55
+ msg = "expected publisher not to broadcast #{@event} event"
56
+ msg += " with args: #{@args.inspect}" if @args.size > 0
57
+ msg
49
58
  end
50
59
  end
51
60
 
52
- def broadcast(event)
53
- Matcher.new(event)
61
+ def broadcast(event, *args)
62
+ Matcher.new(event, *args)
54
63
  end
55
64
  end
56
65
  end
@@ -1,5 +1,5 @@
1
1
  module Wisper
2
2
  module Rspec
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -12,6 +12,20 @@ describe 'broadcast matcher' do
12
12
  expect { publisher.send(:broadcast, :foobar) }.to broadcast(:foobar)
13
13
  end
14
14
 
15
+ context "with arguments" do
16
+ it 'passes when publisher broadcasts inside block' do
17
+ expect { publisher.send(:broadcast, :fizzbuzz, 12345) }.to broadcast(:fizzbuzz, 12345)
18
+ end
19
+
20
+ it 'passes without arguments when publisher broadcasts inside block' do
21
+ expect { publisher.send(:broadcast, :fizzbuzz, 12345) }.to broadcast(:fizzbuzz)
22
+ end
23
+
24
+ it 'fails with incorrect arguments when publisher broadcasts inside block' do
25
+ expect { publisher.send(:broadcast, :fizzbuzz, 12345) }.not_to broadcast(:fizzbuzz, 98765)
26
+ end
27
+ end
28
+
15
29
  it 'passes with not_to when publisher does not broadcast inside block' do
16
30
  expect { publisher }.not_to broadcast(:foobar)
17
31
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wisper-rspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kris Leech
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-27 00:00:00.000000000 Z
11
+ date: 2015-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: wisper
@@ -76,6 +76,7 @@ files:
76
76
  - ".gitignore"
77
77
  - ".rspec"
78
78
  - ".travis.yml"
79
+ - CHANGELOG.md
79
80
  - Gemfile
80
81
  - LICENSE.txt
81
82
  - README.md