commands 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/commands-0.0.3.gem +0 -0
- data/commands.gemspec +1 -1
- data/lib/commands.rb +66 -17
- metadata +2 -1
data/commands-0.0.3.gem
ADDED
Binary file
|
data/commands.gemspec
CHANGED
data/lib/commands.rb
CHANGED
@@ -13,33 +13,36 @@ class Commands
|
|
13
13
|
include Rake::DSL
|
14
14
|
|
15
15
|
def initialize
|
16
|
-
|
17
|
-
|
16
|
+
load_rake_tasks
|
17
|
+
load_rails_generators
|
18
18
|
end
|
19
19
|
|
20
|
-
def rake(task, *args)
|
21
|
-
|
22
|
-
|
23
|
-
# Rake by default only allows tasks to be run once per session
|
24
|
-
Rake.application.tasks.each(&:reenable)
|
25
|
-
|
20
|
+
def rake(task = nil, *args)
|
21
|
+
task.nil? ? print_rake_tasks : invoke_rake_task(task, *args)
|
26
22
|
"Completed"
|
27
|
-
rescue SystemExit
|
28
|
-
# Swallow exit/abort calls as we'll never want to exit the IRB session
|
23
|
+
rescue SystemExit, RuntimeError
|
29
24
|
"Failed"
|
30
25
|
end
|
31
26
|
|
32
27
|
# FIXME: Turn this into calls directly to the test classes, so we don't have to load environment again.
|
33
28
|
# Also need to toggle the environment to test and back to dev after running.
|
34
29
|
def test(what = nil)
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
30
|
+
forking do
|
31
|
+
case what
|
32
|
+
when NilClass
|
33
|
+
print_test_usage
|
34
|
+
when "all"
|
35
|
+
rake "test"
|
36
|
+
when /^[^\/]+$/ # models
|
37
|
+
rake "test:#{what}"
|
38
|
+
when /[\/]+/ # models/person
|
39
|
+
ENV['TEST'] = "test/#{what}_test.rb"
|
40
|
+
rake "test:single"
|
41
|
+
ENV['TEST'] = nil
|
42
|
+
end
|
42
43
|
end
|
44
|
+
|
45
|
+
"Completed"
|
43
46
|
end
|
44
47
|
|
45
48
|
def generate(argv = nil)
|
@@ -56,6 +59,52 @@ class Commands
|
|
56
59
|
|
57
60
|
|
58
61
|
private
|
62
|
+
def load_rake_tasks
|
63
|
+
Rake::TaskManager.record_task_metadata = true # needed to capture comments from define_task
|
64
|
+
load Rails.root.join('Rakefile')
|
65
|
+
end
|
66
|
+
|
67
|
+
def load_rails_generators
|
68
|
+
Rails.application.load_generators
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
def print_rake_tasks
|
73
|
+
Rake.application.options.show_tasks = :tasks
|
74
|
+
Rake.application.options.show_task_pattern = Regexp.new('')
|
75
|
+
Rake.application.display_tasks_and_comments
|
76
|
+
end
|
77
|
+
|
78
|
+
def invoke_rake_task(task, *args)
|
79
|
+
silence_active_record_logger { Rake::Task[task].invoke(*args) }
|
80
|
+
Rake.application.tasks.each(&:reenable) # Rake by default only allows tasks to be run once per session
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
def print_test_usage
|
85
|
+
puts <<-EOT
|
86
|
+
Usage:
|
87
|
+
test "WHAT"
|
88
|
+
|
89
|
+
Description:
|
90
|
+
Runs either a full set of test suites or single suite.
|
91
|
+
|
92
|
+
If you supply WHAT with either models, controllers, helpers, integration, or performance,
|
93
|
+
those whole sets will be run.
|
94
|
+
|
95
|
+
If you supply WHAT with models/person, just test/models/person_test.rb will be run.
|
96
|
+
EOT
|
97
|
+
end
|
98
|
+
|
99
|
+
def forking
|
100
|
+
pid = Kernel.fork do
|
101
|
+
yield
|
102
|
+
Kernel.exit
|
103
|
+
end
|
104
|
+
Process.wait pid
|
105
|
+
end
|
106
|
+
|
107
|
+
|
59
108
|
def generator(name, argv = nil)
|
60
109
|
if argv.nil?
|
61
110
|
# FIXME: I don't know why we can't just catch SystemExit here, then we wouldn't need this if block
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: commands
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -34,6 +34,7 @@ extensions: []
|
|
34
34
|
extra_rdoc_files: []
|
35
35
|
files:
|
36
36
|
- ./commands-0.0.2.gem
|
37
|
+
- ./commands-0.0.3.gem
|
37
38
|
- ./commands.gemspec
|
38
39
|
- ./Gemfile
|
39
40
|
- ./Gemfile.lock
|