Skip to content

Bring in M to run tests #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
source "http://rubygems.org"

gemspec

gem "rails"
76 changes: 61 additions & 15 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,50 +1,96 @@
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)
rack (~> 1.4.0)
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!
1 change: 1 addition & 0 deletions commands.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
67 changes: 27 additions & 40 deletions lib/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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('')
Expand All @@ -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
Expand All @@ -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
Expand Down