Skip to content

Commit

Permalink
test some of the rc specification
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Oct 30, 2013
1 parent 9696073 commit 3060dfc
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
6 changes: 5 additions & 1 deletion railties/lib/rails/generators/rails/app/app_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,10 @@ def prepare!
argv
end

def self.default_rc_file
File.join(File.expand_path('~'), '.railsrc')
end

private

def handle_version_request!(argument)
Expand All @@ -353,7 +357,7 @@ def railsrc
if (customrc = argv.index{ |x| x.include?("--rc=") })
File.expand_path(argv.delete_at(customrc).gsub(/--rc=/, ""))
else
File.join(File.expand_path("~"), '.railsrc')
self.class.default_rc_file
end
end

Expand Down
46 changes: 43 additions & 3 deletions railties/test/generators/argv_scrubber_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'active_support/test_case'
require 'active_support/testing/autorun'
require 'rails/generators/rails/app/app_generator'
require 'tempfile'

module Rails
module Generators
Expand All @@ -14,23 +15,62 @@ def test_version
define_method(:puts) { |str| output = str }
define_method(:exit) { |code| exit_code = code }
})
scrubber.prepare
scrubber.prepare!
assert_equal "Rails #{Rails::VERSION::STRING}", output
assert_equal 0, exit_code
end
end

def test_prepare_returns_args
scrubber = ARGVScrubber.new ['hi mom']
args = scrubber.prepare
args = scrubber.prepare!
assert_equal '--help', args.first
end

def test_no_mutations
scrubber = ARGVScrubber.new ['hi mom'].freeze
args = scrubber.prepare
args = scrubber.prepare!
assert_equal '--help', args.first
end

def test_new_command_no_rc
scrubber = Class.new(ARGVScrubber) {
def self.default_rc_file
File.join(Dir.tmpdir, 'whatever')
end
}.new ['new']
args = scrubber.prepare!
assert_nil args.first
assert_equal [], args
end

def test_new_homedir_rc
file = Tempfile.new 'myrcfile'
file.puts '--hello-world'
file.flush

message = nil
scrubber = Class.new(ARGVScrubber) {
define_singleton_method(:default_rc_file) do
file.path
end
define_method(:puts) { |msg| message = msg }
}.new ['new']
args = scrubber.prepare!
assert_nil args.first
assert_equal [nil, '--hello-world'], args
assert_match 'hello-world', message
assert_match file.path, message
ensure
file.close
file.unlink
end

def test_no_rc
scrubber = ARGVScrubber.new ['new', '--no-rc']
args = scrubber.prepare!
assert_equal [], args
end
end
end
end

0 comments on commit 3060dfc

Please sign in to comment.