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 'rails/generators/rails/app/app_generator'
|
||||
require 'generators/shared_generator_tests'
|
||||
require 'mocha/setup' # FIXME: stop using mocha
|
||||
|
||||
DEFAULT_APP_FILES = %w(
|
||||
.gitignore
|
||||
|
@ -117,10 +116,8 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
|||
|
||||
run_generator [app_root]
|
||||
|
||||
Rails.application.config.root = app_moved_root
|
||||
Rails.application.class.stubs(:name).returns("Myapp")
|
||||
Rails.application.stubs(:is_a?).returns(Rails::Application)
|
||||
|
||||
stub_rails_application(app_moved_root) do
|
||||
Rails.application.stub(:is_a?, -> *args { Rails::Application }) do
|
||||
FileUtils.mv(app_root, app_moved_root)
|
||||
|
||||
# make sure we are in correct dir
|
||||
|
@ -133,20 +130,20 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
|||
assert_file "myapp_moved/config/environment.rb", /Rails\.application\.initialize!/
|
||||
assert_file "myapp_moved/config/initializers/session_store.rb", /_myapp_session/
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_rails_update_generates_correct_session_key
|
||||
app_root = File.join(destination_root, 'myapp')
|
||||
run_generator [app_root]
|
||||
|
||||
Rails.application.config.root = app_root
|
||||
Rails.application.class.stubs(:name).returns("Myapp")
|
||||
Rails.application.stubs(:is_a?).returns(Rails::Application)
|
||||
|
||||
stub_rails_application(app_root) do
|
||||
generator = Rails::Generators::AppGenerator.new ["rails"], { with_dispatchers: true }, destination_root: app_root, shell: @shell
|
||||
generator.send(:app_const)
|
||||
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
|
||||
run_generator
|
||||
|
@ -158,15 +155,13 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
|||
app_root = File.join(destination_root, 'myapp')
|
||||
run_generator [app_root]
|
||||
|
||||
Rails.application.config.root = app_root
|
||||
Rails.application.class.stubs(:name).returns("Myapp")
|
||||
Rails.application.stubs(:is_a?).returns(Rails::Application)
|
||||
|
||||
stub_rails_application(app_root) do
|
||||
generator = Rails::Generators::AppGenerator.new ["rails"], { with_dispatchers: true }, destination_root: app_root, shell: @shell
|
||||
generator.send(:app_const)
|
||||
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
|
||||
app_root = File.join(destination_root, 'myapp')
|
||||
|
@ -174,15 +169,13 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
|||
|
||||
FileUtils.rm("#{app_root}/config/initializers/callback_terminator.rb")
|
||||
|
||||
Rails.application.config.root = app_root
|
||||
Rails.application.class.stubs(:name).returns("Myapp")
|
||||
Rails.application.stubs(:is_a?).returns(Rails::Application)
|
||||
|
||||
stub_rails_application(app_root) do
|
||||
generator = Rails::Generators::AppGenerator.new ["rails"], { with_dispatchers: true }, destination_root: app_root, shell: @shell
|
||||
generator.send(:app_const)
|
||||
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
|
||||
app_root = File.join(destination_root, 'myapp')
|
||||
|
@ -190,15 +183,13 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
|||
|
||||
FileUtils.touch("#{app_root}/config/initializers/callback_terminator.rb")
|
||||
|
||||
Rails.application.config.root = app_root
|
||||
Rails.application.class.stubs(:name).returns("Myapp")
|
||||
Rails.application.stubs(:is_a?).returns(Rails::Application)
|
||||
|
||||
stub_rails_application(app_root) do
|
||||
generator = Rails::Generators::AppGenerator.new ["rails"], { with_dispatchers: true }, destination_root: app_root, shell: @shell
|
||||
generator.send(:app_const)
|
||||
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
|
||||
app_root = File.join(destination_root, 'myapp')
|
||||
|
@ -206,15 +197,13 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
|||
|
||||
FileUtils.rm("#{app_root}/config/initializers/cookies_serializer.rb")
|
||||
|
||||
Rails.application.config.root = app_root
|
||||
Rails.application.class.stubs(:name).returns("Myapp")
|
||||
Rails.application.stubs(:is_a?).returns(Rails::Application)
|
||||
|
||||
stub_rails_application(app_root) do
|
||||
generator = Rails::Generators::AppGenerator.new ["rails"], { with_dispatchers: true }, destination_root: app_root, shell: @shell
|
||||
generator.send(:app_const)
|
||||
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
|
||||
app_root = File.join(destination_root, 'myapp')
|
||||
|
@ -222,15 +211,13 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
|||
|
||||
FileUtils.rm("#{app_root}/config/initializers/active_record_belongs_to_required_by_default.rb")
|
||||
|
||||
Rails.application.config.root = app_root
|
||||
Rails.application.class.stubs(:name).returns("Myapp")
|
||||
Rails.application.stubs(:is_a?).returns(Rails::Application)
|
||||
|
||||
stub_rails_application(app_root) do
|
||||
generator = Rails::Generators::AppGenerator.new ["rails"], { with_dispatchers: true }, destination_root: app_root, shell: @shell
|
||||
generator.send(:app_const)
|
||||
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
|
||||
app_root = File.join(destination_root, 'myapp')
|
||||
|
@ -238,15 +225,13 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
|||
|
||||
FileUtils.touch("#{app_root}/config/initializers/active_record_belongs_to_required_by_default.rb")
|
||||
|
||||
Rails.application.config.root = app_root
|
||||
Rails.application.class.stubs(:name).returns("Myapp")
|
||||
Rails.application.stubs(:is_a?).returns(Rails::Application)
|
||||
|
||||
stub_rails_application(app_root) do
|
||||
generator = Rails::Generators::AppGenerator.new ["rails"], { with_dispatchers: true }, destination_root: app_root, shell: @shell
|
||||
generator.send(:app_const)
|
||||
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
|
||||
run_generator [File.join(destination_root, "hats")]
|
||||
|
@ -456,14 +441,16 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
|||
end
|
||||
|
||||
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
|
||||
end
|
||||
end
|
||||
|
||||
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)
|
||||
end
|
||||
end
|
||||
|
||||
def test_default_namespace
|
||||
assert_match "rails:app", Rails::Generators::AppGenerator.namespace
|
||||
|
@ -538,20 +525,33 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
|||
|
||||
def test_spring_binstubs
|
||||
jruby_skip "spring doesn't run on JRuby"
|
||||
generator.stubs(:bundle_command).with('install')
|
||||
generator.expects(:bundle_command).with('exec spring binstub --all').once
|
||||
command_check = -> command do
|
||||
@binstub_called ||= 0
|
||||
|
||||
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
|
||||
|
||||
def test_spring_no_fork
|
||||
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
|
||||
|
||||
assert_file "Gemfile" do |content|
|
||||
assert_no_match(/spring/, content)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_skip_spring
|
||||
run_generator [destination_root, "--skip-spring"]
|
||||
|
@ -651,18 +651,37 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
|||
template = %{ after_bundle { run 'echo ran after_bundle' } }
|
||||
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')
|
||||
generator.expects(:bundle_command).with('install').once.in_sequence(bundler_first)
|
||||
generator.expects(:bundle_command).with('exec spring binstub --all').in_sequence(bundler_first)
|
||||
generator.expects(:run).with('echo ran after_bundle').in_sequence(bundler_first)
|
||||
sequence = ['install', 'exec spring binstub --all', 'echo ran after_bundle']
|
||||
ensure_bundler_first = -> command do
|
||||
@sequence_step ||= 0
|
||||
|
||||
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
|
||||
|
||||
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)
|
||||
capture(:stdout) { generator.send(*args, &block) }
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue