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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1718698a58e0c296d5ea90c17e985e2b11e29066
4
- data.tar.gz: 91503847e44ceaf0515743ca5437961db0618778
3
+ metadata.gz: 3028d08f961e119349b80c44ab1809c333d95066
4
+ data.tar.gz: cb913b720f705ecf252ae37930823b026235c76a
5
5
  SHA512:
6
- metadata.gz: 50f5eda520268beb59e8b69c3609d500b16ad9243084eae51350ba72e23c8ab58c6a240ad2d93595954d5f10d181aee01260b9269480ff15ff2f4d89d3cdbc7a
7
- data.tar.gz: bcebcce1914b6af57772a2dd20660587b57e81698a78d12b6050aa205cfa35b499c26ddd75cea202e9a480f1f2827b53ce8351ee1c044e4d8daa695efc74c162
6
+ metadata.gz: 2344202069fc523a21a7eb67c125f8a39203c428341b3dcc168472b2dbe6b4420c6eac08596af93ccc0cecb77f86b122db79ab94770e93fa7d2498eb06ddc46e
7
+ data.tar.gz: 423b169d738c321b5ef677aae9370c417dcab1a1ff00386f97d8bce70b0ca5857cde357895333feb7b515b22f1eb966c24e199a4cf5eedfbdf96dc7ff1bfb3d9
@@ -0,0 +1,2 @@
1
+ gem 'minitest', '~> 4.3.2'
2
+ require 'minitest/autorun'
data/lib/wires/test.rb CHANGED
@@ -1,5 +1,7 @@
1
- gem 'minitest', '~> 4.3.2'
2
- require 'minitest/autorun'
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, clear:false, exclusive:false, plurality:nil,
23
- exact_event:false, exact_channel:false, &block)
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
- key_chan = Channel.new channel
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.class == e.class) : (key_event =~ e)) and
29
- (exact_channel ? (key_chan === c) : (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 and (results.size != plurality)
48
+ return false if plurality and (results.size != plurality)
37
49
 
38
- results.each(&block) # Execute passed block for each match
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.5
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/