jakewendt-test_with_verbosity 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/test_with_verbosity.rb +63 -32
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d0d01ad45aa02b869c69d0158eebbd9d2f4e4855
|
4
|
+
data.tar.gz: 5b1f40af682e43a5d90733fac1b27d7bb6ad7628
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0347b201d1362727d7271689d615ae4d71fde647ffdab1ef7ada6f101e2da865339237df6f2391045ff66649d29d43b5fa98e2110a75d909c6a648f1f9d51087
|
7
|
+
data.tar.gz: 8bb2373ea9e3b619a591f5016a80b499b1e7a9e259f3bb989687fbde4458a4d1c1a192ec4cbecdce46428f29511734068fa3fc3b4f3d12ea08b9ef6feb5b7f61
|
data/lib/test_with_verbosity.rb
CHANGED
@@ -4,33 +4,40 @@ module JakeWendt::TestWithVerbosity
|
|
4
4
|
def self.included(base)
|
5
5
|
base.extend(ClassMethods)
|
6
6
|
|
7
|
-
base.class_eval do
|
8
|
-
class << self
|
9
|
-
alias_method_chain( :test, :verbosity
|
10
|
-
) unless method_defined?(:test_without_verbosity)
|
11
|
-
end
|
12
|
-
end #unless base.respond_to?(:test_without_verbosity)
|
7
|
+
# base.class_eval do
|
8
|
+
# class << self
|
9
|
+
# alias_method_chain( :test, :verbosity
|
10
|
+
# ) unless method_defined?(:test_without_verbosity)
|
11
|
+
# end
|
12
|
+
# end #unless base.respond_to?(:test_without_verbosity)
|
13
13
|
end
|
14
14
|
|
15
15
|
module ClassMethods
|
16
16
|
|
17
17
|
# activesupport-4.1.4/lib/active_support/testing/declarative.rb
|
18
|
+
# my modified version
|
18
19
|
def test(name, &block)
|
19
20
|
#test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym
|
20
21
|
test_name = "test_#{name.gsub(/\W/,'_')}".to_sym # NEED THIS
|
21
22
|
defined = instance_method(test_name) rescue false
|
22
23
|
raise "#{test_name} is already defined in #{self}" if defined
|
23
24
|
if block_given?
|
24
|
-
define_method(test_name, &block)
|
25
|
+
# define_method(test_name, &block)
|
25
26
|
|
26
27
|
#
|
27
28
|
# could possibly do something like this, but I can't seem to figure out
|
28
29
|
# how to call a passed block correctly.
|
29
30
|
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
|
31
|
+
# lots of the like ....
|
32
|
+
# NoMethodError: undefined method `assert' for InterviewAssignmentTest:Class
|
33
|
+
#
|
34
|
+
define_method(test_name) do
|
35
|
+
print "\n#{self.class.name.gsub(/Test$/,'').titleize} #{name}: "
|
36
|
+
# block.call # FAIL
|
37
|
+
# self.block.call # FAIL
|
38
|
+
# yield # FAIL
|
39
|
+
instance_exec(&block) # SUCCESS!
|
40
|
+
end
|
34
41
|
else
|
35
42
|
define_method(test_name) do
|
36
43
|
flunk "No implementation provided for #{name}"
|
@@ -39,29 +46,53 @@ module JakeWendt::TestWithVerbosity
|
|
39
46
|
end
|
40
47
|
|
41
48
|
|
42
|
-
# rails used \s+ and converted groups of whitespace to a single underscore
|
43
|
-
# I then used \W+ and converted groups of non-word chars to a single underscore
|
44
49
|
|
45
|
-
# NOW I use \W and converted non-word chars to a underscores (no more groups)
|
46
50
|
|
47
|
-
|
48
|
-
|
49
|
-
test_name = "test_#{name.gsub(/\
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
51
|
+
# # activesupport-4.1.4/lib/active_support/testing/declarative.rb
|
52
|
+
# def test(name, &block)
|
53
|
+
# #test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym
|
54
|
+
# test_name = "test_#{name.gsub(/\W/,'_')}".to_sym # NEED THIS
|
55
|
+
# defined = instance_method(test_name) rescue false
|
56
|
+
# raise "#{test_name} is already defined in #{self}" if defined
|
57
|
+
# if block_given?
|
58
|
+
# define_method(test_name, &block)
|
59
|
+
# else
|
60
|
+
# define_method(test_name) do
|
61
|
+
# flunk "No implementation provided for #{name}"
|
62
|
+
# end
|
63
|
+
# end
|
64
|
+
# end
|
65
|
+
#
|
66
|
+
## rails used \s+ and converted groups of whitespace to a single underscore
|
67
|
+
## I then used \W+ and converted groups of non-word chars to a single underscore
|
68
|
+
#
|
69
|
+
## NOW I use \W and converted non-word chars to a underscores (no more groups)
|
70
|
+
#
|
71
|
+
# def test_with_verbosity(name,&block)
|
72
|
+
# test_without_verbosity(name,&block)
|
73
|
+
# test_name = "test_#{name.gsub(/\W/,'_')}".to_sym
|
74
|
+
# define_method("_#{test_name}_with_verbosity") do
|
75
|
+
# print "\n#{self.class.name.gsub(/Test$/,'').titleize} #{name}: "
|
76
|
+
# send("_#{test_name}_without_verbosity")
|
77
|
+
# end
|
78
|
+
# #
|
79
|
+
# # can't do this...
|
80
|
+
# # alias_method_chain test_name, :verbosity
|
81
|
+
# # end up with 2 methods that begin
|
82
|
+
# # with 'test_' so they both get run
|
83
|
+
# #
|
84
|
+
# alias_method "_#{test_name}_without_verbosity".to_sym,
|
85
|
+
# test_name
|
86
|
+
# alias_method test_name,
|
87
|
+
# "_#{test_name}_with_verbosity".to_sym
|
88
|
+
# end
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
|
65
96
|
|
66
97
|
#
|
67
98
|
#
|