mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #20022 from repinel/remove-mocha1
Remove use of mocha in the railties path tests
This commit is contained in:
commit
f271f43f10
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,10 +92,12 @@ 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
|
||||||
@root.add "app", with: "/app"
|
File.stub(:exist?, true) do
|
||||||
@root["app"].autoload_once!
|
@root.add "app", with: "/app"
|
||||||
assert @root["app"].autoload_once?
|
@root["app"].autoload_once!
|
||||||
assert @root.autoload_once.include?(@root["app"].expanded.first)
|
assert @root["app"].autoload_once?
|
||||||
|
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
|
||||||
|
@ -110,37 +111,47 @@ 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
|
||||||
@root.add "app", with: "/app", autoload_once: true
|
File.stub(:exist?, true) do
|
||||||
assert @root["app"].autoload_once?
|
@root.add "app", with: "/app", autoload_once: true
|
||||||
assert @root.autoload_once.include?("/app")
|
assert @root["app"].autoload_once?
|
||||||
|
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
|
||||||
@root.add "app", with: ["/app", "/app2"], autoload_once: true
|
File.stub(:exist?, true) do
|
||||||
assert @root["app"].autoload_once?
|
@root.add "app", with: ["/app", "/app2"], autoload_once: true
|
||||||
assert @root.autoload_once.include?("/app")
|
assert @root["app"].autoload_once?
|
||||||
assert @root.autoload_once.include?("/app2")
|
assert @root.autoload_once.include?("/app")
|
||||||
|
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
|
||||||
@root["app"] = "/app"
|
File.stub(:exist?, true) do
|
||||||
@root["app"].autoload_once!
|
@root["app"] = "/app"
|
||||||
@root["app"].autoload_once!
|
@root["app"].autoload_once!
|
||||||
assert_equal 1, @root.autoload_once.select {|p| p == @root["app"].expanded.first }.size
|
@root["app"].autoload_once!
|
||||||
|
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
|
||||||
@root["app"] = "/app"
|
File.stub(:exist?, true) do
|
||||||
@root["app"].autoload_once!
|
@root["app"] = "/app"
|
||||||
@root["app"] << "/app2"
|
@root["app"].autoload_once!
|
||||||
assert_equal 2, @root.autoload_once.size
|
@root["app"] << "/app2"
|
||||||
|
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
|
||||||
@root["app"] = "/app"
|
File.stub(:exist?, true) do
|
||||||
@root["app"].eager_load!
|
@root["app"] = "/app"
|
||||||
assert @root["app"].eager_load?
|
@root["app"].eager_load!
|
||||||
assert @root.eager_load.include?(@root["app"].to_a.first)
|
assert @root["app"].eager_load?
|
||||||
|
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
|
||||||
|
@ -154,38 +165,48 @@ 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
|
||||||
@root.add "app", with: "/app", eager_load: true
|
File.stub(:exist?, true) do
|
||||||
assert @root["app"].eager_load?
|
@root.add "app", with: "/app", eager_load: true
|
||||||
assert @root.eager_load.include?("/app")
|
assert @root["app"].eager_load?
|
||||||
|
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
|
||||||
@root.add "app", with: ["/app", "/app2"], eager_load: true
|
File.stub(:exist?, true) do
|
||||||
assert @root["app"].eager_load?
|
@root.add "app", with: ["/app", "/app2"], eager_load: true
|
||||||
assert @root.eager_load.include?("/app")
|
assert @root["app"].eager_load?
|
||||||
assert @root.eager_load.include?("/app2")
|
assert @root.eager_load.include?("/app")
|
||||||
|
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
|
||||||
@root.add "app", with: "/app", eager_load: true, autoload_once: true
|
File.stub(:exist?, true) do
|
||||||
assert @root["app"].eager_load?
|
@root.add "app", with: "/app", eager_load: true, autoload_once: true
|
||||||
assert @root["app"].autoload_once?
|
assert @root["app"].eager_load?
|
||||||
assert @root.eager_load.include?("/app")
|
assert @root["app"].autoload_once?
|
||||||
assert @root.autoload_once.include?("/app")
|
assert @root.eager_load.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
|
||||||
@root["app"] = "/app"
|
File.stub(:exist?, true) do
|
||||||
@root["app"].eager_load!
|
@root["app"] = "/app"
|
||||||
@root["app"].eager_load!
|
@root["app"].eager_load!
|
||||||
assert_equal 1, @root.eager_load.select {|p| p == @root["app"].expanded.first }.size
|
@root["app"].eager_load!
|
||||||
|
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
|
||||||
@root["app"] = "/app"
|
File.stub(:exist?, true) do
|
||||||
@root["app"].eager_load!
|
@root["app"] = "/app"
|
||||||
@root["app"] << "/app2"
|
@root["app"].eager_load!
|
||||||
assert_equal 2, @root.eager_load.size
|
@root["app"] << "/app2"
|
||||||
|
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
|
||||||
|
@ -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
|
||||||
@root["app"] = "app"
|
File.stub(:exist?, true) do
|
||||||
@root["app"].load_path!
|
@root["app"] = "app"
|
||||||
@root["app/models"] = "app/models"
|
@root["app"].load_path!
|
||||||
assert_equal ["/foo/bar/app"], @root.load_paths
|
@root["app/models"] = "app/models"
|
||||||
|
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
|
||||||
@root.add "app", with: "/app", load_path: true
|
File.stub(:exist?, true) do
|
||||||
assert @root["app"].load_path?
|
@root.add "app", with: "/app", load_path: true
|
||||||
assert_equal ["/app"], @root.load_paths
|
assert @root["app"].load_path?
|
||||||
|
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
|
||||||
@root["app"] = "app"
|
File.stub(:exist?, true) do
|
||||||
@root["app"].autoload!
|
@root["app"] = "app"
|
||||||
@root["app/models"] = "app/models"
|
@root["app"].autoload!
|
||||||
assert_equal ["/foo/bar/app"], @root.autoload_paths
|
@root["app/models"] = "app/models"
|
||||||
|
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
|
||||||
@root.add "app", with: "/app", autoload: true
|
File.stub(:exist?, true) do
|
||||||
assert @root["app"].autoload?
|
@root.add "app", with: "/app", autoload: true
|
||||||
assert_equal ["/app"], @root.autoload_paths
|
assert @root["app"].autoload?
|
||||||
|
assert_equal ["/app"], @root.autoload_paths
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue