mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #20248 from ronakjangir47/remove_mocha
Remove use of mocha in the railties generators tests
This commit is contained in:
commit
5e92f9022f
1 changed files with 34 additions and 18 deletions
|
@ -1,7 +1,7 @@
|
|||
require 'generators/generators_test_helper'
|
||||
require 'rails/generators/rails/model/model_generator'
|
||||
require 'rails/generators/test_unit/model/model_generator'
|
||||
require 'mocha/setup' # FIXME: stop using mocha
|
||||
require 'minitest/mock'
|
||||
|
||||
class GeneratorsTest < Rails::Generators::TestCase
|
||||
include GeneratorsTestHelper
|
||||
|
@ -9,17 +9,21 @@ class GeneratorsTest < Rails::Generators::TestCase
|
|||
def setup
|
||||
@path = File.expand_path("lib", Rails.root)
|
||||
$LOAD_PATH.unshift(@path)
|
||||
@mock_generator = MiniTest::Mock.new
|
||||
end
|
||||
|
||||
def teardown
|
||||
$LOAD_PATH.delete(@path)
|
||||
@mock_generator.verify
|
||||
end
|
||||
|
||||
def test_simple_invoke
|
||||
assert File.exist?(File.join(@path, 'generators', 'model_generator.rb'))
|
||||
TestUnit::Generators::ModelGenerator.expects(:start).with(["Account"], {})
|
||||
@mock_generator.expect(:call, nil, [["Account"],{}])
|
||||
TestUnit::Generators::ModelGenerator.stub(:start, @mock_generator) do
|
||||
Rails::Generators.invoke("test_unit:model", ["Account"])
|
||||
end
|
||||
end
|
||||
|
||||
def test_invoke_when_generator_is_not_found
|
||||
name = :unknown
|
||||
|
@ -47,20 +51,26 @@ class GeneratorsTest < Rails::Generators::TestCase
|
|||
|
||||
def test_should_give_higher_preference_to_rails_generators
|
||||
assert File.exist?(File.join(@path, 'generators', 'model_generator.rb'))
|
||||
Rails::Generators::ModelGenerator.expects(:start).with(["Account"], {})
|
||||
@mock_generator.expect(:call, nil, [["Account"],{}])
|
||||
Rails::Generators::ModelGenerator.stub(:start, @mock_generator) do
|
||||
warnings = capture(:stderr){ Rails::Generators.invoke :model, ["Account"] }
|
||||
assert warnings.empty?
|
||||
end
|
||||
end
|
||||
|
||||
def test_invoke_with_default_values
|
||||
Rails::Generators::ModelGenerator.expects(:start).with(["Account"], {})
|
||||
@mock_generator.expect(:call, nil, [["Account"],{}])
|
||||
Rails::Generators::ModelGenerator.stub(:start, @mock_generator) do
|
||||
Rails::Generators.invoke :model, ["Account"]
|
||||
end
|
||||
end
|
||||
|
||||
def test_invoke_with_config_values
|
||||
Rails::Generators::ModelGenerator.expects(:start).with(["Account"], behavior: :skip)
|
||||
@mock_generator.expect(:call, nil, [["Account"],{behavior: :skip}])
|
||||
Rails::Generators::ModelGenerator.stub(:start, @mock_generator) do
|
||||
Rails::Generators.invoke :model, ["Account"], behavior: :skip
|
||||
end
|
||||
end
|
||||
|
||||
def test_find_by_namespace
|
||||
klass = Rails::Generators.find_by_namespace("rails:model")
|
||||
|
@ -103,12 +113,14 @@ class GeneratorsTest < Rails::Generators::TestCase
|
|||
end
|
||||
|
||||
def test_invoke_with_nested_namespaces
|
||||
model_generator = mock('ModelGenerator') do
|
||||
expects(:start).with(["Account"], {})
|
||||
end
|
||||
Rails::Generators.expects(:find_by_namespace).with('namespace', 'my:awesome').returns(model_generator)
|
||||
model_generator = Minitest::Mock.new
|
||||
model_generator.expect(:start, nil, [["Account"], {}])
|
||||
@mock_generator.expect(:call, model_generator, ['namespace', 'my:awesome'])
|
||||
Rails::Generators.stub(:find_by_namespace, @mock_generator) do
|
||||
Rails::Generators.invoke 'my:awesome:namespace', ["Account"]
|
||||
end
|
||||
model_generator.verify
|
||||
end
|
||||
|
||||
def test_rails_generators_help_with_builtin_information
|
||||
output = capture(:stdout){ Rails::Generators.help }
|
||||
|
@ -173,8 +185,10 @@ class GeneratorsTest < Rails::Generators::TestCase
|
|||
|
||||
def test_fallbacks_for_generators_on_invoke
|
||||
Rails::Generators.fallbacks[:shoulda] = :test_unit
|
||||
TestUnit::Generators::ModelGenerator.expects(:start).with(["Account"], {})
|
||||
@mock_generator.expect(:call, nil, [["Account"],{}])
|
||||
TestUnit::Generators::ModelGenerator.stub(:start, @mock_generator) do
|
||||
Rails::Generators.invoke "shoulda:model", ["Account"]
|
||||
end
|
||||
ensure
|
||||
Rails::Generators.fallbacks.delete(:shoulda)
|
||||
end
|
||||
|
@ -182,8 +196,10 @@ class GeneratorsTest < Rails::Generators::TestCase
|
|||
def test_nested_fallbacks_for_generators
|
||||
Rails::Generators.fallbacks[:shoulda] = :test_unit
|
||||
Rails::Generators.fallbacks[:super_shoulda] = :shoulda
|
||||
TestUnit::Generators::ModelGenerator.expects(:start).with(["Account"], {})
|
||||
@mock_generator.expect(:call, nil, [["Account"],{}])
|
||||
TestUnit::Generators::ModelGenerator.stub(:start, @mock_generator) do
|
||||
Rails::Generators.invoke "super_shoulda:model", ["Account"]
|
||||
end
|
||||
ensure
|
||||
Rails::Generators.fallbacks.delete(:shoulda)
|
||||
Rails::Generators.fallbacks.delete(:super_shoulda)
|
||||
|
|
Loading…
Reference in a new issue