-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminitest.rake
90 lines (69 loc) · 2.05 KB
/
minitest.rake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
namespace( :mt ) do
class MakeMyTest
attr_reader :type, :dir
def initialize( type, wd, files )
@type = type
@wd = wd
@files = files
end
def manipulate()
for file in @files
if file.end_with?( @type )
yield(file, @type, @wd)
end
end
end
def spec_folder
Dir.mkdir( "#{@wd}/specs" ) unless Dir.exists? 'specs'
end
def model_folder
Dir.mkdir( "{@wd}/models" ) unless Dir.exists? 'models'
@files = Dir.entries( getwd() + "/models")
end
def models(models)
for model in models
open("#{@wd}/models/#{model}.rb", "a") do |f|
f << class_bplate( model )
end
end
@files = Dir.entries( @wd + "/models" ) # once we create the models we need to update our object with that info
end
def class_bplate( model )
name = model.slice(0,1).capitalize + model.slice(1..-1)
return "class #{name}\n\n\nend"
end
def minitest_bplate( model )
name = model.slice(0,1).capitalize + model.slice(1..-1)
return "require( 'minitest/autorun' )\nrequire( 'minitest/rg' )\nrequire_relative( '../models/#{model}.rb' )\n\nclass Test#{name} < MiniTest::Test\n\n\nend"
end
end
test = MakeMyTest.new( '.rb', getwd(), nil )
task( :setup ) do |t, args|
test model_folder()
test.models(args.extras)
test.spec_folder()
test.manipulate do |file, type, wd|
touch( "#{wd}/specs/#{file.split( type ).first()}_spec.rb")
end
test.manipulate do |file, type, wd|
model = file.split(type).first
spec_file = model + "_spec.rb"
open( "#{wd}/specs/#{spec_file}", 'a' ) do |f|
f << test.minitest_bplate( model )
end
end
end
task( :run ) do
files = Dir.entries( "#{getwd()}/specs" )
test = MakeMyTest.new( '.rb', getwd(), files )
test.manipulate do |file, type, wd|
sh("ruby #{wd}/specs/#{file}")
end
end
task( :delete_specs ) do
system "rm -rf specs/"
end
task( :delete_models ) do
system "rm -rf models/"
end
end