mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #21721 from ronakjangir47/remove_mocha_railties_app_generator
Removed Mocha from app generators tests
This commit is contained in:
commit
5c30e86dc4
1 changed files with 106 additions and 87 deletions
|
@ -1,7 +1,6 @@
|
||||||
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 'generators/shared_generator_tests'
|
require 'generators/shared_generator_tests'
|
||||||
require 'mocha/setup' # FIXME: stop using mocha
|
|
||||||
|
|
||||||
DEFAULT_APP_FILES = %w(
|
DEFAULT_APP_FILES = %w(
|
||||||
.gitignore
|
.gitignore
|
||||||
|
@ -117,35 +116,33 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
||||||
|
|
||||||
run_generator [app_root]
|
run_generator [app_root]
|
||||||
|
|
||||||
Rails.application.config.root = app_moved_root
|
stub_rails_application(app_moved_root) do
|
||||||
Rails.application.class.stubs(:name).returns("Myapp")
|
Rails.application.stub(:is_a?, -> *args { Rails::Application }) do
|
||||||
Rails.application.stubs(:is_a?).returns(Rails::Application)
|
FileUtils.mv(app_root, app_moved_root)
|
||||||
|
|
||||||
FileUtils.mv(app_root, app_moved_root)
|
# make sure we are in correct dir
|
||||||
|
FileUtils.cd(app_moved_root)
|
||||||
|
|
||||||
# make sure we are in correct dir
|
generator = Rails::Generators::AppGenerator.new ["rails"], { with_dispatchers: true },
|
||||||
FileUtils.cd(app_moved_root)
|
destination_root: app_moved_root, shell: @shell
|
||||||
|
generator.send(:app_const)
|
||||||
generator = Rails::Generators::AppGenerator.new ["rails"], { with_dispatchers: true },
|
quietly { generator.send(:update_config_files) }
|
||||||
destination_root: app_moved_root, shell: @shell
|
assert_file "myapp_moved/config/environment.rb", /Rails\.application\.initialize!/
|
||||||
generator.send(:app_const)
|
assert_file "myapp_moved/config/initializers/session_store.rb", /_myapp_session/
|
||||||
quietly { generator.send(:update_config_files) }
|
end
|
||||||
assert_file "myapp_moved/config/environment.rb", /Rails\.application\.initialize!/
|
end
|
||||||
assert_file "myapp_moved/config/initializers/session_store.rb", /_myapp_session/
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_rails_update_generates_correct_session_key
|
def test_rails_update_generates_correct_session_key
|
||||||
app_root = File.join(destination_root, 'myapp')
|
app_root = File.join(destination_root, 'myapp')
|
||||||
run_generator [app_root]
|
run_generator [app_root]
|
||||||
|
|
||||||
Rails.application.config.root = app_root
|
stub_rails_application(app_root) do
|
||||||
Rails.application.class.stubs(:name).returns("Myapp")
|
generator = Rails::Generators::AppGenerator.new ["rails"], { with_dispatchers: true }, destination_root: app_root, shell: @shell
|
||||||
Rails.application.stubs(:is_a?).returns(Rails::Application)
|
generator.send(:app_const)
|
||||||
|
quietly { generator.send(:update_config_files) }
|
||||||
generator = Rails::Generators::AppGenerator.new ["rails"], { with_dispatchers: true }, destination_root: app_root, shell: @shell
|
assert_file "myapp/config/initializers/session_store.rb", /_myapp_session/
|
||||||
generator.send(:app_const)
|
end
|
||||||
quietly { generator.send(:update_config_files) }
|
|
||||||
assert_file "myapp/config/initializers/session_store.rb", /_myapp_session/
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_new_application_use_json_serialzier
|
def test_new_application_use_json_serialzier
|
||||||
|
@ -158,14 +155,12 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
||||||
app_root = File.join(destination_root, 'myapp')
|
app_root = File.join(destination_root, 'myapp')
|
||||||
run_generator [app_root]
|
run_generator [app_root]
|
||||||
|
|
||||||
Rails.application.config.root = app_root
|
stub_rails_application(app_root) do
|
||||||
Rails.application.class.stubs(:name).returns("Myapp")
|
generator = Rails::Generators::AppGenerator.new ["rails"], { with_dispatchers: true }, destination_root: app_root, shell: @shell
|
||||||
Rails.application.stubs(:is_a?).returns(Rails::Application)
|
generator.send(:app_const)
|
||||||
|
quietly { generator.send(:update_config_files) }
|
||||||
generator = Rails::Generators::AppGenerator.new ["rails"], { with_dispatchers: true }, destination_root: app_root, shell: @shell
|
assert_file("#{app_root}/config/initializers/cookies_serializer.rb", /Rails\.application\.config\.action_dispatch\.cookies_serializer = :json/)
|
||||||
generator.send(:app_const)
|
end
|
||||||
quietly { generator.send(:update_config_files) }
|
|
||||||
assert_file("#{app_root}/config/initializers/cookies_serializer.rb", /Rails\.application\.config\.action_dispatch\.cookies_serializer = :json/)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_rails_update_does_not_create_callback_terminator_initializer
|
def test_rails_update_does_not_create_callback_terminator_initializer
|
||||||
|
@ -174,14 +169,12 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
||||||
|
|
||||||
FileUtils.rm("#{app_root}/config/initializers/callback_terminator.rb")
|
FileUtils.rm("#{app_root}/config/initializers/callback_terminator.rb")
|
||||||
|
|
||||||
Rails.application.config.root = app_root
|
stub_rails_application(app_root) do
|
||||||
Rails.application.class.stubs(:name).returns("Myapp")
|
generator = Rails::Generators::AppGenerator.new ["rails"], { with_dispatchers: true }, destination_root: app_root, shell: @shell
|
||||||
Rails.application.stubs(:is_a?).returns(Rails::Application)
|
generator.send(:app_const)
|
||||||
|
quietly { generator.send(:update_config_files) }
|
||||||
generator = Rails::Generators::AppGenerator.new ["rails"], { with_dispatchers: true }, destination_root: app_root, shell: @shell
|
assert_no_file "#{app_root}/config/initializers/callback_terminator.rb"
|
||||||
generator.send(:app_const)
|
end
|
||||||
quietly { generator.send(:update_config_files) }
|
|
||||||
assert_no_file "#{app_root}/config/initializers/callback_terminator.rb"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_rails_update_does_not_remove_callback_terminator_initializer_if_already_present
|
def test_rails_update_does_not_remove_callback_terminator_initializer_if_already_present
|
||||||
|
@ -190,14 +183,12 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
||||||
|
|
||||||
FileUtils.touch("#{app_root}/config/initializers/callback_terminator.rb")
|
FileUtils.touch("#{app_root}/config/initializers/callback_terminator.rb")
|
||||||
|
|
||||||
Rails.application.config.root = app_root
|
stub_rails_application(app_root) do
|
||||||
Rails.application.class.stubs(:name).returns("Myapp")
|
generator = Rails::Generators::AppGenerator.new ["rails"], { with_dispatchers: true }, destination_root: app_root, shell: @shell
|
||||||
Rails.application.stubs(:is_a?).returns(Rails::Application)
|
generator.send(:app_const)
|
||||||
|
quietly { generator.send(:update_config_files) }
|
||||||
generator = Rails::Generators::AppGenerator.new ["rails"], { with_dispatchers: true }, destination_root: app_root, shell: @shell
|
assert_file "#{app_root}/config/initializers/callback_terminator.rb"
|
||||||
generator.send(:app_const)
|
end
|
||||||
quietly { generator.send(:update_config_files) }
|
|
||||||
assert_file "#{app_root}/config/initializers/callback_terminator.rb"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_rails_update_set_the_cookie_serializer_to_marchal_if_it_is_not_already_configured
|
def test_rails_update_set_the_cookie_serializer_to_marchal_if_it_is_not_already_configured
|
||||||
|
@ -206,14 +197,12 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
||||||
|
|
||||||
FileUtils.rm("#{app_root}/config/initializers/cookies_serializer.rb")
|
FileUtils.rm("#{app_root}/config/initializers/cookies_serializer.rb")
|
||||||
|
|
||||||
Rails.application.config.root = app_root
|
stub_rails_application(app_root) do
|
||||||
Rails.application.class.stubs(:name).returns("Myapp")
|
generator = Rails::Generators::AppGenerator.new ["rails"], { with_dispatchers: true }, destination_root: app_root, shell: @shell
|
||||||
Rails.application.stubs(:is_a?).returns(Rails::Application)
|
generator.send(:app_const)
|
||||||
|
quietly { generator.send(:update_config_files) }
|
||||||
generator = Rails::Generators::AppGenerator.new ["rails"], { with_dispatchers: true }, destination_root: app_root, shell: @shell
|
assert_file("#{app_root}/config/initializers/cookies_serializer.rb", /Rails\.application\.config\.action_dispatch\.cookies_serializer = :marshal/)
|
||||||
generator.send(:app_const)
|
end
|
||||||
quietly { generator.send(:update_config_files) }
|
|
||||||
assert_file("#{app_root}/config/initializers/cookies_serializer.rb", /Rails\.application\.config\.action_dispatch\.cookies_serializer = :marshal/)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_rails_update_does_not_create_active_record_belongs_to_required_by_default
|
def test_rails_update_does_not_create_active_record_belongs_to_required_by_default
|
||||||
|
@ -222,14 +211,12 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
||||||
|
|
||||||
FileUtils.rm("#{app_root}/config/initializers/active_record_belongs_to_required_by_default.rb")
|
FileUtils.rm("#{app_root}/config/initializers/active_record_belongs_to_required_by_default.rb")
|
||||||
|
|
||||||
Rails.application.config.root = app_root
|
stub_rails_application(app_root) do
|
||||||
Rails.application.class.stubs(:name).returns("Myapp")
|
generator = Rails::Generators::AppGenerator.new ["rails"], { with_dispatchers: true }, destination_root: app_root, shell: @shell
|
||||||
Rails.application.stubs(:is_a?).returns(Rails::Application)
|
generator.send(:app_const)
|
||||||
|
quietly { generator.send(:update_config_files) }
|
||||||
generator = Rails::Generators::AppGenerator.new ["rails"], { with_dispatchers: true }, destination_root: app_root, shell: @shell
|
assert_no_file "#{app_root}/config/initializers/active_record_belongs_to_required_by_default.rb"
|
||||||
generator.send(:app_const)
|
end
|
||||||
quietly { generator.send(:update_config_files) }
|
|
||||||
assert_no_file "#{app_root}/config/initializers/active_record_belongs_to_required_by_default.rb"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_rails_update_does_not_remove_active_record_belongs_to_required_by_default_if_already_present
|
def test_rails_update_does_not_remove_active_record_belongs_to_required_by_default_if_already_present
|
||||||
|
@ -238,14 +225,12 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
||||||
|
|
||||||
FileUtils.touch("#{app_root}/config/initializers/active_record_belongs_to_required_by_default.rb")
|
FileUtils.touch("#{app_root}/config/initializers/active_record_belongs_to_required_by_default.rb")
|
||||||
|
|
||||||
Rails.application.config.root = app_root
|
stub_rails_application(app_root) do
|
||||||
Rails.application.class.stubs(:name).returns("Myapp")
|
generator = Rails::Generators::AppGenerator.new ["rails"], { with_dispatchers: true }, destination_root: app_root, shell: @shell
|
||||||
Rails.application.stubs(:is_a?).returns(Rails::Application)
|
generator.send(:app_const)
|
||||||
|
quietly { generator.send(:update_config_files) }
|
||||||
generator = Rails::Generators::AppGenerator.new ["rails"], { with_dispatchers: true }, destination_root: app_root, shell: @shell
|
assert_file "#{app_root}/config/initializers/active_record_belongs_to_required_by_default.rb"
|
||||||
generator.send(:app_const)
|
end
|
||||||
quietly { generator.send(:update_config_files) }
|
|
||||||
assert_file "#{app_root}/config/initializers/active_record_belongs_to_required_by_default.rb"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_application_names_are_not_singularized
|
def test_application_names_are_not_singularized
|
||||||
|
@ -456,13 +441,15 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_usage_read_from_file
|
def test_usage_read_from_file
|
||||||
File.expects(:read).returns("USAGE FROM FILE")
|
assert_called(File, :read, returns: "USAGE FROM FILE") do
|
||||||
assert_equal "USAGE FROM FILE", Rails::Generators::AppGenerator.desc
|
assert_equal "USAGE FROM FILE", Rails::Generators::AppGenerator.desc
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_default_usage
|
def test_default_usage
|
||||||
Rails::Generators::AppGenerator.expects(:usage_path).returns(nil)
|
assert_called(Rails::Generators::AppGenerator, :usage_path, returns: nil) do
|
||||||
assert_match(/Create rails files for app generator/, Rails::Generators::AppGenerator.desc)
|
assert_match(/Create rails files for app generator/, Rails::Generators::AppGenerator.desc)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_default_namespace
|
def test_default_namespace
|
||||||
|
@ -538,18 +525,31 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
||||||
|
|
||||||
def test_spring_binstubs
|
def test_spring_binstubs
|
||||||
jruby_skip "spring doesn't run on JRuby"
|
jruby_skip "spring doesn't run on JRuby"
|
||||||
generator.stubs(:bundle_command).with('install')
|
command_check = -> command do
|
||||||
generator.expects(:bundle_command).with('exec spring binstub --all').once
|
@binstub_called ||= 0
|
||||||
quietly { generator.invoke_all }
|
|
||||||
|
case command
|
||||||
|
when 'install'
|
||||||
|
# Called when running bundle, we just want to stub it so nothing to do here.
|
||||||
|
when 'exec spring binstub --all'
|
||||||
|
@binstub_called += 1
|
||||||
|
assert_equal 1, @binstub_called, "exec spring binstub --all expected to be called once, but was called #{@install_called} times."
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
generator.stub :bundle_command, command_check do
|
||||||
|
quietly { generator.invoke_all }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_spring_no_fork
|
def test_spring_no_fork
|
||||||
jruby_skip "spring doesn't run on JRuby"
|
jruby_skip "spring doesn't run on JRuby"
|
||||||
Process.stubs(:respond_to?).with(:fork).returns(false)
|
assert_called_with(Process, :respond_to?, [:fork], returns: false) do
|
||||||
run_generator
|
run_generator
|
||||||
|
|
||||||
assert_file "Gemfile" do |content|
|
assert_file "Gemfile" do |content|
|
||||||
assert_no_match(/spring/, content)
|
assert_no_match(/spring/, content)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -651,18 +651,37 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
||||||
template = %{ after_bundle { run 'echo ran after_bundle' } }
|
template = %{ after_bundle { run 'echo ran after_bundle' } }
|
||||||
template.instance_eval "def read; self; end" # Make the string respond to read
|
template.instance_eval "def read; self; end" # Make the string respond to read
|
||||||
|
|
||||||
generator([destination_root], template: path).expects(:open).with(path, 'Accept' => 'application/x-thor-template').returns(template)
|
check_open = -> *args do
|
||||||
|
assert_equal [ path, 'Accept' => 'application/x-thor-template' ], args
|
||||||
|
template
|
||||||
|
end
|
||||||
|
|
||||||
bundler_first = sequence('bundle, binstubs, after_bundle')
|
sequence = ['install', 'exec spring binstub --all', 'echo ran after_bundle']
|
||||||
generator.expects(:bundle_command).with('install').once.in_sequence(bundler_first)
|
ensure_bundler_first = -> command do
|
||||||
generator.expects(:bundle_command).with('exec spring binstub --all').in_sequence(bundler_first)
|
@sequence_step ||= 0
|
||||||
generator.expects(:run).with('echo ran after_bundle').in_sequence(bundler_first)
|
|
||||||
|
|
||||||
quietly { generator.invoke_all }
|
assert_equal sequence[@sequence_step], command, "commands should be called in sequence #{sequence}"
|
||||||
|
@sequence_step += 1
|
||||||
|
end
|
||||||
|
|
||||||
|
generator([destination_root], template: path).stub(:open, check_open, template) do
|
||||||
|
generator.stub(:bundle_command, ensure_bundler_first) do
|
||||||
|
generator.stub(:run, ensure_bundler_first) do
|
||||||
|
quietly { generator.invoke_all }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
|
def stub_rails_application(root)
|
||||||
|
Rails.application.config.root = root
|
||||||
|
Rails.application.class.stub(:name, "Myapp") do
|
||||||
|
yield
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def action(*args, &block)
|
def action(*args, &block)
|
||||||
capture(:stdout) { generator.send(*args, &block) }
|
capture(:stdout) { generator.send(*args, &block) }
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue