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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aabc80d88b58884367f206fb948310569b1fb749ca02502ee8eab2134796087e
4
- data.tar.gz: d72ec949930e7dd4defa37adf0a9ec2b704f31b266e4388a5502eb7d77128e7d
3
+ metadata.gz: 6e5007cd9d3b6e90cecb29ab78442d92c6d432f11b0d2582fccee8fc44a44fc0
4
+ data.tar.gz: 2708ff35d5702618f6a50129748de02b20d90085fa260f24e3646f5bfd88c231
5
5
  SHA512:
6
- metadata.gz: 0ebb5d820fb13dfc3b769dd0f79b35ae6580144ed604ac452d484c1b18f4b8c546759c1e73fe583af52ac3f67090b63f12d5f807e61976f488239090d72f2a70
7
- data.tar.gz: 13104f7a6e153d809109db370ebd44e9b6708f30abe4093a5970bc90326e96ee3c2454bbcdf30480f2a73dcc493565b19d0361a27f00263ae0b970b8aad869c2
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
@@ -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
- # Hoist the method variable outside of the block below so we can access it afterwards
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); end
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inline_tests
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Brown