mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Remove use of mocha in the railties path tests
This commit is contained in:
parent
1622298428
commit
b36f159adf
1 changed files with 88 additions and 59 deletions
|
@ -1,10 +1,9 @@
|
||||||
require 'abstract_unit'
|
require 'abstract_unit'
|
||||||
require 'rails/paths'
|
require 'rails/paths'
|
||||||
require 'mocha/setup' # FIXME: stop using mocha
|
require 'minitest/mock'
|
||||||
|
|
||||||
class PathsTest < ActiveSupport::TestCase
|
class PathsTest < ActiveSupport::TestCase
|
||||||
def setup
|
def setup
|
||||||
File.stubs(:exist?).returns(true)
|
|
||||||
@root = Rails::Paths::Root.new("/foo/bar")
|
@root = Rails::Paths::Root.new("/foo/bar")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -93,11 +92,13 @@ class PathsTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it is possible to add a path that should be autoloaded only once" do
|
test "it is possible to add a path that should be autoloaded only once" do
|
||||||
|
File.stub(:exist?, true) do
|
||||||
@root.add "app", with: "/app"
|
@root.add "app", with: "/app"
|
||||||
@root["app"].autoload_once!
|
@root["app"].autoload_once!
|
||||||
assert @root["app"].autoload_once?
|
assert @root["app"].autoload_once?
|
||||||
assert @root.autoload_once.include?(@root["app"].expanded.first)
|
assert @root.autoload_once.include?(@root["app"].expanded.first)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
test "it is possible to remove a path that should be autoloaded only once" do
|
test "it is possible to remove a path that should be autoloaded only once" do
|
||||||
@root["app"] = "/app"
|
@root["app"] = "/app"
|
||||||
|
@ -110,38 +111,48 @@ class PathsTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it is possible to add a path without assignment and specify it should be loaded only once" do
|
test "it is possible to add a path without assignment and specify it should be loaded only once" do
|
||||||
|
File.stub(:exist?, true) do
|
||||||
@root.add "app", with: "/app", autoload_once: true
|
@root.add "app", with: "/app", autoload_once: true
|
||||||
assert @root["app"].autoload_once?
|
assert @root["app"].autoload_once?
|
||||||
assert @root.autoload_once.include?("/app")
|
assert @root.autoload_once.include?("/app")
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
test "it is possible to add multiple paths without assignment and specify it should be loaded only once" do
|
test "it is possible to add multiple paths without assignment and specify it should be loaded only once" do
|
||||||
|
File.stub(:exist?, true) do
|
||||||
@root.add "app", with: ["/app", "/app2"], autoload_once: true
|
@root.add "app", with: ["/app", "/app2"], autoload_once: true
|
||||||
assert @root["app"].autoload_once?
|
assert @root["app"].autoload_once?
|
||||||
assert @root.autoload_once.include?("/app")
|
assert @root.autoload_once.include?("/app")
|
||||||
assert @root.autoload_once.include?("/app2")
|
assert @root.autoload_once.include?("/app2")
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
test "making a path autoload_once more than once only includes it once in @root.load_once" do
|
test "making a path autoload_once more than once only includes it once in @root.load_once" do
|
||||||
|
File.stub(:exist?, true) do
|
||||||
@root["app"] = "/app"
|
@root["app"] = "/app"
|
||||||
@root["app"].autoload_once!
|
@root["app"].autoload_once!
|
||||||
@root["app"].autoload_once!
|
@root["app"].autoload_once!
|
||||||
assert_equal 1, @root.autoload_once.select {|p| p == @root["app"].expanded.first }.size
|
assert_equal 1, @root.autoload_once.select {|p| p == @root["app"].expanded.first }.size
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
test "paths added to a load_once path should be added to the autoload_once collection" do
|
test "paths added to a load_once path should be added to the autoload_once collection" do
|
||||||
|
File.stub(:exist?, true) do
|
||||||
@root["app"] = "/app"
|
@root["app"] = "/app"
|
||||||
@root["app"].autoload_once!
|
@root["app"].autoload_once!
|
||||||
@root["app"] << "/app2"
|
@root["app"] << "/app2"
|
||||||
assert_equal 2, @root.autoload_once.size
|
assert_equal 2, @root.autoload_once.size
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
test "it is possible to mark a path as eager loaded" do
|
test "it is possible to mark a path as eager loaded" do
|
||||||
|
File.stub(:exist?, true) do
|
||||||
@root["app"] = "/app"
|
@root["app"] = "/app"
|
||||||
@root["app"].eager_load!
|
@root["app"].eager_load!
|
||||||
assert @root["app"].eager_load?
|
assert @root["app"].eager_load?
|
||||||
assert @root.eager_load.include?(@root["app"].to_a.first)
|
assert @root.eager_load.include?(@root["app"].to_a.first)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
test "it is possible to skip a path from eager loading" do
|
test "it is possible to skip a path from eager loading" do
|
||||||
@root["app"] = "/app"
|
@root["app"] = "/app"
|
||||||
|
@ -154,39 +165,49 @@ class PathsTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it is possible to add a path without assignment and mark it as eager" do
|
test "it is possible to add a path without assignment and mark it as eager" do
|
||||||
|
File.stub(:exist?, true) do
|
||||||
@root.add "app", with: "/app", eager_load: true
|
@root.add "app", with: "/app", eager_load: true
|
||||||
assert @root["app"].eager_load?
|
assert @root["app"].eager_load?
|
||||||
assert @root.eager_load.include?("/app")
|
assert @root.eager_load.include?("/app")
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
test "it is possible to add multiple paths without assignment and mark them as eager" do
|
test "it is possible to add multiple paths without assignment and mark them as eager" do
|
||||||
|
File.stub(:exist?, true) do
|
||||||
@root.add "app", with: ["/app", "/app2"], eager_load: true
|
@root.add "app", with: ["/app", "/app2"], eager_load: true
|
||||||
assert @root["app"].eager_load?
|
assert @root["app"].eager_load?
|
||||||
assert @root.eager_load.include?("/app")
|
assert @root.eager_load.include?("/app")
|
||||||
assert @root.eager_load.include?("/app2")
|
assert @root.eager_load.include?("/app2")
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
test "it is possible to create a path without assignment and mark it both as eager and load once" do
|
test "it is possible to create a path without assignment and mark it both as eager and load once" do
|
||||||
|
File.stub(:exist?, true) do
|
||||||
@root.add "app", with: "/app", eager_load: true, autoload_once: true
|
@root.add "app", with: "/app", eager_load: true, autoload_once: true
|
||||||
assert @root["app"].eager_load?
|
assert @root["app"].eager_load?
|
||||||
assert @root["app"].autoload_once?
|
assert @root["app"].autoload_once?
|
||||||
assert @root.eager_load.include?("/app")
|
assert @root.eager_load.include?("/app")
|
||||||
assert @root.autoload_once.include?("/app")
|
assert @root.autoload_once.include?("/app")
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
test "making a path eager more than once only includes it once in @root.eager_paths" do
|
test "making a path eager more than once only includes it once in @root.eager_paths" do
|
||||||
|
File.stub(:exist?, true) do
|
||||||
@root["app"] = "/app"
|
@root["app"] = "/app"
|
||||||
@root["app"].eager_load!
|
@root["app"].eager_load!
|
||||||
@root["app"].eager_load!
|
@root["app"].eager_load!
|
||||||
assert_equal 1, @root.eager_load.select {|p| p == @root["app"].expanded.first }.size
|
assert_equal 1, @root.eager_load.select {|p| p == @root["app"].expanded.first }.size
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
test "paths added to an eager_load path should be added to the eager_load collection" do
|
test "paths added to an eager_load path should be added to the eager_load collection" do
|
||||||
|
File.stub(:exist?, true) do
|
||||||
@root["app"] = "/app"
|
@root["app"] = "/app"
|
||||||
@root["app"].eager_load!
|
@root["app"].eager_load!
|
||||||
@root["app"] << "/app2"
|
@root["app"] << "/app2"
|
||||||
assert_equal 2, @root.eager_load.size
|
assert_equal 2, @root.eager_load.size
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
test "it should be possible to add a path's default glob" do
|
test "it should be possible to add a path's default glob" do
|
||||||
@root["app"] = "/app"
|
@root["app"] = "/app"
|
||||||
|
@ -207,28 +228,36 @@ class PathsTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
test "a path can be added to the load path" do
|
test "a path can be added to the load path" do
|
||||||
|
File.stub(:exist?, true) do
|
||||||
@root["app"] = "app"
|
@root["app"] = "app"
|
||||||
@root["app"].load_path!
|
@root["app"].load_path!
|
||||||
@root["app/models"] = "app/models"
|
@root["app/models"] = "app/models"
|
||||||
assert_equal ["/foo/bar/app"], @root.load_paths
|
assert_equal ["/foo/bar/app"], @root.load_paths
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
test "a path can be added to the load path on creation" do
|
test "a path can be added to the load path on creation" do
|
||||||
|
File.stub(:exist?, true) do
|
||||||
@root.add "app", with: "/app", load_path: true
|
@root.add "app", with: "/app", load_path: true
|
||||||
assert @root["app"].load_path?
|
assert @root["app"].load_path?
|
||||||
assert_equal ["/app"], @root.load_paths
|
assert_equal ["/app"], @root.load_paths
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
test "a path can be marked as autoload path" do
|
test "a path can be marked as autoload path" do
|
||||||
|
File.stub(:exist?, true) do
|
||||||
@root["app"] = "app"
|
@root["app"] = "app"
|
||||||
@root["app"].autoload!
|
@root["app"].autoload!
|
||||||
@root["app/models"] = "app/models"
|
@root["app/models"] = "app/models"
|
||||||
assert_equal ["/foo/bar/app"], @root.autoload_paths
|
assert_equal ["/foo/bar/app"], @root.autoload_paths
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
test "a path can be marked as autoload on creation" do
|
test "a path can be marked as autoload on creation" do
|
||||||
|
File.stub(:exist?, true) do
|
||||||
@root.add "app", with: "/app", autoload: true
|
@root.add "app", with: "/app", autoload: true
|
||||||
assert @root["app"].autoload?
|
assert @root["app"].autoload?
|
||||||
assert_equal ["/app"], @root.autoload_paths
|
assert_equal ["/app"], @root.autoload_paths
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue