wires-test 0.1.3 → 0.1.4
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 +4 -4
- data/lib/wires/test.rb +71 -73
- metadata +4 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a3c4bf5ece47b1d797b828be77984f4891b4c9a
|
4
|
+
data.tar.gz: 67706a912177f2717174f1b0f2ca248df8cc4f0a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 413d663728075ee10b62f392291def4612af0a612bb21dd3d6a032581158e36c5552a1c9d2d3ae84a7f43376bf88b681d307b19fa40c6378dff70777ef1386f9
|
7
|
+
data.tar.gz: e04e33bb642574f228c67bb0e53b40a41135e2a7ac15a8f866b0f0501339756ef9bbd19d37322b09f3b664474e59a766e0a4cccc100618db4250e629273ee0ab
|
data/lib/wires/test.rb
CHANGED
@@ -1,28 +1,25 @@
|
|
1
1
|
|
2
|
-
# Encase all code in a HEREDOC string until the...
|
3
|
-
<<'-END OF IMPLEMENTATION'
|
4
|
-
|
5
2
|
module Wires
|
6
3
|
module Test
|
7
4
|
module Helper
|
8
5
|
|
9
|
-
attr_reader :
|
6
|
+
attr_reader :wires_events
|
10
7
|
|
11
|
-
def
|
12
|
-
@
|
13
|
-
@
|
8
|
+
def wires_test_setup
|
9
|
+
@wires_events = []
|
10
|
+
@wires_test_fire_hook = \
|
14
11
|
Channel.add_hook(:@before_fire) { |e,c|
|
15
|
-
@
|
12
|
+
@wires_events << [e,c]
|
16
13
|
}
|
17
14
|
end
|
18
15
|
|
19
|
-
def
|
16
|
+
def wires_test_teardown
|
20
17
|
Wires::Hub.join_children
|
21
|
-
@
|
22
|
-
Channel.remove_hook(:@before_fire, &@
|
18
|
+
@wires_events = nil
|
19
|
+
Channel.remove_hook(:@before_fire, &@wires_test_fire_hook)
|
23
20
|
end
|
24
21
|
|
25
|
-
def
|
22
|
+
def fired?(event, channel=:__no_channel_was_specified__,
|
26
23
|
clear:false, exclusive:false, plurality:nil,
|
27
24
|
exact_event:false, exact_channel:false,
|
28
25
|
&block)
|
@@ -49,7 +46,7 @@ module Wires
|
|
49
46
|
"#{key_event.inspect}"
|
50
47
|
end
|
51
48
|
|
52
|
-
results = @
|
49
|
+
results = @wires_events.select { |e,c|
|
53
50
|
c = Channel[c]
|
54
51
|
(exact_event ? (key_event == e) : (key_event =~ e)) && (!key_chan ||
|
55
52
|
(exact_channel ? (key_chan == c) : (key_chan =~ c)))
|
@@ -58,20 +55,20 @@ module Wires
|
|
58
55
|
# If passed a block, use it to determine
|
59
56
|
results.select! { |e,c| yield e,c } if block_given?
|
60
57
|
|
61
|
-
|
58
|
+
clear_fired if clear
|
62
59
|
|
63
60
|
return false if results.empty?
|
64
|
-
return false if exclusive and (@
|
61
|
+
return false if exclusive and (@wires_events != results)
|
65
62
|
return false if plurality and (results.size != plurality)
|
66
63
|
|
67
64
|
true
|
68
65
|
end
|
69
66
|
|
70
|
-
def
|
71
|
-
@
|
67
|
+
def clear_fired
|
68
|
+
@wires_events.clear
|
72
69
|
end
|
73
70
|
|
74
|
-
def
|
71
|
+
def wires_test_channel_from_kwargs **kwargs
|
75
72
|
# Get channel_name from keyword arguments
|
76
73
|
channel_name = \
|
77
74
|
kwargs.has_key?(:channel_name) ?
|
@@ -90,7 +87,7 @@ module Wires
|
|
90
87
|
end
|
91
88
|
|
92
89
|
|
93
|
-
shared_context "with
|
90
|
+
shared_context "with wires", :wires=>true do
|
94
91
|
unless ancestors.include? Wires::Convenience
|
95
92
|
include Wires::Convenience
|
96
93
|
end
|
@@ -98,52 +95,75 @@ shared_context "with AFFIX wires", :AFFIX_wires=>true do
|
|
98
95
|
unless ancestors.include? Wires::Test::Helper
|
99
96
|
include Wires::Test::Helper
|
100
97
|
around do |example|
|
101
|
-
|
98
|
+
wires_test_setup
|
102
99
|
example.run
|
103
|
-
|
100
|
+
wires_test_teardown
|
104
101
|
end
|
105
102
|
end
|
106
103
|
|
107
104
|
extend Wires::Test::RSpec::ExampleGroupMethods
|
108
105
|
end
|
109
106
|
|
110
|
-
shared_context "with
|
111
|
-
include_context "with
|
107
|
+
shared_context "with wires stimulus" do |event, **kwargs|
|
108
|
+
include_context "with wires"
|
112
109
|
|
113
110
|
before do
|
114
|
-
channel_obj =
|
111
|
+
channel_obj = wires_test_channel_from_kwargs **kwargs
|
115
112
|
channel_obj.fire event, blocking:true
|
116
113
|
end
|
117
114
|
end
|
118
115
|
|
119
116
|
|
120
|
-
::RSpec::Matchers.define :
|
121
|
-
|
122
|
-
|
123
|
-
|
117
|
+
::RSpec::Matchers.define :have_fired do |*args|
|
118
|
+
def where(&block)
|
119
|
+
raise ArgumentError, "No block passed to #should have_fired(...).where; "\
|
120
|
+
"be sure to use {} instead of do/end so that the "\
|
121
|
+
"block binds syntactically to #where instead of "\
|
122
|
+
"binding to #should." if block.nil?
|
123
|
+
@fulfilling_block = proc{|*args| block.call(*args); true}
|
124
|
+
self
|
125
|
+
end
|
126
|
+
|
127
|
+
def fulfilling(&block)
|
128
|
+
raise ArgumentError, "No block passed to #should have_fired(...).fulfilling; "\
|
129
|
+
"be sure to use {} instead of do/end so that the "\
|
130
|
+
"block binds syntactically to #fulfilling instead of "\
|
131
|
+
"binding to #should." if block.nil?
|
132
|
+
@fulfilling_block = block
|
133
|
+
self
|
134
|
+
end
|
135
|
+
|
136
|
+
def once; exactly(1).times; self end
|
137
|
+
def twice; exactly(2).times; self end
|
138
|
+
def exactly(n) @plurality = n; self end
|
139
|
+
def times; @use_plurality = true; self end
|
140
|
+
|
141
|
+
match do
|
142
|
+
plur = @use_plurality ? @plurality : nil
|
143
|
+
fired? *args, plurality:plur, &@fulfilling_block
|
124
144
|
end
|
125
145
|
|
126
146
|
description do
|
127
|
-
event, channel,
|
147
|
+
event, channel, *rest = args
|
128
148
|
|
129
149
|
str = "have fired #{event.inspect}"
|
130
150
|
str += " on #{channel.inspect}" if channel
|
131
151
|
str
|
132
152
|
end
|
133
153
|
|
134
|
-
failure_message_for_should do
|
154
|
+
failure_message_for_should do
|
155
|
+
"expected to #{description}\n"+
|
135
156
|
"received: \n #{actual_events.map(&:inspect).join("\n ")}"
|
136
157
|
end
|
137
158
|
|
138
|
-
failure_message_for_should_not do
|
159
|
+
failure_message_for_should_not do
|
160
|
+
"expected not to #{description}\n"+
|
139
161
|
"received: \n #{actual_events.map(&:inspect).join("\n ")}"
|
140
162
|
end
|
141
163
|
|
142
164
|
def actual_events
|
143
|
-
matcher_execution_context.instance_variable_get :@
|
165
|
+
matcher_execution_context.instance_variable_get :@wires_events
|
144
166
|
end
|
145
|
-
|
146
|
-
def process_expected(*args, fulfilling:nil); [*args, fulfilling] end
|
147
167
|
end
|
148
168
|
|
149
169
|
|
@@ -152,27 +172,35 @@ module Wires
|
|
152
172
|
module RSpec
|
153
173
|
module ExampleGroupMethods
|
154
174
|
|
155
|
-
def
|
156
|
-
context "(with
|
157
|
-
include_context "with
|
175
|
+
def with_stimulus(event, **kwargs, &block)
|
176
|
+
context "(with stimulus #{event.inspect})" do
|
177
|
+
include_context "with wires stimulus", event, **kwargs
|
158
178
|
instance_eval &block
|
159
179
|
end
|
160
180
|
end
|
161
181
|
|
162
|
-
def
|
182
|
+
def it_fires(event, **kwargs, &block)
|
163
183
|
context "fires #{event.inspect}" do
|
164
184
|
specify do
|
165
|
-
channel_obj =
|
166
|
-
|
185
|
+
channel_obj = wires_test_channel_from_kwargs **kwargs
|
186
|
+
if block.nil?
|
187
|
+
should have_fired(event, channel_obj)
|
188
|
+
else
|
189
|
+
should have_fired(event, channel_obj).fulfilling(&block)
|
190
|
+
end
|
167
191
|
end
|
168
192
|
end
|
169
193
|
end
|
170
194
|
|
171
|
-
def
|
195
|
+
def it_fires_no(event, **kwargs, &block)
|
172
196
|
context "fires no #{event.inspect}" do
|
173
197
|
specify do
|
174
|
-
channel_obj =
|
175
|
-
|
198
|
+
channel_obj = wires_test_channel_from_kwargs **kwargs
|
199
|
+
if block.nil?
|
200
|
+
should_not have_fired(event, channel_obj)
|
201
|
+
else
|
202
|
+
should_not have_fired(event, channel_obj).fulfilling(&block)
|
203
|
+
end
|
176
204
|
end
|
177
205
|
end
|
178
206
|
end
|
@@ -181,33 +209,3 @@ module Wires
|
|
181
209
|
end
|
182
210
|
end
|
183
211
|
end
|
184
|
-
|
185
|
-
-END OF IMPLEMENTATION
|
186
|
-
.gsub(/AFFIX[_ ]/, "") # Remove all AFFIX markers (see Wires::Test.build_alt)
|
187
|
-
.tap { |code| eval code } # Eval the cleaned code in
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
module Wires
|
192
|
-
module Test
|
193
|
-
# Build an alternate version of Test for an alternate Wires module
|
194
|
-
# Optionally, specify an affix to be used in method names;
|
195
|
-
# This helps to differentiate from the original Helper
|
196
|
-
def self.build_alt(wires_module_path, affix:nil)
|
197
|
-
affix = affix ? affix.to_s+'_' : ''
|
198
|
-
|
199
|
-
[__FILE__] # List of files to mutate and eval
|
200
|
-
.map { |file| File.read file }
|
201
|
-
.each do |code|
|
202
|
-
|
203
|
-
code =~ /(?<='-END OF IMPLEMENTATION').*?(?=-END OF IMPLEMENTATION)/m
|
204
|
-
code = $&
|
205
|
-
|
206
|
-
code.gsub! /Wires/, "#{wires_module_path}"
|
207
|
-
code.gsub! /AFFIX[_ ]/, affix
|
208
|
-
|
209
|
-
eval code
|
210
|
-
end
|
211
|
-
end
|
212
|
-
end
|
213
|
-
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wires-test
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joe McIlvain
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: wires
|
@@ -72,8 +72,8 @@ executables: []
|
|
72
72
|
extensions: []
|
73
73
|
extra_rdoc_files: []
|
74
74
|
files:
|
75
|
-
- lib/wires/test.rb
|
76
75
|
- LICENSE
|
76
|
+
- lib/wires/test.rb
|
77
77
|
homepage: https://github.com/jemc/wires-test/
|
78
78
|
licenses:
|
79
79
|
- Copyright 2013 Joe McIlvain. All rights reserved.
|
@@ -94,9 +94,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
94
|
version: '0'
|
95
95
|
requirements: []
|
96
96
|
rubyforge_project:
|
97
|
-
rubygems_version: 2.
|
97
|
+
rubygems_version: 2.2.0
|
98
98
|
signing_key:
|
99
99
|
specification_version: 4
|
100
100
|
summary: wires-test
|
101
101
|
test_files: []
|
102
|
-
has_rdoc:
|