micro_test 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -3,6 +3,3 @@ source :rubygems
3
3
  gem "slop"
4
4
  gem "pry"
5
5
  gem "pry-stack_explorer"
6
- gem "pry-exception_explorer"
7
- gem "pry-remote"
8
- gem "coderay"
data/Gemfile.lock CHANGED
@@ -8,11 +8,6 @@ GEM
8
8
  coderay (~> 1.0.5)
9
9
  method_source (~> 0.8)
10
10
  slop (~> 3.3.1)
11
- pry-exception_explorer (0.1.9)
12
- pry-stack_explorer (>= 0.3.9)
13
- pry-remote (0.1.6)
14
- pry (~> 0.9)
15
- slop (~> 3.0)
16
11
  pry-stack_explorer (0.4.6)
17
12
  binding_of_caller (~> 0.6.2)
18
13
  slop (3.3.3)
@@ -21,9 +16,6 @@ PLATFORMS
21
16
  ruby
22
17
 
23
18
  DEPENDENCIES
24
- coderay
25
19
  pry
26
- pry-exception_explorer
27
- pry-remote
28
20
  pry-stack_explorer
29
21
  slop
data/bin/mt CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
  require "slop"
3
- require File.expand_path(File.join(File.dirname(__FILE__), "..", "lib", "micro_test"))
4
- require File.expand_path(File.join(File.dirname(__FILE__), "..", "lib", "micro_test", "color"))
3
+ lib_path = File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
4
+ require File.join(lib_path, "micro_test")
5
+ require File.join(lib_path, "micro_test", "color")
5
6
 
6
7
  include MicroTest::Color
7
8
 
@@ -26,11 +27,13 @@ end
26
27
  if path =~ /\.rb$/
27
28
  require path
28
29
  else
29
- Dir[File.join(path, "**", "*.rb")].each { |p| require p }
30
+ Dir[File.join(path, "**", "*.rb")].each do |p|
31
+ require p unless p =~ /fail\.rb$/ && opts[:demo].nil?
32
+ end
30
33
  end
31
34
 
32
35
  formatter_name = opts[:formatter] || "default"
33
- formatter_path = File.expand_path(File.join(File.dirname(__FILE__), "..", "lib", "micro_test", "formatters", formatter_name + ".rb"))
36
+ formatter_path = File.join(lib_path, "micro_test", "formatters", formatter_name + ".rb")
34
37
  unless File.exist?(formatter_path)
35
38
  puts "#{formatter_path} not found."
36
39
  puts "Please check the formatter name and try again."
@@ -49,7 +52,8 @@ MicroTest::PRY = !!opts[:pry]
49
52
  if MicroTest::PRY
50
53
  require "pry"
51
54
  require "pry-stack_explorer"
52
- # require "pry-exception_explorer"
55
+ $micro_test_demo = true
56
+
53
57
  Pry.config.hooks.add_hook :before_session, :print_instructions do
54
58
  puts "".rjust(80, "-")
55
59
  puts "#{MicroTest::Runner.current_test} #{red "FAIL"}"
@@ -58,10 +62,6 @@ if MicroTest::PRY
58
62
  puts " #{magenta "whereami 10"} for more context"
59
63
  puts " #{magenta "edit-method"} to make the fix"
60
64
  end
61
- # EE.enabled = true
62
- # EE.intercept do |frame , ex|
63
- # !ex.is_a?(LoadError)
64
- # end
65
65
  end
66
66
 
67
67
  MicroTest::Runner.run formatter
@@ -4,7 +4,7 @@ module MicroTest
4
4
  attr_reader :current_test
5
5
 
6
6
  def update(event, arg)
7
- send event, arg
7
+ send(event, arg) if respond_to?(event)
8
8
  end
9
9
 
10
10
  def add_test_class(klass)
data/test/test_fail.rb ADDED
@@ -0,0 +1,14 @@
1
+ class Fail < MicroTest::Test
2
+
3
+ before :each do
4
+ @var = "fubar"
5
+ end
6
+
7
+ test "fail" do
8
+ # Failing on purpose for the demo.
9
+ # Use pry to check out the current binding.
10
+ # For example, type @var.
11
+ assert false
12
+ end
13
+
14
+ end
@@ -0,0 +1,35 @@
1
+ class TestRunner < MicroTest::Test
2
+
3
+ test "interface" do
4
+ assert MicroTest::Runner.respond_to?(:current_test)
5
+ assert MicroTest::Runner.respond_to?(:add_test_class)
6
+ assert MicroTest::Runner.respond_to?(:test_classes)
7
+ assert MicroTest::Runner.respond_to?(:file)
8
+ assert MicroTest::Runner.respond_to?(:file_info)
9
+ assert MicroTest::Runner.respond_to?(:assert)
10
+ assert MicroTest::Runner.respond_to?(:run)
11
+ end
12
+
13
+ test "add_test_class" do
14
+ t = Class.new(MicroTest::Test)
15
+ assert MicroTest::Runner.test_classes.include?(t)
16
+ end
17
+
18
+ test "file" do
19
+ f = MicroTest::Runner.file(__FILE__)
20
+ assert f.is_a?(Array)
21
+ end
22
+
23
+ test "file_info" do
24
+ info = MicroTest::Runner.file_info caller[0]
25
+ assert info[:file].is_a?(Array)
26
+ assert info[:line_num].is_a?(Numeric)
27
+ assert info[:path] =~ /.*lib\/micro_test\/runner\.rb$/
28
+ assert info[:line] == "test_class.tests[desc].call"
29
+ end
30
+
31
+ test "current_test" do
32
+ assert MicroTest::Runner.current_test == "TestRunner -> test current_test"
33
+ end
34
+
35
+ end
data/test/test_test.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  class TestTest < MicroTest::Test
2
2
 
3
- before :all do
3
+ before :each do
4
4
  @Test = Class.new(MicroTest::Test)
5
5
  end
6
6
 
@@ -22,6 +22,32 @@ class TestTest < MicroTest::Test
22
22
  assert @Test.callbacks[:after].is_a?(Hash)
23
23
  end
24
24
 
25
+ test "notify" do
26
+ observer = Class.new do
27
+ def update(event, arg)
28
+ (@events ||= {})[event] = arg
29
+ end
30
+ end
31
+ o = observer.new
32
+ MicroTest::Test.add_observer o
33
+ MicroTest::Test.notify(:foo, :bar)
34
+ events = o.instance_eval { @events }
35
+ assert events[:foo] == :bar
36
+ end
37
+
38
+ test "notification when inherited" do
39
+ observer = Class.new do
40
+ def update(event, arg)
41
+ (@events ||= {})[event] = arg
42
+ end
43
+ end
44
+ o = observer.new
45
+ MicroTest::Test.add_observer o
46
+ t = Class.new(MicroTest::Test)
47
+ events = o.instance_eval { @events }
48
+ assert events[:add_test_class] == t
49
+ end
50
+
25
51
  test "callbacks" do
26
52
  a = lambda {}
27
53
  b = lambda {}
@@ -37,11 +63,55 @@ class TestTest < MicroTest::Test
37
63
  assert @Test.callbacks[:after][:all].equal?(d)
38
64
  end
39
65
 
40
- test "failure" do
41
- # Failing on purpose for the demo.
42
- # Use pry to check out the current binding.
43
- # For example, type @Test.
44
- assert false
66
+ test "invoke callbacks" do
67
+ before_all = false
68
+ before_each = false
69
+ after_each = false
70
+ after_all = false
71
+ @Test.before(:all) { before_all = true }
72
+ @Test.before(:each) { before_each = true }
73
+ @Test.after(:each) { after_each = true }
74
+ @Test.after(:all) { after_all = true }
75
+ @Test.invoke(:before, :all)
76
+ @Test.invoke(:before, :each)
77
+ @Test.invoke(:after, :each)
78
+ @Test.invoke(:after, :all)
79
+ assert before_all
80
+ assert before_each
81
+ assert after_each
82
+ assert after_all
83
+ end
84
+
85
+ test "tests" do
86
+ assert MicroTest::Test.tests.is_a?(Hash)
87
+ end
88
+
89
+ test "add tests" do
90
+ a = lambda {}
91
+ b = lambda {}
92
+ c = lambda {}
93
+ @Test.test("a", &a)
94
+ @Test.test("b", &b)
95
+ @Test.test("c", &c)
96
+ assert @Test.tests["a"].equal?(a)
97
+ assert @Test.tests["b"].equal?(b)
98
+ assert @Test.tests["c"].equal?(c)
99
+ end
100
+
101
+ test "assert" do
102
+ observer = Class.new do
103
+ def update(event, arg)
104
+ (@events ||= {})[event] = arg
105
+ end
106
+ end
107
+ o = observer.new
108
+ MicroTest::Test.add_observer o
109
+ @Test.test "assert test" do
110
+ assert true
111
+ end
112
+ @Test.tests["assert test"].call
113
+ events = o.instance_eval { @events }
114
+ assert events[:assert] == true
45
115
  end
46
116
 
47
117
  end
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.1.7
4
+ version: 0.1.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-03 00:00:00.000000000 Z
12
+ date: 2012-10-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: slop
@@ -76,7 +76,8 @@ files:
76
76
  - lib/micro_test/test.rb
77
77
  - lib/micro_test.rb
78
78
  - bin/mt
79
- - test/math.rb
79
+ - test/test_fail.rb
80
+ - test/test_runner.rb
80
81
  - test/test_test.rb
81
82
  - Gemfile
82
83
  - Gemfile.lock
data/test/math.rb DELETED
@@ -1,45 +0,0 @@
1
- # # /example/test/math_test.rb
2
- # class MathTest < MicroTest::Test
3
-
4
- # before :all do
5
- # # puts "runs once before all tests"
6
- # end
7
-
8
- # before :each do
9
- # # puts "runs before each test"
10
- # end
11
-
12
- # test "addition" do
13
- # assert 2 + 2 == 4
14
- # end
15
-
16
- # test "subtraction" do
17
- # assert 2 - 2 == 0
18
- # end
19
-
20
- # test "multiplication" do
21
- # assert 2 * 2 == 4
22
- # end
23
-
24
- # test "division" do
25
- # assert 2 / 2 == 1 # add a trailing comment if you want a message
26
- # end
27
-
28
- # # and one failing test
29
- # test "fail" do
30
- # assert 2 + 2 == 5
31
- # end
32
-
33
- # # test "error" do
34
- # # assert 1 / 0 == 0
35
- # # end
36
-
37
- # after :each do
38
- # # puts "runs after each test"
39
- # end
40
-
41
- # after :all do
42
- # # puts "runs once after all tests"
43
- # end
44
-
45
- # end