diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-05-30 14:49:59 -0700 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-05-30 14:49:59 -0700 |
commit | 4056915cf5dd885186465f63dce0ad9caf6e60f8 (patch) | |
tree | 98ff0f6fcd02335d8a8d82777c16f444ebfdfcf8 /railties/test/commands/console_test.rb | |
parent | c56ef677058de800fbdd16affaf00af10832d69c (diff) | |
parent | dce0afd47f334f61a4ab22acccef7c5e9d6e8b0a (diff) | |
download | rails-4056915cf5dd885186465f63dce0ad9caf6e60f8.tar.gz rails-4056915cf5dd885186465f63dce0ad9caf6e60f8.tar.bz2 rails-4056915cf5dd885186465f63dce0ad9caf6e60f8.zip |
Merge pull request #6276 from samoli/fix_console_arguments
Fix various bugs with console arguments and improve test coverage
Diffstat (limited to 'railties/test/commands/console_test.rb')
-rw-r--r-- | railties/test/commands/console_test.rb | 89 |
1 files changed, 60 insertions, 29 deletions
diff --git a/railties/test/commands/console_test.rb b/railties/test/commands/console_test.rb index 78648a16b3..91ede1cb68 100644 --- a/railties/test/commands/console_test.rb +++ b/railties/test/commands/console_test.rb @@ -3,47 +3,44 @@ require 'rails/commands/console' class Rails::ConsoleTest < ActiveSupport::TestCase class FakeConsole + def self.start; end end def setup end def test_sandbox_option - console = Rails::Console.new(app, ["--sandbox"]) + console = Rails::Console.new(app, parse_arguments(["--sandbox"])) assert console.sandbox? end def test_short_version_of_sandbox_option - console = Rails::Console.new(app, ["-s"]) + console = Rails::Console.new(app, parse_arguments(["-s"])) assert console.sandbox? end def test_debugger_option - console = Rails::Console.new(app, ["--debugger"]) + console = Rails::Console.new(app, parse_arguments(["--debugger"])) assert console.debugger? end def test_no_options - console = Rails::Console.new(app, []) + console = Rails::Console.new(app, parse_arguments([])) assert !console.debugger? assert !console.sandbox? end def test_start - app.expects(:sandbox=).with(nil) FakeConsole.expects(:start) - start - assert_match(/Loading \w+ environment \(Rails/, output) end def test_start_with_debugger - app.expects(:sandbox=).with(nil) + rails_console = Rails::Console.new(app, parse_arguments(["--debugger"])) rails_console.expects(:require_debugger).returns(nil) - FakeConsole.expects(:start) - start ["--debugger"] + silence_stream(STDOUT) { rails_console.start } end def test_start_with_sandbox @@ -56,42 +53,63 @@ class Rails::ConsoleTest < ActiveSupport::TestCase end def test_console_with_environment - app.expects(:sandbox=).with(nil) - FakeConsole.expects(:start) - start ["-e production"] + assert_match(/\sproduction\s/, output) + end + + def test_console_defaults_to_IRB + config = mock("config", :console => nil) + app = mock("app", :config => config) + app.expects(:load_console).returns(nil) - assert_match(/production/, output) + assert_equal IRB, Rails::Console.new(app).console end - def test_console_with_rails_environment - app.expects(:sandbox=).with(nil) - FakeConsole.expects(:start) + def test_default_environment_with_no_rails_env + with_rails_env nil do + start + assert_match /\sdevelopment\s/, output + end + end - start ["RAILS_ENV=production"] + def test_default_environment_with_rails_env + with_rails_env 'special-production' do + start + assert_match /\sspecial-production\s/, output + end + end + + def test_e_option + start ['-e', 'special-production'] + assert_match /\sspecial-production\s/, output + end - assert_match(/production/, output) + def test_environment_option + start ['--environment=special-production'] + assert_match /\sspecial-production\s/, output end + def test_rails_env_is_production_when_first_argument_is_p + start ['p'] + assert_match /\sproduction\s/, output + end - def test_console_defaults_to_IRB - config = mock("config", :console => nil) - app = mock("app", :config => config) - app.expects(:load_console).returns(nil) + def test_rails_env_is_test_when_first_argument_is_t + start ['t'] + assert_match /\stest\s/, output + end - assert_equal IRB, Rails::Console.new(app).console + def test_rails_env_is_development_when_argument_is_d + start ['d'] + assert_match /\sdevelopment\s/, output end private attr_reader :output - def rails_console - @rails_console ||= Rails::Console.new(app) - end - def start(argv = []) - rails_console.stubs(:arguments => argv) + rails_console = Rails::Console.new(app, parse_arguments(argv)) @output = output = capture(:stdout) { rails_console.start } end @@ -99,8 +117,21 @@ class Rails::ConsoleTest < ActiveSupport::TestCase @app ||= begin config = mock("config", :console => FakeConsole) app = mock("app", :config => config) + app.stubs(:sandbox=).returns(nil) app.expects(:load_console) app end end + + def parse_arguments(args) + Rails::Console.parse_arguments(args) + end + + def with_rails_env(env) + original_rails_env = ENV['RAILS_ENV'] + ENV['RAILS_ENV'] = env + yield + ensure + ENV['RAILS_ENV'] = original_rails_env + end end |