Skip to content

Commit

Permalink
Flesh out the test command
Browse files Browse the repository at this point in the history
  • Loading branch information
dhh committed Dec 21, 2012
1 parent f31aae1 commit 19b6a1d
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions lib/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,23 @@ def initialize

def rake(task = nil, *args)
task.nil? ? print_rake_tasks : invoke_rake_task(task, *args)

"Completed"
rescue SystemExit
# Swallow exit/abort calls as we'll never want to exit the IRB session
rescue SystemExit, RuntimeError
"Failed"
end

# FIXME: Turn this into calls directly to the test classes, so we don't have to load environment again.
# Also need to toggle the environment to test and back to dev after running.
def test(what = nil)
case what
when NilClass, :all
rake "test:units"
when String
when NilClass
print_test_usage
"Completed"
when "all"
rake "test"
when /^[^\/]+$/ # models
rake "test:#{what}"
when /[\/]+/ # models/person
ENV['TEST'] = "test/#{what}_test.rb"
rake "test:single"
ENV['TEST'] = nil
Expand All @@ -54,7 +57,7 @@ def destroy(argv = nil)

private
def load_rake_tasks
Rake::TaskManager.record_task_metadata = true # needed to capture
Rake::TaskManager.record_task_metadata = true # needed to capture comments from define_task
load Rails.root.join('Rakefile')
end

Expand All @@ -74,6 +77,22 @@ def invoke_rake_task(task, *args)
Rake.application.tasks.each(&:reenable) # Rake by default only allows tasks to be run once per session
end


def print_test_usage
puts <<-EOT
Usage:
test "WHAT"
Description:
Runs either a full set of test suites or single suite.
If you supply WHAT with either models, controllers, helpers, integration, or performance,
those whole sets will be run.
If you supply WHAT with models/person, just test/models/person_test.rb will be run.
EOT
end


def generator(name, argv = nil)
if argv.nil?
Expand Down

0 comments on commit 19b6a1d

Please sign in to comment.