micro_test 0.4.0 → 0.4.1

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: 775d8a6619af17df32d4d5ae13f62a5dd8f84d60
4
- data.tar.gz: 02b1f437f7b5620cc7b0afd34d62bca05d7a04e5
3
+ metadata.gz: 95b18d1f0d146dbda392fada14c0d687ee85b703
4
+ data.tar.gz: 34d42a85bac2b5eb1c909383fdd92068f3f4c5ab
5
5
  SHA512:
6
- metadata.gz: 10bfa9df02a1e8c96474c532939d7ae688f446e1676d529d0bfb06cd9567fb995449a9edac7f31b8658f9ffd7851c21a2423569be7b497ad7846add1bfd03515
7
- data.tar.gz: 6047106158516aa8af7ab474926ce7857ad6d3b7bcd6d21dc040fdc5dfec9e4d97c20abfc1cc1e492374480b616029bca379ed1c1f4f9da2c038a15060fa00db
6
+ metadata.gz: 56ecea611b376a6ad4f02e457b722597dc340a85597c96409a3769816812479909bbc1514837e0cd585bee5073f3e28b9cf9fe00f769786ac90983daf20f0b04
7
+ data.tar.gz: 0d983415c067420fbb43ba964695576a099d56e1fbcf1a3061f709e426a59a1651d2f9a2383f3800d9d8aca968e96e6a06946403f93fac5ed35194628b5248d3
data/bin/mt CHANGED
@@ -6,15 +6,7 @@ require File.join(lib_path, "micro_test")
6
6
  include MicroTest::Color
7
7
 
8
8
  # setup the formatters list ---------------------------------------------------
9
- formatters_path = File.join(lib_path, "micro_test", "formatters")
10
- formatter_names = Dir[File.join(formatters_path, "*.rb")].reduce([]) do |memo, file|
11
- if (file =~ /(base_formatter\.rb|_async\.rb)$/).nil?
12
- name = file[file.rindex("/") + 1..-4]
13
- name = "*#{name}" if name == "mt"
14
- memo << name
15
- end
16
- memo
17
- end
9
+ formatter_names = MicroTest.formatters.map(&:short_name).sort
18
10
 
19
11
  # setup the options -----------------------------------------------------------
20
12
  options = {}
@@ -91,28 +83,11 @@ else
91
83
  end
92
84
 
93
85
  # setup the formatter ---------------------------------------------------------
94
- formatter_name = options[:formatter] || "mt"
95
- path = File.join(formatters_path, formatter_name + ".rb")
96
- if options[:async]
97
- async_path = path.gsub(/\.rb$/, "_async.rb")
98
- path = async_path if File.exist?(async_path)
99
- end
100
- unless File.exist?(path)
101
- puts "Formatter not found at #{path}"
102
- puts "Please check the formatter name and try again."
103
- exit 1
104
- end
105
- begin
106
- require path
107
- formatter = MicroTest.const_get("Formatter").new
108
- rescue Exception => ex
109
- puts "Failed to load the formatter defined at #{path}"
110
- puts ex.message
111
- exit 1
112
- end
86
+ formatter = MicroTest.formatters.find { |f| f.short_name == options[:formatter] }
87
+ formatter ||= MicroTest.formatters.find { |f| f.short_name == "default" }
113
88
 
114
89
  # setup the test runner -------------------------------------------------------
115
- runner = MicroTest::Runner.new(formatter, options)
90
+ runner = MicroTest::Runner.new(formatter.new, options)
116
91
 
117
92
  # setup pry -------------------------------------------------------------------
118
93
  if options[:pry]
@@ -1,2 +1,5 @@
1
- path = File.join(File.dirname(__FILE__), "micro_test", "*.rb")
1
+ path = File.expand_path("../micro_test/*.rb", __FILE__)
2
+ Dir[path].each { |file| require file }
3
+
4
+ path = File.expand_path("../micro_test/formatters/*.rb", __FILE__)
2
5
  Dir[path].each { |file| require file }
@@ -2,6 +2,12 @@ require File.join(File.dirname(__FILE__), "..", "color")
2
2
 
3
3
  module MicroTest
4
4
 
5
+ class << self
6
+ def formatters
7
+ @formatters ||= []
8
+ end
9
+ end
10
+
5
11
  # The base class for formatters.
6
12
  # Defines the API that formatters can/should implement
7
13
  # to control test run output.
@@ -9,6 +15,20 @@ module MicroTest
9
15
  include MicroTest::Color
10
16
  attr_accessor :passed, :failed, :duration
11
17
 
18
+ class << self
19
+ def inherited(subclass)
20
+ MicroTest.formatters << subclass
21
+ end
22
+
23
+ def short_name
24
+ @short_name || name
25
+ end
26
+
27
+ def set_short_name(value)
28
+ @short_name = value
29
+ end
30
+ end
31
+
12
32
  def initialize
13
33
  @duration = 0
14
34
  @passed = 0
@@ -0,0 +1,87 @@
1
+ require File.join(File.dirname(__FILE__), "base_formatter")
2
+
3
+ module MicroTest
4
+ class DefaultAsyncFormatter < MicroTest::BaseFormatter
5
+ set_short_name "default_async"
6
+
7
+ def after_test(test)
8
+ test.passed? ? print(green ".") : print(red ".")
9
+ end
10
+
11
+ def after_suite(test_classes)
12
+ puts
13
+ test_classes.each do |test_class|
14
+ print_output_for_test_class test_class
15
+ end
16
+ puts
17
+ puts "".ljust(80, "-")
18
+ print " #{passed + failed} Tests finished in #{yellow duration} seconds. "
19
+ totals = []
20
+ totals << green("#{passed} Passed") if passed > 0
21
+ totals << red("#{failed} Failed") if failed > 0
22
+ print "(#{totals.join(", ")})"
23
+ puts
24
+ puts
25
+ end
26
+
27
+ private
28
+
29
+ def print_output_for_test_class(test_class)
30
+ puts
31
+ puts test_class.name.ljust(80, "-")
32
+ test_class.tests.each do |test|
33
+ print_output_for_test test
34
+ end
35
+ end
36
+
37
+ def print_output_for_test(test)
38
+ return unless test.finished?
39
+ duration = (test.duration * 10**4).round.to_f / 10**4
40
+ print yellow(" #{duration.to_s.ljust(6, "0")}")
41
+
42
+ if test.passed?
43
+ print green(" #{test.desc}")
44
+ else
45
+ print_test_failure test
46
+ end
47
+
48
+ puts
49
+ end
50
+
51
+ def print_test_failure(test)
52
+ puts red(" #{test.desc}")
53
+ test.failed_asserts.each do |assert|
54
+ print_assert_failure assert
55
+ end
56
+ end
57
+
58
+ def print_assert_failure(assert)
59
+ puts
60
+ print "".ljust(9)
61
+ puts "#{assert[:file_path]}:#{red(assert[:line_num])}"
62
+ puts "".ljust(9) + "".rjust(71, "-")
63
+ index = assert[:line_num] - 1
64
+ start = index - 2
65
+ start = 0 if start <= 0
66
+ finish = index + 2
67
+ finish = assert[:lines].length - 1 if finish >= assert[:lines].length
68
+ print_assert_failure_lines assert, start, finish
69
+ end
70
+
71
+ def print_assert_failure_lines(assert, start, finish)
72
+ (start..finish).each do |i|
73
+ print "".ljust(9)
74
+ if i == index
75
+ print red((i + 1).to_s.rjust(3, "0"))
76
+ print red("|")
77
+ print red(assert[:lines][i])
78
+ else
79
+ print (i + 1).to_s.rjust(3, "0")
80
+ print "|"
81
+ print assert[:lines][i]
82
+ end
83
+ end
84
+ end
85
+
86
+ end
87
+ end
@@ -0,0 +1,89 @@
1
+ require File.join(File.dirname(__FILE__), "base_formatter")
2
+
3
+ module MicroTest
4
+ class DefaultFormatter < MicroTest::BaseFormatter
5
+ set_short_name "default"
6
+
7
+ def before_class(test_class)
8
+ puts
9
+ print_with_line test_class.name
10
+ end
11
+
12
+ def after_test(test)
13
+ duration = (test.duration * 10**4).round.to_f / 10**4
14
+ color = duration < 0.01 ? :yellow : :red
15
+ print send(color, " #{duration.to_s.ljust(6, "0")}")
16
+
17
+ if test.passed?
18
+ print green(" #{test.desc}")
19
+ else
20
+ print_test_failure test
21
+ end
22
+
23
+ puts
24
+ end
25
+
26
+ def after_suite(test_classes)
27
+ puts
28
+ print_line
29
+ print_totals
30
+ puts " in #{yellow duration} seconds."
31
+ print_line
32
+ puts
33
+ puts
34
+ end
35
+
36
+ private
37
+
38
+ def print_with_line(value)
39
+ puts "#{value} ".ljust(80, "-")
40
+ end
41
+
42
+ def print_line
43
+ puts "".ljust(80, "-")
44
+ end
45
+
46
+ def print_totals
47
+ totals = []
48
+ totals << green("#{passed} Passed") if passed > 0
49
+ totals << red("#{failed} Failed") if failed > 0
50
+ print totals.join(", ")
51
+ end
52
+
53
+ def print_test_failure(test)
54
+ puts red(" #{test.desc}")
55
+ test.failed_asserts.each do |assert|
56
+ print_assert_failure assert
57
+ end
58
+ end
59
+
60
+ def print_assert_failure(assert)
61
+ puts
62
+ print "".ljust(9)
63
+ puts "#{assert[:file_path]}:#{red(assert[:line_num])}"
64
+ puts "".ljust(9) + "".rjust(71, "-")
65
+ index = assert[:line_num] - 1
66
+ start = index - 2
67
+ start = 0 if start <= 0
68
+ finish = index + 2
69
+ finish = assert[:lines].length - 1 if finish >= assert[:lines].length
70
+ print_assert_failure_lines assert, start, finish
71
+ end
72
+
73
+ def print_assert_failure_lines(assert, start, finish)
74
+ (start..finish).each do |i|
75
+ print "".ljust(9)
76
+ if i == index
77
+ print red((i + 1).to_s.rjust(3, "0"))
78
+ print red("|")
79
+ print red(assert[:lines][i])
80
+ else
81
+ print (i + 1).to_s.rjust(3, "0")
82
+ print "|"
83
+ print assert[:lines][i]
84
+ end
85
+ end
86
+ end
87
+
88
+ end
89
+ end
@@ -1,7 +1,8 @@
1
1
  require File.join(File.dirname(__FILE__), "base_formatter")
2
2
 
3
3
  module MicroTest
4
- class Formatter < MicroTest::BaseFormatter
4
+ class DocFormatter < MicroTest::BaseFormatter
5
+ set_short_name "doc"
5
6
 
6
7
  def initialize
7
8
  @failures = []
@@ -1,7 +1,8 @@
1
1
  require File.join(File.dirname(__FILE__), "base_formatter")
2
2
 
3
3
  module MicroTest
4
- class Formatter < MicroTest::BaseFormatter
4
+ class DotsFormatter < MicroTest::BaseFormatter
5
+ set_short_name "dots"
5
6
 
6
7
  def after_test(test)
7
8
  print(test.passed? ? green(".") : red("."))
@@ -1,7 +1,8 @@
1
1
  require File.join(File.dirname(__FILE__), "base_formatter")
2
2
 
3
3
  module MicroTest
4
- class Formatter < MicroTest::BaseFormatter
4
+ class MinFormatter < MicroTest::BaseFormatter
5
+ set_short_name "min"
5
6
 
6
7
  def after_suite(test_classes)
7
8
  puts
@@ -1,3 +1,3 @@
1
1
  module MicroTest
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
@@ -2,7 +2,7 @@ unless ENV["MT_DEMO"]
2
2
  class TestRunner < MicroTest::Test
3
3
 
4
4
  before do
5
- @runner = MicroTest::Runner.new(MicroTest::Formatter.new)
5
+ @runner = MicroTest::Runner.new(MicroTest::DefaultFormatter.new)
6
6
  end
7
7
 
8
8
  test ".running" do
@@ -2,9 +2,10 @@ unless ENV["MT_DEMO"]
2
2
  class TestTest < MicroTest::Test
3
3
 
4
4
  before do
5
- TestTest.instance_eval { @subclasses = [] }
6
- TestTest.instance_eval { @tests = [] }
7
- @Example = Class.new(TestTest) do
5
+ @test_test = TestTest.clone
6
+ @test_test.instance_eval { @subclasses = [] }
7
+ @test_test.instance_eval { @tests = [] }
8
+ @Example = Class.new(@test_test) do
8
9
  before {}
9
10
  after {}
10
11
  test("truth") { assert true }
@@ -14,14 +15,14 @@ unless ENV["MT_DEMO"]
14
15
  end
15
16
 
16
17
  test "adds subclass" do
17
- assert TestTest.subclasses.length == 1
18
- assert TestTest.subclasses[0] == @Example
18
+ assert @test_test.subclasses.length == 1
19
+ assert @test_test.subclasses[0] == @Example
19
20
  end
20
21
 
21
22
  test "stores subclasses" do
22
- assert TestTest.subclasses.is_a?(Array)
23
- assert TestTest.subclasses.length == 1
24
- assert TestTest.subclasses.first == @Example
23
+ assert @test_test.subclasses.is_a?(Array)
24
+ assert @test_test.subclasses.length == 1
25
+ assert @test_test.subclasses.first == @Example
25
26
  end
26
27
 
27
28
  test "stores tests" do
@@ -32,8 +33,8 @@ unless ENV["MT_DEMO"]
32
33
 
33
34
  test "stores files" do
34
35
  file = __FILE__
35
- assert TestTest.files[file].is_a?(Array)
36
- assert TestTest.files[file].select{ |l| l.start_with?(" assert TestTest.files[file].select{ |l| l.start_with?(") }.length > 0
36
+ assert @test_test.files[file].is_a?(Array)
37
+ assert @test_test.files[file].select{ |l| l.start_with?(" assert @test_test.files[file].select{ |l| l.start_with?(") }.length > 0
37
38
  end
38
39
 
39
40
  test ".reset" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: micro_test
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Hopkins
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-12 00:00:00.000000000 Z
11
+ date: 2014-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: os
@@ -51,11 +51,11 @@ files:
51
51
  - ext/mkrf_conf.rb
52
52
  - lib/micro_test/color.rb
53
53
  - lib/micro_test/formatters/base_formatter.rb
54
- - lib/micro_test/formatters/doc.rb
55
- - lib/micro_test/formatters/dots.rb
56
- - lib/micro_test/formatters/min.rb
57
- - lib/micro_test/formatters/mt.rb
58
- - lib/micro_test/formatters/mt_async.rb
54
+ - lib/micro_test/formatters/default_async_formatter.rb
55
+ - lib/micro_test/formatters/default_formatter.rb
56
+ - lib/micro_test/formatters/doc_formatter.rb
57
+ - lib/micro_test/formatters/dots_formatter.rb
58
+ - lib/micro_test/formatters/min_formatter.rb
59
59
  - lib/micro_test/runner.rb
60
60
  - lib/micro_test/test.rb
61
61
  - lib/micro_test/test_wrapper.rb
@@ -69,7 +69,7 @@ files:
69
69
  - test/runner_test.rb
70
70
  - test/test_test.rb
71
71
  - test/test_wrapper_test.rb
72
- homepage: http://hopsoft.github.com/micro_test/
72
+ homepage: https://github.com/hopsoft/micro_test
73
73
  licenses:
74
74
  - MIT
75
75
  metadata: {}
@@ -102,3 +102,4 @@ test_files:
102
102
  - test/runner_test.rb
103
103
  - test/test_test.rb
104
104
  - test/test_wrapper_test.rb
105
+ has_rdoc:
@@ -1,63 +0,0 @@
1
- require File.join(File.dirname(__FILE__), "base_formatter")
2
-
3
- module MicroTest
4
- class Formatter < MicroTest::BaseFormatter
5
- def before_class(test_class)
6
- puts
7
- puts test_class.name.ljust(80, "-")
8
- end
9
-
10
- def after_test(test)
11
- duration = (test.duration * 10**4).round.to_f / 10**4
12
- if duration < 0.01
13
- print yellow(" #{duration.to_s.ljust(6, "0")}")
14
- else
15
- print red(" #{duration.to_s.ljust(6, "0")}")
16
- end
17
-
18
- if test.passed?
19
- print green(" #{test.desc}")
20
- else
21
- puts red(" #{test.desc}")
22
- test.failed_asserts.each do |assert|
23
- puts
24
- print "".ljust(9)
25
- puts "#{assert[:file_path]}:#{red(assert[:line_num])}"
26
- puts "".ljust(9) + "".rjust(71, "-")
27
- index = assert[:line_num] - 1
28
- start = index - 2
29
- start = 0 if start <= 0
30
- finish = index + 2
31
- finish = assert[:lines].length - 1 if finish >= assert[:lines].length
32
- (start..finish).each do |i|
33
- print "".ljust(9)
34
- if i == index
35
- print red((i + 1).to_s.rjust(3, "0"))
36
- print red("|")
37
- print red(assert[:lines][i])
38
- else
39
- print (i + 1).to_s.rjust(3, "0")
40
- print "|"
41
- print assert[:lines][i]
42
- end
43
- end
44
- end
45
- end
46
-
47
- puts
48
- end
49
-
50
- def after_suite(test_classes)
51
- puts
52
- puts "".ljust(80, "-")
53
- print " #{passed + failed} Tests finished in #{yellow duration} seconds. "
54
- totals = []
55
- totals << green("#{passed} Passed") if passed > 0
56
- totals << red("#{failed} Failed") if failed > 0
57
- print "(#{totals.join(", ")})"
58
- puts
59
- puts
60
- end
61
-
62
- end
63
- end
@@ -1,67 +0,0 @@
1
- require File.join(File.dirname(__FILE__), "base_formatter")
2
-
3
- module MicroTest
4
- class Formatter < MicroTest::BaseFormatter
5
-
6
- def after_test(test)
7
- test.passed? ? print(green ".") : print(red ".")
8
- end
9
-
10
- def after_suite(test_classes)
11
- puts
12
-
13
- test_classes.each do |test_class|
14
- puts
15
- puts test_class.name.ljust(80, "-")
16
-
17
- test_class.tests.each do |test|
18
- next unless test.finished?
19
- duration = (test.duration * 10**4).round.to_f / 10**4
20
- print yellow(" #{duration.to_s.ljust(6, "0")}")
21
-
22
- if test.passed?
23
- print green(" #{test.desc}")
24
- else
25
- puts red(" #{test.desc}")
26
- test.failed_asserts.each do |assert|
27
- puts
28
- print "".ljust(9)
29
- puts "#{assert[:file_path]}:#{red(assert[:line_num])}"
30
- puts "".ljust(9) + "".rjust(71, "-")
31
- index = assert[:line_num] - 1
32
- start = index - 2
33
- start = 0 if start <= 0
34
- finish = index + 2
35
- finish = assert[:lines].length - 1 if finish >= assert[:lines].length
36
- (start..finish).each do |i|
37
- print "".ljust(9)
38
- if i == index
39
- print red((i + 1).to_s.rjust(3, "0"))
40
- print red("|")
41
- print red(assert[:lines][i])
42
- else
43
- print (i + 1).to_s.rjust(3, "0")
44
- print "|"
45
- print assert[:lines][i]
46
- end
47
- end
48
- end
49
- end
50
-
51
- puts
52
- end
53
- end
54
-
55
- puts
56
- puts "".ljust(80, "-")
57
- print " #{passed + failed} Tests finished in #{yellow duration} seconds. "
58
- totals = []
59
- totals << green("#{passed} Passed") if passed > 0
60
- totals << red("#{failed} Failed") if failed > 0
61
- print "(#{totals.join(", ")})"
62
- puts
63
- puts
64
- end
65
-
66
- end
67
- end