mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Remove some more globals from tests
We are using blocks here so we have access to the environment around them, no need for globals.
This commit is contained in:
parent
32f49612e7
commit
5d4fce640e
1 changed files with 26 additions and 26 deletions
|
@ -72,26 +72,26 @@ module ApplicationTests
|
|||
end
|
||||
|
||||
def test_rake_tasks_defined_on_different_applications_go_to_the_same_class
|
||||
$run_count = 0
|
||||
run_count = 0
|
||||
|
||||
application1 = AppTemplate::Application.new
|
||||
application1.rake_tasks do
|
||||
$run_count += 1
|
||||
run_count += 1
|
||||
end
|
||||
|
||||
application2 = AppTemplate::Application.new
|
||||
application2.rake_tasks do
|
||||
$run_count += 1
|
||||
run_count += 1
|
||||
end
|
||||
|
||||
require "#{app_path}/config/environment"
|
||||
|
||||
assert_equal 0, $run_count, "The count should stay at zero without any calls to the rake tasks"
|
||||
assert_equal 0, run_count, "The count should stay at zero without any calls to the rake tasks"
|
||||
require 'rake'
|
||||
require 'rake/testtask'
|
||||
require 'rdoc/task'
|
||||
Rails.application.load_tasks
|
||||
assert_equal 2, $run_count, "Calling a rake task should result in two increments to the count"
|
||||
assert_equal 2, run_count, "Calling a rake task should result in two increments to the count"
|
||||
end
|
||||
|
||||
def test_multiple_applications_can_be_initialized
|
||||
|
@ -100,56 +100,56 @@ module ApplicationTests
|
|||
|
||||
def test_initializers_run_on_different_applications_go_to_the_same_class
|
||||
application1 = AppTemplate::Application.new
|
||||
$run_count = 0
|
||||
run_count = 0
|
||||
|
||||
AppTemplate::Application.initializer :init0 do
|
||||
$run_count += 1
|
||||
run_count += 1
|
||||
end
|
||||
|
||||
application1.initializer :init1 do
|
||||
$run_count += 1
|
||||
run_count += 1
|
||||
end
|
||||
|
||||
AppTemplate::Application.new.initializer :init2 do
|
||||
$run_count += 1
|
||||
run_count += 1
|
||||
end
|
||||
|
||||
assert_equal 0, $run_count, "Without loading the initializers, the count should be 0"
|
||||
assert_equal 0, run_count, "Without loading the initializers, the count should be 0"
|
||||
|
||||
# Set config.eager_load to false so that an eager_load warning doesn't pop up
|
||||
AppTemplate::Application.new { config.eager_load = false }.initialize!
|
||||
|
||||
assert_equal 3, $run_count, "There should have been three initializers that incremented the count"
|
||||
assert_equal 3, run_count, "There should have been three initializers that incremented the count"
|
||||
end
|
||||
|
||||
def test_consoles_run_on_different_applications_go_to_the_same_class
|
||||
$run_count = 0
|
||||
AppTemplate::Application.console { $run_count += 1 }
|
||||
AppTemplate::Application.new.console { $run_count += 1 }
|
||||
run_count = 0
|
||||
AppTemplate::Application.console { run_count += 1 }
|
||||
AppTemplate::Application.new.console { run_count += 1 }
|
||||
|
||||
assert_equal 0, $run_count, "Without loading the consoles, the count should be 0"
|
||||
assert_equal 0, run_count, "Without loading the consoles, the count should be 0"
|
||||
Rails.application.load_console
|
||||
assert_equal 2, $run_count, "There should have been two consoles that increment the count"
|
||||
assert_equal 2, run_count, "There should have been two consoles that increment the count"
|
||||
end
|
||||
|
||||
def test_generators_run_on_different_applications_go_to_the_same_class
|
||||
$run_count = 0
|
||||
AppTemplate::Application.generators { $run_count += 1 }
|
||||
AppTemplate::Application.new.generators { $run_count += 1 }
|
||||
run_count = 0
|
||||
AppTemplate::Application.generators { run_count += 1 }
|
||||
AppTemplate::Application.new.generators { run_count += 1 }
|
||||
|
||||
assert_equal 0, $run_count, "Without loading the generators, the count should be 0"
|
||||
assert_equal 0, run_count, "Without loading the generators, the count should be 0"
|
||||
Rails.application.load_generators
|
||||
assert_equal 2, $run_count, "There should have been two generators that increment the count"
|
||||
assert_equal 2, run_count, "There should have been two generators that increment the count"
|
||||
end
|
||||
|
||||
def test_runners_run_on_different_applications_go_to_the_same_class
|
||||
$run_count = 0
|
||||
AppTemplate::Application.runner { $run_count += 1 }
|
||||
AppTemplate::Application.new.runner { $run_count += 1 }
|
||||
run_count = 0
|
||||
AppTemplate::Application.runner { run_count += 1 }
|
||||
AppTemplate::Application.new.runner { run_count += 1 }
|
||||
|
||||
assert_equal 0, $run_count, "Without loading the runners, the count should be 0"
|
||||
assert_equal 0, run_count, "Without loading the runners, the count should be 0"
|
||||
Rails.application.load_runner
|
||||
assert_equal 2, $run_count, "There should have been two runners that increment the count"
|
||||
assert_equal 2, run_count, "There should have been two runners that increment the count"
|
||||
end
|
||||
|
||||
def test_isolate_namespace_on_an_application
|
||||
|
|
Loading…
Reference in a new issue