wires-test 0.0.7 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/wires/test.rb +132 -52
- metadata +14 -14
- data/lib/wires/test/minitest.rb +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f0991c03a9d93a361970b27477d58a18656a54dc
|
4
|
+
data.tar.gz: 6992614716f21cb4d501e994c10391f08158282a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0043870480143307e8469fb414866dd10ffe0f5706422c4a692b7323f7609fbf564d31489db0b040e7fff670371ffbe2bcea4543afff01e6d2e7c5f286c6339c
|
7
|
+
data.tar.gz: 952ff5f296535e411b7bf65f6b8025329b8f1426103faf50d268ace723716fac1508ed2124d83968dec4f9751fa955fbf45baf88af7e9a230f3d0d404aadbf4f
|
data/lib/wires/test.rb
CHANGED
@@ -1,29 +1,33 @@
|
|
1
1
|
|
2
|
-
|
3
|
-
|
2
|
+
# Encase all code in a HEREDOC string until the...
|
3
|
+
<<'-END OF IMPLEMENTATION'
|
4
4
|
|
5
5
|
module Wires
|
6
|
-
|
7
6
|
module Test
|
8
|
-
|
9
7
|
module Helper
|
10
8
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
9
|
+
attr_reader :AFFIX_wires_events
|
10
|
+
|
11
|
+
def AFFIX_wires_test_setup
|
12
|
+
@AFFIX_wires_events = []
|
13
|
+
@AFFIX_wires_test_fire_hook = \
|
14
|
+
Channel.add_hook(:@before_fire) { |e,c|
|
15
|
+
@AFFIX_wires_events << [e,c]
|
16
|
+
}
|
15
17
|
end
|
16
18
|
|
17
|
-
def
|
18
|
-
|
19
|
-
|
19
|
+
def AFFIX_wires_test_teardown
|
20
|
+
Wires::Hub.join_children
|
21
|
+
@AFFIX_wires_events = nil
|
22
|
+
Channel.remove_hook(:@before_fire, &@AFFIX_wires_test_fire_hook)
|
20
23
|
end
|
21
24
|
|
22
|
-
def
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
def AFFIX_fired?(event, channel,
|
26
|
+
clear:false, exclusive:false, plurality:nil,
|
27
|
+
exact_event:false, exact_channel:false,
|
28
|
+
&block)
|
29
|
+
key_chan = channel.is_a?(Channel) ? channel : Channel[channel]
|
30
|
+
key_event = Event.list_from event
|
27
31
|
|
28
32
|
case key_event.count
|
29
33
|
when 0
|
@@ -34,69 +38,145 @@ module Wires
|
|
34
38
|
raise ArgumentError,"Can't check for fired? on multiple events: #{key_event.inspect}"
|
35
39
|
end
|
36
40
|
|
37
|
-
results = @
|
38
|
-
|
39
|
-
(
|
41
|
+
results = @AFFIX_wires_events.select { |e,c|
|
42
|
+
c = Channel[c]
|
43
|
+
(exact_event ? (key_event == e) : (key_event =~ e)) and
|
44
|
+
(exact_channel ? (key_chan == c) : (key_chan =~ c))
|
40
45
|
}
|
41
46
|
|
42
|
-
|
47
|
+
results.select! { |e,c| yield e,c } if block_given?
|
48
|
+
|
49
|
+
clear_AFFIX_fired if clear
|
43
50
|
|
44
51
|
return false if results.empty?
|
45
|
-
return false if exclusive and (@
|
52
|
+
return false if exclusive and (@AFFIX_wires_events != results)
|
46
53
|
return false if plurality and (results.size != plurality)
|
47
54
|
|
48
|
-
# Execute passed block for each match
|
49
|
-
results.each { |e,c| yield e,c if block_given? }
|
55
|
+
# # Execute passed block for each match
|
56
|
+
# results.each { |e,c| yield e,c if block_given? }
|
50
57
|
|
51
58
|
true
|
52
59
|
end
|
53
60
|
|
54
|
-
def
|
55
|
-
|
56
|
-
"Expected an event matching #{event.inspect}"\
|
57
|
-
" to have been fired on channel #{channel.inspect}."
|
61
|
+
def clear_AFFIX_fired
|
62
|
+
@AFFIX_wires_events.clear
|
58
63
|
end
|
59
64
|
|
60
|
-
def
|
61
|
-
|
62
|
-
|
63
|
-
|
65
|
+
def AFFIX_wires_test_channel_from_kwargs **kwargs
|
66
|
+
# Get channel_name from keyword arguments
|
67
|
+
channel_name = \
|
68
|
+
kwargs.has_key?(:channel_name) ?
|
69
|
+
kwargs[:channel_name] :
|
70
|
+
kwargs.has_key?(:to) ?
|
71
|
+
eval(kwargs[:to].to_s) :
|
72
|
+
subject
|
73
|
+
# Get channel object from channel_name or keyword argument :channel_obj
|
74
|
+
channel_obj = \
|
75
|
+
kwargs.has_key?(:channel_obj) ?
|
76
|
+
kwargs[:channel_obj] :
|
77
|
+
Wires::Channel[channel_name]
|
64
78
|
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
shared_context "with AFFIX wires", :AFFIX_wires=>true do
|
85
|
+
unless ancestors.include? Wires::Convenience
|
86
|
+
include Wires::Convenience
|
87
|
+
end
|
88
|
+
|
89
|
+
unless ancestors.include? Wires::Test::Helper
|
90
|
+
include Wires::Test::Helper
|
91
|
+
around do |example|
|
92
|
+
AFFIX_wires_test_setup
|
93
|
+
example.run
|
94
|
+
AFFIX_wires_test_teardown
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
shared_context "with AFFIX wires stimulus" do |event, **kwargs|
|
100
|
+
include_context "with AFFIX wires"
|
101
|
+
|
102
|
+
before do
|
103
|
+
channel_obj = AFFIX_wires_test_channel_from_kwargs **kwargs
|
104
|
+
channel_obj.fire event, blocking:true
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
|
109
|
+
::RSpec::Matchers.define :have_AFFIX_fired do |event, channel=nil|
|
110
|
+
match do |_|
|
111
|
+
channel ||= subject
|
112
|
+
AFFIX_fired? event, channel
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
|
117
|
+
module Wires
|
118
|
+
module Test
|
119
|
+
module RSpec
|
120
|
+
module ExampleGroupMethods
|
65
121
|
|
66
|
-
|
67
|
-
|
122
|
+
def with_AFFIX_stimulus(event, **kwargs, &block)
|
123
|
+
context "(with stimulus #{event.inspect})" do
|
124
|
+
include_context "with AFFIX wires stimulus", event, **kwargs
|
125
|
+
instance_eval &block
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def it_AFFIX_fires(event, **kwargs, &block)
|
130
|
+
context "fires #{event.inspect}" do
|
131
|
+
specify do
|
132
|
+
channel_obj = AFFIX_wires_test_channel_from_kwargs **kwargs
|
133
|
+
expect(AFFIX_fired?(event, channel_obj, &block)).to be
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def it_AFFIX_fires_no(event, **kwargs, &block)
|
139
|
+
context "fires no #{event.inspect}" do
|
140
|
+
specify do
|
141
|
+
channel_obj = AFFIX_wires_test_channel_from_kwargs **kwargs
|
142
|
+
expect(AFFIX_fired?(event, channel_obj, &block)).to_not be
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
68
147
|
end
|
69
148
|
end
|
70
|
-
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
-END OF IMPLEMENTATION
|
153
|
+
.gsub(/AFFIX[_ ]/, "") # Remove all AFFIX markers (see Wires::Test.build_alt)
|
154
|
+
.tap { |code| eval code } # Eval the cleaned code in
|
155
|
+
|
156
|
+
|
157
|
+
RSpec.configuration.extend Wires::Test::RSpec::ExampleGroupMethods
|
158
|
+
|
159
|
+
|
160
|
+
module Wires
|
161
|
+
module Test
|
71
162
|
# Build an alternate version of Test for an alternate Wires module
|
72
163
|
# Optionally, specify an affix to be used in method names;
|
73
164
|
# This helps to differentiate from the original Helper
|
74
165
|
def self.build_alt(wires_module_path, affix:nil)
|
75
|
-
affix = affix.to_s
|
166
|
+
affix = affix ? affix.to_s+'_' : ''
|
76
167
|
|
77
168
|
[__FILE__] # List of files to mutate and eval
|
78
169
|
.map { |file| File.read file }
|
79
170
|
.each do |code|
|
80
171
|
|
81
|
-
code
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
+ [:@received_wires_events]
|
87
|
-
|
88
|
-
mutated_names.each do |meth|
|
89
|
-
meth = meth.to_s
|
90
|
-
sys_meth = meth.gsub /([^_]+)$/, "#{affix}_\\1"
|
91
|
-
code.gsub!(meth, sys_meth)
|
92
|
-
end if affix
|
172
|
+
code =~ /(?<='-END OF IMPLEMENTATION').*?(?=-END OF IMPLEMENTATION)/m
|
173
|
+
code = $&
|
174
|
+
|
175
|
+
code.gsub! /Wires/, "#{wires_module_path}"
|
176
|
+
code.gsub! /AFFIX[_ ]/, affix
|
93
177
|
|
94
178
|
eval code
|
95
179
|
end
|
96
180
|
end
|
97
|
-
|
98
|
-
class Unit < ::Minitest::Unit; include Helper; end
|
99
|
-
class Spec < ::Minitest::Spec; include Helper; end
|
100
181
|
end
|
101
|
-
|
102
|
-
end
|
182
|
+
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.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joe McIlvain
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: wires
|
@@ -16,30 +16,30 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.5.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: 0.5.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
34
|
-
type: :
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: fivemat
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
@@ -72,12 +72,11 @@ executables: []
|
|
72
72
|
extensions: []
|
73
73
|
extra_rdoc_files: []
|
74
74
|
files:
|
75
|
-
- lib/wires/test/minitest.rb
|
76
75
|
- lib/wires/test.rb
|
77
76
|
- LICENSE
|
78
77
|
homepage: https://github.com/jemc/wires-test/
|
79
78
|
licenses:
|
80
|
-
-
|
79
|
+
- Copyright 2013 Joe McIlvain. All rights reserved.
|
81
80
|
metadata: {}
|
82
81
|
post_install_message:
|
83
82
|
rdoc_options: []
|
@@ -100,3 +99,4 @@ signing_key:
|
|
100
99
|
specification_version: 4
|
101
100
|
summary: wires-test
|
102
101
|
test_files: []
|
102
|
+
has_rdoc:
|
data/lib/wires/test/minitest.rb
DELETED