micro_test 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -9,7 +9,7 @@ MicroTest avoids this pitfall with a relentless focus on simplicity.
9
9
 
10
10
  * A simple test API/interface
11
11
  * An awesome test + dev workflow using Pry
12
- * Fast asynchronous test runs with Celluloid
12
+ * Fast asynchronous test runs
13
13
 
14
14
  ## The Interface
15
15
 
@@ -99,4 +99,8 @@ Try some of the more advanced features.
99
99
  MicroTest is small & unobtrusive. It can run parallel with other test frameworks,
100
100
  and can be introduced to existing projects with minimal effort.
101
101
 
102
+ ## Advanced
103
+
104
+ [See the wiki](https://github.com/hopsoft/micro_test/wiki) to troubleshoot or dig into more advanced topics.
105
+
102
106
  Start testing today!
@@ -15,6 +15,7 @@ module MicroTest
15
15
  puts test_class.name.ljust(80, "-")
16
16
 
17
17
  test_class.tests.each do |test|
18
+ next unless test.finished?
18
19
  duration = (test.duration * 10**4).round.to_f / 10**4
19
20
  print yellow(" #{duration.to_s.ljust(6, "0")}")
20
21
 
@@ -1,3 +1,6 @@
1
+ require "os"
2
+ require "thread"
3
+
1
4
  module MicroTest
2
5
  class Runner
3
6
  class << self
@@ -21,10 +24,10 @@ module MicroTest
21
24
  test_classes.each do |test_class|
22
25
  formatter.before_class(test_class)
23
26
  test_class.tests.shuffle.each do |test|
24
- stop && exit if MicroTest::Runner.exit
25
27
  @active_test = test
26
- if options[:async]
27
- test.async.invoke(@formatter, @options)
28
+ if @options[:async]
29
+ @tests ||= Queue.new
30
+ @tests << test
28
31
  else
29
32
  test.invoke(@formatter, @options)
30
33
  end
@@ -32,7 +35,8 @@ module MicroTest
32
35
  formatter.after_class(test_class)
33
36
  end
34
37
 
35
- sleep 0.1 while !finished?(tests)
38
+ run_threads if @options[:async]
39
+
36
40
  @duration = Time.now - start
37
41
  @passed = tests.select{ |test| test.passed? }.count
38
42
  @failed = tests.select{ |test| !test.passed? }.count
@@ -40,25 +44,28 @@ module MicroTest
40
44
  formatter.after_suite(test_classes)
41
45
  end
42
46
 
43
- def stop
44
- MicroTest::Test.subclasses.each do |subclass|
45
- subclass.tests.each { |test| test.terminate }
46
- end
47
- puts
48
- sleep 0.5
49
- true
50
- end
51
-
52
47
  def reset
53
48
  @duration = 0
54
49
  @passed = 0
55
50
  @failed = 0
56
51
  end
57
52
 
58
- private
53
+ protected
59
54
 
60
- def finished?(tests)
61
- tests.empty? || tests.map{ |test| test.finished? }.uniq == [true]
55
+ def run_threads
56
+ threads = []
57
+ thread_count = OS.cpu_count
58
+ thread_count = 2 if thread_count < 2
59
+ puts "MicroTest is running #{thread_count} threads."
60
+ thread_count.times do
61
+ threads << Thread.new do
62
+ while @tests.empty? == false
63
+ Thread.current.kill if MicroTest::Runner.exit
64
+ @tests.pop.invoke(@formatter, @options)
65
+ end
66
+ end
67
+ end
68
+ threads.each { |t| t.join }
62
69
  end
63
70
 
64
71
  end
@@ -1,10 +1,8 @@
1
1
  module MicroTest
2
2
 
3
3
  # A wrapper class for individual tests.
4
- # Exists for the purpose of isolating the test method inside of a
5
- # Celluloid Actor to support asynchronous test runs.
4
+ # Exists for the purpose of isolating the test method so it can run in its own thread.
6
5
  class TestWrapper
7
- include Celluloid
8
6
  attr_reader :test_class, :desc, :asserts, :duration
9
7
 
10
8
  # Constructor.
@@ -62,8 +60,8 @@ module MicroTest
62
60
 
63
61
  if !value
64
62
  binding.pry(:quiet => true) if @options[:pry]
63
+
65
64
  # I don't really like the coupling to the runner here
66
- # but I couldn't get an observer to work with celluloid & pry
67
65
  MicroTest::Runner.exit = true if @options[:fail_fast]
68
66
  end
69
67
 
@@ -1,3 +1,3 @@
1
1
  module MicroTest
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
data/lib/micro_test.rb CHANGED
@@ -1,3 +1,2 @@
1
- require "celluloid"
2
1
  path = File.join(File.dirname(__FILE__), "micro_test", "*.rb")
3
2
  Dir[path].each { |file| require file }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: micro_test
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,10 +9,10 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-24 00:00:00.000000000 Z
12
+ date: 2012-11-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: celluloid
15
+ name: os
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
@@ -28,7 +28,7 @@ dependencies:
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
30
  description: ! " Simple test API.\n Awesome test/dev workflow with pry.\n Asynchronous
31
- test runs with celluloid.\n What more could you want?\n"
31
+ test runs.\n What more could you want?\n"
32
32
  email:
33
33
  - natehop@gmail.com
34
34
  executables: