testhelper 0.0.1 → 0.1.0
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/file_line.rb +55 -0
- data/lib/testhelper.rb +81 -3
- metadata +5 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ac3a6fbd2b3c2f81f595614c19da52a9accdef9f
|
|
4
|
+
data.tar.gz: d12be2a5ecd9ae975086c0d96944c8bb814b0f4d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 123d26d466a040eeabd26f4ceebab66c8924f2d32331642aede810358ae70fbe27e15ea382d8fb12b14b4cdbf0e2e9e405f1591bf15ac2ae96fe5774e1236ebf
|
|
7
|
+
data.tar.gz: ba3c5520869efea11dd66d598fa83b1d541debd5a9cb7483979b84cd1f33103b3d0cd4a4328f2429afb4698a6703e7339af828971cf78c1de592868691c8b8cd
|
data/lib/file_line.rb
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
module FileLine
|
|
2
|
+
def self.get(file_path, line_no)
|
|
3
|
+
open(file_path) do |f|
|
|
4
|
+
# tap depend on ruby > 1.9
|
|
5
|
+
return f.each_line.tap{|enum| (line_no-1).times{enum.next}}.next
|
|
6
|
+
end
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
module SourceFile
|
|
11
|
+
# /Users/colin/work/testhelper/lib/testhelper.rb:55:in `<main>'
|
|
12
|
+
# " self.ppt()\n"
|
|
13
|
+
# ColintTest
|
|
14
|
+
# " mm.ppt()\n"
|
|
15
|
+
def self.split_file_name_and_no(location_str)
|
|
16
|
+
source_infos = location_str.split(":")
|
|
17
|
+
[source_infos[0], source_infos[1].to_i]
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def self.analyze_variable_name(the_line, the_callee)
|
|
21
|
+
the_line.slice(0, the_line.index(the_callee.to_s)-1).strip()
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def self.get_variable_name(location_str, the_callee)
|
|
25
|
+
the_line = FileLine.get(*split_file_name_and_no(location_str))
|
|
26
|
+
analyze_variable_name(the_line, the_callee)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
if __FILE__ == $0
|
|
31
|
+
require 'minitest/spec'
|
|
32
|
+
require 'minitest/autorun'
|
|
33
|
+
|
|
34
|
+
describe FileLine do
|
|
35
|
+
it "get line from the file" do
|
|
36
|
+
file_path = "../testhelper.gemspec"
|
|
37
|
+
line_no = 3
|
|
38
|
+
FileLine.get(file_path, line_no).must_equal(
|
|
39
|
+
" s.version = '0.0.1'\n")
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
describe SourceFile do
|
|
44
|
+
it "splits the file name and line not from the location string" do
|
|
45
|
+
location_str = "/Users/colin/work/testhelper/lib/testhelper.rb:55:in `<main>'"
|
|
46
|
+
SourceFile.split_file_name_and_no(location_str).must_equal(
|
|
47
|
+
["/Users/colin/work/testhelper/lib/testhelper.rb", 55])
|
|
48
|
+
end
|
|
49
|
+
it "analyze variable name from a line of source" do
|
|
50
|
+
the_line = " mm.ppt()\n"
|
|
51
|
+
the_callee = :ppt
|
|
52
|
+
SourceFile.analyze_variable_name(the_line, the_callee).must_equal("mm")
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
data/lib/testhelper.rb
CHANGED
|
@@ -1,6 +1,84 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
direc = File.dirname(__FILE__)
|
|
2
|
+
|
|
3
|
+
require "#{direc}/file_line"
|
|
4
|
+
require 'pp'
|
|
5
|
+
|
|
6
|
+
module TestHelper
|
|
7
|
+
module ObjectMixin
|
|
8
|
+
# It will pretty print the self, with title.
|
|
9
|
+
def pt(title=nil)
|
|
10
|
+
location_str = caller()[0]
|
|
11
|
+
if title == nil
|
|
12
|
+
title = SourceFile.get_variable_name(location_str, __callee__)
|
|
13
|
+
end
|
|
14
|
+
puts("#{title} : #{self.inspect()}")
|
|
15
|
+
end
|
|
16
|
+
def ptl(title=nil)
|
|
17
|
+
location_str = caller()[0]
|
|
18
|
+
puts(location_str)
|
|
19
|
+
if title == nil
|
|
20
|
+
title = SourceFile.get_variable_name(location_str, __callee__)
|
|
21
|
+
end
|
|
22
|
+
puts("#{title} : #{self.inspect()}")
|
|
23
|
+
end
|
|
24
|
+
def ppt(title=nil)
|
|
25
|
+
location_str = caller()[0]
|
|
26
|
+
if title == nil
|
|
27
|
+
title = SourceFile.get_variable_name(location_str, __callee__)
|
|
28
|
+
end
|
|
29
|
+
puts("#{title} :")
|
|
30
|
+
pp(self)
|
|
31
|
+
end
|
|
32
|
+
def pptl(title=nil)
|
|
33
|
+
location_str = caller()[0]
|
|
34
|
+
puts(location_str)
|
|
35
|
+
if title == nil
|
|
36
|
+
title = SourceFile.get_variable_name(location_str, __callee__)
|
|
37
|
+
end
|
|
38
|
+
puts("#{title} : ")
|
|
39
|
+
pp(self)
|
|
40
|
+
end
|
|
41
|
+
def flag_test(title=nil)
|
|
42
|
+
location_str = caller()[0]
|
|
43
|
+
puts(location_str)
|
|
44
|
+
if title == nil
|
|
45
|
+
title = ""
|
|
46
|
+
else
|
|
47
|
+
title = title+" : "
|
|
48
|
+
end
|
|
49
|
+
puts(title+"There are codes for test in this place!")
|
|
50
|
+
end
|
|
51
|
+
alias puts_with_title pt
|
|
52
|
+
alias puts_with_title_lineno ptl
|
|
53
|
+
alias pretty_print_with_title ppt
|
|
54
|
+
alias pretty_print_with_title_lineno pptl
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
class Object < BasicObject # :nodoc:
|
|
59
|
+
include TestHelper::ObjectMixin
|
|
3
60
|
end
|
|
4
61
|
|
|
5
62
|
|
|
6
|
-
|
|
63
|
+
if __FILE__ == $0
|
|
64
|
+
class ColinTest
|
|
65
|
+
def inspect()
|
|
66
|
+
"ColinTest"
|
|
67
|
+
end
|
|
68
|
+
alias to_str inspect
|
|
69
|
+
end
|
|
70
|
+
name = "Test Helper"
|
|
71
|
+
name.pt()
|
|
72
|
+
name.pt("Tt's the name")
|
|
73
|
+
name.ppt()
|
|
74
|
+
name.ppt("Tt's the name")
|
|
75
|
+
|
|
76
|
+
ct = ColinTest.new()
|
|
77
|
+
ct.ptl()
|
|
78
|
+
ct.ptl("It's a new instance.")
|
|
79
|
+
ct.pptl()
|
|
80
|
+
ct.pptl("It's a new instance.")
|
|
81
|
+
|
|
82
|
+
flag_test()
|
|
83
|
+
flag_test("for test")
|
|
84
|
+
end
|
metadata
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: testhelper
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0
|
|
4
|
+
version: 0.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Colin Ji
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2014-07-
|
|
11
|
+
date: 2014-07-30 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
|
-
description:
|
|
13
|
+
description: Some print helper methods like pt, ptl, ppt, pptl, flag_test for testing.
|
|
14
14
|
email: jichen3000@gmail.com
|
|
15
15
|
executables: []
|
|
16
16
|
extensions: []
|
|
17
17
|
extra_rdoc_files: []
|
|
18
18
|
files:
|
|
19
|
+
- lib/file_line.rb
|
|
19
20
|
- lib/testhelper.rb
|
|
20
21
|
homepage: http://rubygems.org/gems/testhelper
|
|
21
22
|
licenses:
|
|
@@ -29,7 +30,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
29
30
|
requirements:
|
|
30
31
|
- - ">="
|
|
31
32
|
- !ruby/object:Gem::Version
|
|
32
|
-
version:
|
|
33
|
+
version: 1.9.0
|
|
33
34
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
34
35
|
requirements:
|
|
35
36
|
- - ">="
|