aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/commands/console_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'railties/test/commands/console_test.rb')
-rw-r--r--railties/test/commands/console_test.rb96
1 files changed, 68 insertions, 28 deletions
diff --git a/railties/test/commands/console_test.rb b/railties/test/commands/console_test.rb
index 9e449856f4..4aea3e980f 100644
--- a/railties/test/commands/console_test.rb
+++ b/railties/test/commands/console_test.rb
@@ -6,7 +6,13 @@ class Rails::ConsoleTest < ActiveSupport::TestCase
include EnvHelpers
class FakeConsole
- def self.start; end
+ def self.started?
+ @started
+ end
+
+ def self.start
+ @started = true
+ end
end
def test_sandbox_option
@@ -19,37 +25,47 @@ class Rails::ConsoleTest < ActiveSupport::TestCase
assert console.sandbox?
end
- def test_debugger_option
- console = Rails::Console.new(app, parse_arguments(["--debugger"]))
- assert console.debugger?
- end
-
def test_no_options
console = Rails::Console.new(app, parse_arguments([]))
- assert !console.debugger?
assert !console.sandbox?
end
def test_start
- FakeConsole.expects(:start)
start
+
+ assert app.console.started?
assert_match(/Loading \w+ environment \(Rails/, output)
end
- def test_start_with_debugger
- rails_console = Rails::Console.new(app, parse_arguments(["--debugger"]))
- rails_console.expects(:require_debugger).returns(nil)
+ def test_start_with_sandbox
+ start ["--sandbox"]
- silence_stream(STDOUT) { rails_console.start }
+
+ assert app.console.started?
+ assert app.sandbox
+ assert_match(/Loading \w+ environment in sandbox \(Rails/, output)
end
- def test_start_with_sandbox
- app.expects(:sandbox=).with(true)
- FakeConsole.expects(:start)
+ if RUBY_VERSION < '2.0.0'
+ def test_debugger_option
+ console = Rails::Console.new(app, parse_arguments(["--debugger"]))
+ assert console.debugger?
+ end
- start ["--sandbox"]
+ def test_no_options_does_not_set_debugger_flag
+ console = Rails::Console.new(app, parse_arguments([]))
+ assert !console.debugger?
+ end
- assert_match(/Loading \w+ environment in sandbox \(Rails/, output)
+ def test_start_with_debugger
+ stubbed_console = Class.new(Rails::Console) do
+ def require_debugger
+ end
+ end
+
+ rails_console = stubbed_console.new(app, parse_arguments(["--debugger"]))
+ silence_stream(STDOUT) { rails_console.start }
+ end
end
def test_console_with_environment
@@ -58,10 +74,7 @@ class Rails::ConsoleTest < ActiveSupport::TestCase
end
def test_console_defaults_to_IRB
- config = mock("config", console: nil)
- app = mock("app", config: config)
- app.expects(:load_console).returns(nil)
-
+ app = build_app(nil)
assert_equal IRB, Rails::Console.new(app).console
end
@@ -111,9 +124,20 @@ class Rails::ConsoleTest < ActiveSupport::TestCase
assert_match(/\sdevelopment\s/, output)
end
- private
+ def test_rails_env_is_dev_when_argument_is_dev_and_dev_env_is_present
+ stubbed_console = Class.new(Rails::Console) do
+ def available_environments
+ ['dev']
+ end
+ end
+ options = stubbed_console.parse_arguments(['dev'])
+ assert_match('dev', options[:environment])
+ end
attr_reader :output
+ private :output
+
+ private
def start(argv = [])
rails_console = Rails::Console.new(app, parse_arguments(argv))
@@ -121,13 +145,29 @@ class Rails::ConsoleTest < ActiveSupport::TestCase
end
def app
- @app ||= begin
- config = mock("config", console: FakeConsole)
- app = mock("app", config: config)
- app.stubs(:sandbox=).returns(nil)
- app.expects(:load_console)
- app
+ @app ||= build_app(FakeConsole)
+ end
+
+ def build_app(console)
+ mocked_console = Class.new do
+ attr_reader :sandbox, :console
+
+ def initialize(console)
+ @console = console
+ end
+
+ def config
+ self
+ end
+
+ def sandbox=(arg)
+ @sandbox = arg
+ end
+
+ def load_console
+ end
end
+ mocked_console.new(console)
end
def parse_arguments(args)