1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Stop using mocha on console_test

This commit is contained in:
Rafael Mendonça França 2014-07-07 23:39:18 -03:00
parent 57e298fcd5
commit a83efa4a1f

View file

@ -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
@ -25,17 +31,18 @@ class Rails::ConsoleTest < ActiveSupport::TestCase
end
def test_start
FakeConsole.expects(:start)
start
assert app.console.started?
assert_match(/Loading \w+ environment \(Rails/, output)
end
def test_start_with_sandbox
app.expects(:sandbox=).with(true)
FakeConsole.expects(:start)
start ["--sandbox"]
assert app.console.started?
assert app.sandbox
assert_match(/Loading \w+ environment in sandbox \(Rails/, output)
end
@ -64,7 +71,7 @@ class Rails::ConsoleTest < ActiveSupport::TestCase
end
def test_console_defaults_to_IRB
app = build_app(console: nil)
app = build_app(nil)
assert_equal IRB, Rails::Console.new(app).console
end
@ -115,8 +122,12 @@ class Rails::ConsoleTest < ActiveSupport::TestCase
end
def test_rails_env_is_dev_when_argument_is_dev_and_dev_env_is_present
Rails::Console.stubs(:available_environments).returns(['dev'])
options = Rails::Console.parse_arguments(['dev'])
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
@ -131,15 +142,29 @@ class Rails::ConsoleTest < ActiveSupport::TestCase
end
def app
@app ||= build_app(console: FakeConsole)
@app ||= build_app(FakeConsole)
end
def build_app(config)
config = mock("config", config)
app = mock("app", config: config)
app.stubs(:sandbox=).returns(nil)
app.expects(:load_console)
app
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)