inline_tests 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/inline_tests.rb +3 -0
- data/lib/kernel_extensions.rb +33 -28
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e5007cd9d3b6e90cecb29ab78442d92c6d432f11b0d2582fccee8fc44a44fc0
|
4
|
+
data.tar.gz: 2708ff35d5702618f6a50129748de02b20d90085fa260f24e3646f5bfd88c231
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f485181a194aec4f7ef249ba5ab5ecd18906bdfbf08cd02993b2b0caa8021c40835ef5fe7d7c798444fe805734bf402a3ecaa0c492757c24fe075fa1d7f549f
|
7
|
+
data.tar.gz: b267f48ed6bc5107e248d7d41fed6885faae502bf93f21a5e24022b6353c544fde19dbcc2ad7212076ff70022e91decff65d175e82bf74315be51b0257d1b26e
|
data/lib/inline_tests.rb
CHANGED
@@ -61,6 +61,9 @@ class InlineTests
|
|
61
61
|
puts "#{METHODS_WITH_INLINE_TESTS.count} inline tests ran in #{format_tiny_time all_tests_end_time - all_tests_start_time} seconds."
|
62
62
|
puts " #{test_passes} PASSED"
|
63
63
|
puts " #{test_fails} FAILS"
|
64
|
+
puts
|
65
|
+
puts "#{METHODS_THAT_NEED_TESTS.count} methods still need tests:"
|
66
|
+
METHODS_THAT_NEED_TESTS.each {|method| puts " #{method.inspect}"}
|
64
67
|
end
|
65
68
|
|
66
69
|
private
|
data/lib/kernel_extensions.rb
CHANGED
@@ -1,38 +1,13 @@
|
|
1
1
|
module Kernel
|
2
2
|
METHODS_WITH_INLINE_TESTS = []
|
3
|
+
METHODS_THAT_NEED_TESTS = []
|
3
4
|
|
4
5
|
RUN_TESTS_IN_THIS_ENVIRONMENT = true
|
5
6
|
|
6
7
|
def tested(method_name, _ignored, &inline_test_block)
|
7
8
|
return unless RUN_TESTS_IN_THIS_ENVIRONMENT
|
8
9
|
|
9
|
-
|
10
|
-
method = nil
|
11
|
-
|
12
|
-
# The method definition exists in a different scope dependent on whether we're in a class or not.
|
13
|
-
if self.class.name === Object.name
|
14
|
-
# We're in `main` scope
|
15
|
-
method = method(method_name)
|
16
|
-
|
17
|
-
elsif self.class.name == Class.name
|
18
|
-
# We're in a class -- hunt for that method
|
19
|
-
|
20
|
-
if instance_methods.include?(method_name)
|
21
|
-
method = self.instance_method(method_name)
|
22
|
-
|
23
|
-
# Since the method is defined at script startup, it's an UnboundMethod until there's an instance to
|
24
|
-
# call it on. Obviously, need an instance to call it from during a test anyway, so we bind one here
|
25
|
-
# manually.
|
26
|
-
# TODO: this would be a great place to read defaults for some classes and apply attributes/defaults
|
27
|
-
# upon creation
|
28
|
-
instance = self.new
|
29
|
-
method = method.bind(instance)
|
30
|
-
|
31
|
-
elsif self.singleton_class.instance_methods.include?(method_name)
|
32
|
-
method = self.singleton_class.instance_method(method_name).bind(self)
|
33
|
-
|
34
|
-
end
|
35
|
-
end
|
10
|
+
method = method_ref(method_name)
|
36
11
|
|
37
12
|
# Register the method's tests to be run with InlineTests
|
38
13
|
method.inline_tests = inline_test_block
|
@@ -43,7 +18,10 @@ module Kernel
|
|
43
18
|
def tests; end
|
44
19
|
|
45
20
|
# This is just syntax sugar for decorating methods that are untested / need tests
|
46
|
-
def untested(method_name)
|
21
|
+
def untested(method_name)
|
22
|
+
method = method_ref(method_name)
|
23
|
+
METHODS_THAT_NEED_TESTS.push method
|
24
|
+
end
|
47
25
|
|
48
26
|
def assert(some_statement, description = '')
|
49
27
|
passed = !!some_statement
|
@@ -96,6 +74,33 @@ module Kernel
|
|
96
74
|
|
97
75
|
private
|
98
76
|
|
77
|
+
def method_ref(method_name)
|
78
|
+
# The method definition exists in a different scope dependent on whether we're in a class or not.
|
79
|
+
if self.class.name === Object.name
|
80
|
+
# We're in `main` scope
|
81
|
+
method(method_name)
|
82
|
+
|
83
|
+
elsif self.class.name == Class.name
|
84
|
+
# We're in a class -- hunt for that method
|
85
|
+
|
86
|
+
if instance_methods.include?(method_name)
|
87
|
+
method = self.instance_method(method_name)
|
88
|
+
|
89
|
+
# Since the method is defined at script startup, it's an UnboundMethod until there's an instance to
|
90
|
+
# call it on. Obviously, need an instance to call it from during a test anyway, so we bind one here
|
91
|
+
# manually.
|
92
|
+
# TODO: this would be a great place to read defaults for some classes and apply attributes/defaults
|
93
|
+
# upon creation
|
94
|
+
instance = self.new
|
95
|
+
method.bind(instance)
|
96
|
+
|
97
|
+
elsif self.singleton_class.instance_methods.include?(method_name)
|
98
|
+
self.singleton_class.instance_method(method_name).bind(self)
|
99
|
+
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
99
104
|
def flexible_assert(lhs, rhs, assert_logic)
|
100
105
|
lhs_values = lhs
|
101
106
|
# todo: probably want a custom testresults class instead of hash
|