mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #20357 from ronakjangir47/remove_mocha1
Removed use of mocha from railties actions_test
This commit is contained in:
commit
8b67f28f4a
1 changed files with 58 additions and 33 deletions
|
@ -1,7 +1,7 @@
|
||||||
require 'generators/generators_test_helper'
|
require 'generators/generators_test_helper'
|
||||||
require 'rails/generators/rails/app/app_generator'
|
require 'rails/generators/rails/app/app_generator'
|
||||||
require 'env_helpers'
|
require 'env_helpers'
|
||||||
require 'mocha/setup' # FIXME: stop using mocha
|
require 'minitest/mock'
|
||||||
|
|
||||||
class ActionsTest < Rails::Generators::TestCase
|
class ActionsTest < Rails::Generators::TestCase
|
||||||
include GeneratorsTestHelper
|
include GeneratorsTestHelper
|
||||||
|
@ -12,11 +12,13 @@ class ActionsTest < Rails::Generators::TestCase
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
Rails.application = TestApp::Application
|
Rails.application = TestApp::Application
|
||||||
|
@mock_generator = Minitest::Mock.new
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
def teardown
|
def teardown
|
||||||
Rails.application = TestApp::Application.instance
|
Rails.application = TestApp::Application.instance
|
||||||
|
@mock_generator.verify
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_invoke_other_generator_with_shortcut
|
def test_invoke_other_generator_with_shortcut
|
||||||
|
@ -140,14 +142,19 @@ class ActionsTest < Rails::Generators::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_git_with_symbol_should_run_command_using_git_scm
|
def test_git_with_symbol_should_run_command_using_git_scm
|
||||||
generator.expects(:run).once.with('git init')
|
@mock_generator.expect(:call, nil, ['git init'])
|
||||||
|
generator.stub(:run, @mock_generator) do
|
||||||
action :git, :init
|
action :git, :init
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_git_with_hash_should_run_each_command_using_git_scm
|
def test_git_with_hash_should_run_each_command_using_git_scm
|
||||||
generator.expects(:run).times(2)
|
@mock_generator.expect(:call, nil, ["git rm README"])
|
||||||
|
@mock_generator.expect(:call, nil, ["git add ."])
|
||||||
|
generator.stub(:run, @mock_generator) do
|
||||||
action :git, rm: 'README', add: '.'
|
action :git, rm: 'README', add: '.'
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_vendor_should_write_data_to_file_in_vendor
|
def test_vendor_should_write_data_to_file_in_vendor
|
||||||
action :vendor, 'vendor_file.rb', '# vendor data'
|
action :vendor, 'vendor_file.rb', '# vendor data'
|
||||||
|
@ -170,47 +177,61 @@ class ActionsTest < Rails::Generators::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_generate_should_run_script_generate_with_argument_and_options
|
def test_generate_should_run_script_generate_with_argument_and_options
|
||||||
generator.expects(:run_ruby_script).once.with('bin/rails generate model MyModel', verbose: false)
|
@mock_generator.expect(:call, nil, ['bin/rails generate model MyModel', verbose: false])
|
||||||
|
generator.stub(:run_ruby_script, @mock_generator) do
|
||||||
action :generate, 'model', 'MyModel'
|
action :generate, 'model', 'MyModel'
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_rake_should_run_rake_command_with_default_env
|
def test_rake_should_run_rake_command_with_default_env
|
||||||
generator.expects(:run).once.with("rake log:clear RAILS_ENV=development", verbose: false)
|
@mock_generator.expect(:call, nil, ["rake log:clear RAILS_ENV=development", verbose: false])
|
||||||
|
generator.stub(:run, @mock_generator) do
|
||||||
with_rails_env nil do
|
with_rails_env nil do
|
||||||
action :rake, 'log:clear'
|
action :rake, 'log:clear'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_rake_with_env_option_should_run_rake_command_in_env
|
def test_rake_with_env_option_should_run_rake_command_in_env
|
||||||
generator.expects(:run).once.with('rake log:clear RAILS_ENV=production', verbose: false)
|
@mock_generator.expect(:call, nil, ['rake log:clear RAILS_ENV=production', verbose: false])
|
||||||
|
generator.stub(:run, @mock_generator) do
|
||||||
action :rake, 'log:clear', env: 'production'
|
action :rake, 'log:clear', env: 'production'
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_rake_with_rails_env_variable_should_run_rake_command_in_env
|
def test_rake_with_rails_env_variable_should_run_rake_command_in_env
|
||||||
generator.expects(:run).once.with('rake log:clear RAILS_ENV=production', verbose: false)
|
@mock_generator.expect(:call, nil, ['rake log:clear RAILS_ENV=production', verbose: false])
|
||||||
|
generator.stub(:run, @mock_generator) do
|
||||||
with_rails_env "production" do
|
with_rails_env "production" do
|
||||||
action :rake, 'log:clear'
|
action :rake, 'log:clear'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_env_option_should_win_over_rails_env_variable_when_running_rake
|
def test_env_option_should_win_over_rails_env_variable_when_running_rake
|
||||||
generator.expects(:run).once.with('rake log:clear RAILS_ENV=production', verbose: false)
|
@mock_generator.expect(:call, nil, ['rake log:clear RAILS_ENV=production', verbose: false])
|
||||||
|
generator.stub(:run, @mock_generator) do
|
||||||
with_rails_env "staging" do
|
with_rails_env "staging" do
|
||||||
action :rake, 'log:clear', env: 'production'
|
action :rake, 'log:clear', env: 'production'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_rake_with_sudo_option_should_run_rake_command_with_sudo
|
def test_rake_with_sudo_option_should_run_rake_command_with_sudo
|
||||||
generator.expects(:run).once.with("sudo rake log:clear RAILS_ENV=development", verbose: false)
|
@mock_generator.expect(:call, nil, ["sudo rake log:clear RAILS_ENV=development", verbose: false])
|
||||||
|
generator.stub(:run, @mock_generator) do
|
||||||
with_rails_env nil do
|
with_rails_env nil do
|
||||||
action :rake, 'log:clear', sudo: true
|
action :rake, 'log:clear', sudo: true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_capify_should_run_the_capify_command
|
def test_capify_should_run_the_capify_command
|
||||||
generator.expects(:run).once.with('capify .', verbose: false)
|
@mock_generator.expect(:call, nil, ['capify .', verbose: false])
|
||||||
|
generator.stub(:run, @mock_generator) do
|
||||||
action :capify!
|
action :capify!
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_route_should_add_data_to_the_routes_block_in_config_routes
|
def test_route_should_add_data_to_the_routes_block_in_config_routes
|
||||||
run_generator
|
run_generator
|
||||||
|
@ -245,16 +266,20 @@ F
|
||||||
|
|
||||||
def test_readme
|
def test_readme
|
||||||
run_generator
|
run_generator
|
||||||
Rails::Generators::AppGenerator.expects(:source_root).times(2).returns(destination_root)
|
2.times { @mock_generator.expect(:call, destination_root,[]) }
|
||||||
|
Rails::Generators::AppGenerator.stub(:source_root, @mock_generator) do
|
||||||
assert_match "application up and running", action(:readme, "README.md")
|
assert_match "application up and running", action(:readme, "README.md")
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_readme_with_quiet
|
def test_readme_with_quiet
|
||||||
generator(default_arguments, quiet: true)
|
generator(default_arguments, quiet: true)
|
||||||
run_generator
|
run_generator
|
||||||
Rails::Generators::AppGenerator.expects(:source_root).times(2).returns(destination_root)
|
2.times { @mock_generator.expect(:call, destination_root,[]) }
|
||||||
|
Rails::Generators::AppGenerator.stub(:source_root, @mock_generator) do
|
||||||
assert_no_match "application up and running", action(:readme, "README.md")
|
assert_no_match "application up and running", action(:readme, "README.md")
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_log
|
def test_log
|
||||||
assert_equal("YES\n", action(:log, "YES"))
|
assert_equal("YES\n", action(:log, "YES"))
|
||||||
|
|
Loading…
Reference in a new issue