Stop using mocha on app_rails_loader_test

This commit is contained in:
Rafael Mendonça França 2014-07-07 22:05:30 -03:00
parent e0c6b35dac
commit fb9eb7019e
2 changed files with 27 additions and 10 deletions

View File

@ -2,6 +2,8 @@ require 'pathname'
module Rails
module AppRailsLoader
extend self
RUBY = Gem.ruby
EXECUTABLES = ['bin/rails', 'script/rails']
BUNDLER_WARNING = <<EOS
@ -26,7 +28,7 @@ generate it and add it to source control:
EOS
def self.exec_app_rails
def exec_app_rails
original_cwd = Dir.pwd
loop do
@ -54,7 +56,7 @@ EOS
end
end
def self.find_executable
def find_executable
EXECUTABLES.find { |exe| File.file?(exe) }
end
end

View File

@ -3,13 +3,27 @@ require 'abstract_unit'
require 'rails/app_rails_loader'
class AppRailsLoaderTest < ActiveSupport::TestCase
def loader
@loader ||= Class.new do
extend Rails::AppRailsLoader
def self.exec_arguments
@exec_arguments
end
def self.exec(*args)
@exec_arguments = args
end
end
end
def write(filename, contents=nil)
FileUtils.mkdir_p(File.dirname(filename))
File.write(filename, contents)
end
def expects_exec(exe)
Rails::AppRailsLoader.expects(:exec).with(Rails::AppRailsLoader::RUBY, exe)
assert_equal [Rails::AppRailsLoader::RUBY, exe], loader.exec_arguments
end
setup do
@ -22,30 +36,30 @@ class AppRailsLoaderTest < ActiveSupport::TestCase
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(:file?).with('bin/rails').returns(false)
File.stubs(:file?).with('script/rails').returns(false)
def loader.find_executables; end
assert !Rails::AppRailsLoader.exec_app_rails
assert !loader.exec_app_rails
end
test "is not in a Rails application if #{exe} exists but is a folder" do
FileUtils.mkdir_p(exe)
assert !Rails::AppRailsLoader.exec_app_rails
assert !loader.exec_app_rails
end
['APP_PATH', 'ENGINE_PATH'].each do |keyword|
test "is in a Rails application if #{exe} exists and contains #{keyword}" do
write exe, keyword
loader.exec_app_rails
expects_exec exe
Rails::AppRailsLoader.exec_app_rails
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
assert !loader.exec_app_rails
end
test "is in a Rails application if parent directory has #{exe} containing #{keyword} and chdirs to the root directory" do
@ -54,8 +68,9 @@ class AppRailsLoaderTest < ActiveSupport::TestCase
Dir.chdir('foo/bar')
loader.exec_app_rails
expects_exec exe
Rails::AppRailsLoader.exec_app_rails
# Compare the realpath in case either of them has symlinks.
#