Permalink
Browse files

GH #18: add --version for relevance_rails version and basic runner specs

  • Loading branch information...
1 parent 38c9dd0 commit ce681dc43f18d3bb4bcbc4b9aaee51e4a26a0f7a @cldwalker cldwalker committed Apr 5, 2012
Showing with 59 additions and 8 deletions.
  1. +2 −3 bin/relevance_rails
  2. +24 −0 lib/relevance_rails/runner.rb
  3. +0 −5 lib/relevance_rails/template_injector.rb
  4. +22 −0 spec/lib/runner_spec.rb
  5. +11 −0 spec/spec_helper.rb
View
@@ -1,5 +1,4 @@
#!/usr/bin/env ruby
-require 'relevance_rails/template_injector'
-
-exec 'rails', *ARGV
+require 'relevance_rails/runner'
+RelevanceRails::Runner.start
@@ -0,0 +1,24 @@
+require 'relevance_rails'
+
+module RelevanceRails
+ class Runner
+ def self.start(argv=ARGV)
+ if argv.delete '--version'
+ puts "RelevanceRails #{RelevanceRails::VERSION}"
+ else
+ add_default_options! argv
+ exec 'rails', *argv
+ end
+ end
+
+ private
+
+ def self.add_default_options!(argv)
+ unless argv.any? =~ /^-d$/
+ template = File.join(File.dirname(__FILE__), "relevance_rails_template.rb")
+ argv << '-m'
+ argv << template
+ end
+ end
+ end
+end
@@ -1,5 +0,0 @@
-template = File.join(File.dirname(__FILE__), "relevance_rails_template.rb")
-unless ARGV.any? =~ /^-d$/ then
- ARGV << '-m'
- ARGV << template
-end
View
@@ -0,0 +1,22 @@
+require 'relevance_rails/runner'
+require 'spec_helper'
+
+describe RelevanceRails::Runner do
+ context ".start" do
+ def start(*args)
+ RelevanceRails::Runner.start(args)
+ end
+
+ it "with --version prints version" do
+ capture_stdout { start('--version') }.chomp.should ==
+ "RelevanceRails #{RelevanceRails::VERSION}"
+ end
+
+ it "new calls exec" do
+ RelevanceRails::Runner.should_receive(:exec).with('rails', 'new', 'the_app', '-m',
+ File.expand_path(File.dirname(__FILE__) +
+ "/../../lib/relevance_rails/relevance_rails_template.rb"))
+ start('new', 'the_app')
+ end
+ end
+end
View
@@ -14,6 +14,17 @@ def capture_stderr(&block)
fake.string
end
+ def capture_stdout(&block)
+ original_stdout = $stdout
+ $stdout = fake = StringIO.new
+ begin
+ yield
+ ensure
+ $stdout = original_stdout
+ end
+ fake.string
+ end
+
# wrapper around raise_error that captures stderr
def should_abort_with(msg)
capture_stderr do

0 comments on commit ce681dc

Please sign in to comment.