Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
application loader refactor and test suite complete rewrite
- Loading branch information
Showing
2 changed files
with
71 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,62 @@ | ||
require 'pathname' | ||
require 'abstract_unit' | ||
require 'rails/app_rails_loader' | ||
|
||
class AppRailsLoaderTest < ActiveSupport::TestCase | ||
def write(filename, contents=nil) | ||
FileUtils.mkdir_p(Pathname.new(filename).dirname) | ||
File.write(filename, contents) | ||
end | ||
|
||
def expects_exec(exe) | ||
Rails::AppRailsLoader.expects(:exec).with(Rails::AppRailsLoader::RUBY, exe) | ||
end | ||
|
||
setup do | ||
File.stubs(:exists?).returns(false) | ||
@tmp = Dir.mktmpdir('railties-rails-loader-test-suite') | ||
@cwd = Dir.pwd | ||
Dir.chdir(@tmp) | ||
end | ||
|
||
['bin/rails', 'script/rails'].each do |exe| | ||
test "is in a rails application if #{exe} exists and contains APP_PATH" do | ||
File.stubs(:exists?).with(exe).returns(true) | ||
File.stubs(:read).with(exe).returns('APP_PATH') | ||
assert Rails::AppRailsLoader.find_executable | ||
end | ||
['bin', 'script'].each do |script_dir| | ||
exe = "#{script_dir}/rails" | ||
|
||
test "is not in a Rails application if #{exe} is not found in the current or parent directories" do | ||
File.stubs(:exists?).with('bin/rails').returns(false) | ||
File.stubs(:exists?).with('script/rails').returns(false) | ||
|
||
test "is not in a rails application if #{exe} exists but doesn't contain APP_PATH" do | ||
File.stubs(:exists?).with(exe).returns(true) | ||
File.stubs(:read).with(exe).returns("railties #{exe}") | ||
assert !Rails::AppRailsLoader.exec_app_rails | ||
end | ||
|
||
test "is in a rails application if parent directory has #{exe} containing APP_PATH" do | ||
File.stubs(:exists?).with("/foo/bar/#{exe}").returns(false) | ||
File.stubs(:exists?).with("/foo/#{exe}").returns(true) | ||
File.stubs(:read).with("/foo/#{exe}").returns('APP_PATH') | ||
assert_equal Rails::AppRailsLoader.find_executable_in_parent_path(Pathname.new("/foo/bar")), "/foo/#{exe}" | ||
end | ||
['APP_PATH', 'ENGINE_PATH'].each do |keyword| | ||
test "is in a Rails application if #{exe} exists and contains #{keyword}" do | ||
write exe, keyword | ||
|
||
test "is not in a rails application if at the root directory and doesn't have #{exe}" do | ||
Pathname.any_instance.stubs(:root?).returns true | ||
assert !Rails::AppRailsLoader.find_executable | ||
end | ||
expects_exec exe | ||
Rails::AppRailsLoader.exec_app_rails | ||
end | ||
|
||
test "is in a rails engine if parent directory has #{exe} containing ENGINE_PATH" do | ||
File.stubs(:exists?).with("/foo/bar/#{exe}").returns(false) | ||
File.stubs(:exists?).with("/foo/#{exe}").returns(true) | ||
File.stubs(:read).with("/foo/#{exe}").returns('ENGINE_PATH') | ||
assert Rails::AppRailsLoader.find_executable_in_parent_path(Pathname.new("/foo/bar")), "/foo/#{exe}" | ||
end | ||
test "is not in a Rails application if #{exe} exists but doesn't contain #{keyword}" do | ||
write exe | ||
|
||
assert !Rails::AppRailsLoader.exec_app_rails | ||
end | ||
|
||
test "is in a rails application if parent directory has #{exe} containing #{keyword} and chdirs to the root directory" do | ||
write "foo/bar/#{exe}" | ||
write "foo/#{exe}", keyword | ||
|
||
test "is in a rails engine if #{exe} exists containing ENGINE_PATH" do | ||
File.stubs(:exists?).with(exe).returns(true) | ||
File.stubs(:read).with(exe).returns('ENGINE_PATH') | ||
assert Rails::AppRailsLoader.find_executable | ||
Dir.chdir('foo/bar') | ||
|
||
expects_exec exe | ||
Rails::AppRailsLoader.exec_app_rails | ||
assert_equal File.join(@tmp, 'foo'), Dir.pwd | ||
end | ||
end | ||
end | ||
|
||
teardown do | ||
Dir.chdir(@cwd) | ||
FileUtils.rm_rf(@tmp) | ||
end | ||
end |
85de183
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ππβ€οΈππ
85de183
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π€