From 6c3130debecd68dff326722ab0c0b0912493367c Mon Sep 17 00:00:00 2001 From: Nick Quaranto Date: Fri, 21 Dec 2012 17:02:20 -0500 Subject: [PATCH] Bring in M to run tests! :metal: --- Gemfile | 2 -- Gemfile.lock | 76 ++++++++++++++++++++++++++++++++++++++---------- commands.gemspec | 1 + lib/commands.rb | 67 +++++++++++++++++------------------------- 4 files changed, 89 insertions(+), 57 deletions(-) diff --git a/Gemfile b/Gemfile index e578d66..c80ee36 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,3 @@ source "http://rubygems.org" gemspec - -gem "rails" diff --git a/Gemfile.lock b/Gemfile.lock index a5c8ccc..a2e565d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,15 +1,19 @@ PATH remote: . specs: - jbuilder (0.9.1) - activesupport (>= 3.0.0) + commands (0.0.3) + m (~> 1.3) + rails (>= 3.0.0) GEM remote: http://rubygems.org/ specs: - actionpack (3.2.8) - activemodel (= 3.2.8) - activesupport (= 3.2.8) + actionmailer (3.2.7) + actionpack (= 3.2.7) + mail (~> 2.4.4) + actionpack (3.2.7) + activemodel (= 3.2.7) + activesupport (= 3.2.7) builder (~> 3.0.0) erubis (~> 2.7.0) journey (~> 1.0.4) @@ -17,34 +21,76 @@ GEM rack-cache (~> 1.2) rack-test (~> 0.6.1) sprockets (~> 2.1.3) - activemodel (3.2.8) - activesupport (= 3.2.8) + activemodel (3.2.7) + activesupport (= 3.2.7) builder (~> 3.0.0) - activesupport (3.2.8) + activerecord (3.2.7) + activemodel (= 3.2.7) + activesupport (= 3.2.7) + arel (~> 3.0.2) + tzinfo (~> 0.3.29) + activeresource (3.2.7) + activemodel (= 3.2.7) + activesupport (= 3.2.7) + activesupport (3.2.7) i18n (~> 0.6) multi_json (~> 1.0) - builder (3.0.0) + arel (3.0.2) + builder (3.0.4) erubis (2.7.0) hike (1.2.1) i18n (0.6.1) journey (1.0.4) - multi_json (1.3.6) + json (1.7.5) + m (1.3.0) + method_source (>= 0.6.7) + rake (>= 0.9.2.2, < 1.0.0) + mail (2.4.4) + i18n (>= 0.4.0) + mime-types (~> 1.16) + treetop (~> 1.4.8) + method_source (0.8.1) + mime-types (1.19) + multi_json (1.4.0) + polyglot (0.3.3) rack (1.4.1) rack-cache (1.2) rack (>= 0.4) - rack-test (0.6.1) + rack-ssl (1.3.2) + rack + rack-test (0.6.2) rack (>= 1.0) - rake (0.9.2.2) + rails (3.2.7) + actionmailer (= 3.2.7) + actionpack (= 3.2.7) + activerecord (= 3.2.7) + activeresource (= 3.2.7) + activesupport (= 3.2.7) + bundler (~> 1.0) + railties (= 3.2.7) + railties (3.2.7) + actionpack (= 3.2.7) + activesupport (= 3.2.7) + rack-ssl (~> 1.3.2) + rake (>= 0.8.7) + rdoc (~> 3.4) + thor (>= 0.14.6, < 2.0) + rake (0.9.5) + rdoc (3.12) + json (~> 1.4) sprockets (2.1.3) hike (~> 1.2) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) + thor (0.16.0) tilt (1.3.3) + treetop (1.4.12) + polyglot + polyglot (>= 0.3.1) + tzinfo (0.3.35) PLATFORMS ruby DEPENDENCIES - actionpack - jbuilder! - rake + commands! diff --git a/commands.gemspec b/commands.gemspec index a510b20..071bc58 100644 --- a/commands.gemspec +++ b/commands.gemspec @@ -6,6 +6,7 @@ Gem::Specification.new do |s| s.summary = 'Run Rake/Rails commands through the console' s.add_dependency 'rails', '>= 3.0.0' + s.add_dependency 'm', '~> 1.3' s.files = Dir["#{File.dirname(__FILE__)}/**/*"] end diff --git a/lib/commands.rb b/lib/commands.rb index 34dcde3..ec75bb6 100644 --- a/lib/commands.rb +++ b/lib/commands.rb @@ -6,17 +6,17 @@ module ConsoleMethods def commands @commands ||= Commands.new end - + delegate :rake, :test, :generate, :destroy, :update, to: :commands end include Rake::DSL - + def initialize load_rake_tasks load_rails_generators end - + def rake(task = nil, *args) task.nil? ? print_rake_tasks : invoke_rake_task(task, *args) "Completed" @@ -27,48 +27,51 @@ def rake(task = nil, *args) # 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) - forking do - case what - when NilClass - print_test_usage - when "all" - rake "test" - when /^[^\/]+$/ # models - rake "test:#{what}" - when /[\/]+/ # models/person - ENV['TEST'] = "test/#{what}_test.rb" - rake "test:single" - ENV['TEST'] = nil + require 'm' + + args = if what + directory = File.join("test", what) + + if File.directory?(directory) + [directory] + else + path, line_number = directory.split(":") + file = "#{path}_test.rb" + file << ":#{line_number}" if line_number + [file] end + else + [] end - "Completed" + forking do + M::Runner.new(args).run + end end def generate(argv = nil) generator :generate, argv end - + def update(argv = nil) generator :update, argv end - + def destroy(argv = nil) generator :destroy, argv end - - + + private def load_rake_tasks Rake::TaskManager.record_task_metadata = true # needed to capture comments from define_task load Rails.root.join('Rakefile') end - + def load_rails_generators Rails.application.load_generators end - def print_rake_tasks Rake.application.options.show_tasks = :tasks Rake.application.options.show_task_pattern = Regexp.new('') @@ -80,31 +83,15 @@ 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 forking pid = Kernel.fork do yield Kernel.exit end Process.wait pid + true end - def generator(name, argv = nil) if argv.nil? # FIXME: I don't know why we can't just catch SystemExit here, then we wouldn't need this if block @@ -117,7 +104,7 @@ def generator(name, argv = nil) "Completed" end - + # Only just ensured that this method is available in rails/master, so need a guard for a bit. def silence_active_record_logger begin