wires-test 0.0.5 → 0.0.6
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/minitest.rb +2 -0
- data/lib/wires/test.rb +53 -13
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3028d08f961e119349b80c44ab1809c333d95066
|
4
|
+
data.tar.gz: cb913b720f705ecf252ae37930823b026235c76a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2344202069fc523a21a7eb67c125f8a39203c428341b3dcc168472b2dbe6b4420c6eac08596af93ccc0cecb77f86b122db79ab94770e93fa7d2498eb06ddc46e
|
7
|
+
data.tar.gz: 423b169d738c321b5ef677aae9370c417dcab1a1ff00386f97d8bce70b0ca5857cde357895333feb7b515b22f1eb966c24e199a4cf5eedfbdf96dc7ff1bfb3d9
|
data/lib/wires/test.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
|
2
|
+
begin
|
3
|
+
require_relative 'test/minitest'
|
4
|
+
end unless __FILE__=="(eval)"
|
3
5
|
|
4
6
|
|
5
7
|
module Wires
|
@@ -7,7 +9,7 @@ module Wires
|
|
7
9
|
module Test
|
8
10
|
|
9
11
|
module Helper
|
10
|
-
|
12
|
+
|
11
13
|
def before_setup
|
12
14
|
@received_wires_events = []
|
13
15
|
Channel.before_fire { |e,c| @received_wires_events << [e,c] }
|
@@ -19,23 +21,34 @@ module Wires
|
|
19
21
|
clear_fired
|
20
22
|
end
|
21
23
|
|
22
|
-
def fired?(event,channel=self,
|
23
|
-
|
24
|
+
def fired?(event, channel=self,
|
25
|
+
clear:false, exclusive:false, plurality:nil,
|
26
|
+
exact_event:false, exact_channel:false)
|
27
|
+
key_chan = Channel[channel] unless channel.is_a? Channel
|
24
28
|
key_event = Event.new_from event
|
25
|
-
|
29
|
+
|
30
|
+
case key_event.count
|
31
|
+
when 0
|
32
|
+
raise ArgumentError,"Can't create an event from input: #{input.inspect}"
|
33
|
+
when 1
|
34
|
+
key_event = key_event.first
|
35
|
+
else
|
36
|
+
raise ArgumentError,"Can't check for fired? on multiple events: #{key_event.inspect}"
|
37
|
+
end
|
26
38
|
|
27
39
|
results = @received_wires_events.select { |e,c|
|
28
|
-
(exact_event ? (key_event.
|
29
|
-
(exact_channel ? (key_chan === c)
|
40
|
+
(exact_event ? (key_event.event_type == e.event_type) : (key_event =~ e)) and
|
41
|
+
(exact_channel ? (key_chan === c) : (key_chan =~ c))
|
30
42
|
}
|
31
43
|
|
32
44
|
clear_fired if clear
|
33
45
|
|
34
46
|
return false if results.empty?
|
35
47
|
return false if exclusive and (@received_wires_events != results)
|
36
|
-
return false if plurality
|
48
|
+
return false if plurality and (results.size != plurality)
|
37
49
|
|
38
|
-
|
50
|
+
# Execute passed block for each match
|
51
|
+
results.each { |e,c| yield e,c if block_given? }
|
39
52
|
|
40
53
|
true
|
41
54
|
end
|
@@ -55,10 +68,37 @@ module Wires
|
|
55
68
|
def clear_fired
|
56
69
|
@received_wires_events.clear
|
57
70
|
end
|
71
|
+
|
72
|
+
# Build an alternate version of Helper for an alternate Wires module
|
73
|
+
# Optionally, specify an affix to be used in method names;
|
74
|
+
# This helps to differentiate from the original Helper
|
75
|
+
def self.build_alt(wires_module_path, affix:nil)
|
76
|
+
affix = affix.to_s if affix
|
77
|
+
|
78
|
+
[__FILE__] # List of files to mutate and eval
|
79
|
+
.map { |file| File.read file }
|
80
|
+
.each do |code|
|
81
|
+
|
82
|
+
code.gsub!(/Wires/, "#{wires_module_path}")
|
83
|
+
|
84
|
+
mutated_names =
|
85
|
+
instance_methods \
|
86
|
+
- [:before_setup, :after_teardown] \
|
87
|
+
+ [:@received_wires_events]
|
88
|
+
|
89
|
+
mutated_names.each do |meth|
|
90
|
+
meth = meth.to_s
|
91
|
+
sys_meth = meth.gsub /([^_]+)$/, "#{affix}_\\1"
|
92
|
+
code.gsub!(meth, sys_meth)
|
93
|
+
end if affix
|
94
|
+
|
95
|
+
eval code
|
96
|
+
end
|
97
|
+
end
|
58
98
|
end
|
59
|
-
|
60
|
-
class Unit < Minitest::Unit; include Test::Helper; end
|
61
|
-
class Spec < Minitest::Spec; include Test::Helper; end
|
99
|
+
|
100
|
+
class Unit < ::Minitest::Unit; include Test::Helper; end
|
101
|
+
class Spec < ::Minitest::Spec; include Test::Helper; end
|
62
102
|
end
|
63
103
|
|
64
104
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joe McIlvain
|
@@ -72,6 +72,7 @@ executables: []
|
|
72
72
|
extensions: []
|
73
73
|
extra_rdoc_files: []
|
74
74
|
files:
|
75
|
+
- lib/wires/test/minitest.rb
|
75
76
|
- lib/wires/test.rb
|
76
77
|
- LICENSE
|
77
78
|
homepage: https://github.com/jemc/wires-test/
|