Skip to content

Commit

Permalink
File.exists? been replaced with File.exist?
Browse files Browse the repository at this point in the history
  • Loading branch information
anatol committed Jan 28, 2018
1 parent 4f188f8 commit b804a45
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion lib/cerberus/latch.rb
Expand Up @@ -4,7 +4,7 @@ module Cerberus
class Latch
#Emulate File.flock
def self.lock(lock_file, options = {})
if File.exists?(lock_file)
if File.exist?(lock_file)
modif_time = File::Stat.new(lock_file).mtime
ttl = options[:lock_ttl]

Expand Down
8 changes: 4 additions & 4 deletions lib/cerberus/manager.rb
Expand Up @@ -25,7 +25,7 @@ def run
create_example_config

config_name = "#{HOME}/config/#{application_name}.yml"
say "Application #{application_name} already present in Cerberus" if File.exists?(config_name)
say "Application #{application_name} already present in Cerberus" if File.exist?(config_name)

app_config = {'scm' => {
'url' => scm.url,
Expand Down Expand Up @@ -55,7 +55,7 @@ class RemoveCommand
# classes a lot.

def initialize(application_name, cli_options = {})
unless File.exists?("#{HOME}/config/#{application_name}.yml")
unless File.exist?("#{HOME}/config/#{application_name}.yml")
say "Project '#{application_name}' does not exist in Cerberus. Type 'cerberus list' to see the list of all active projects."
end
@app_root = "#{HOME}/work/#{application_name}"
Expand All @@ -69,7 +69,7 @@ def run

config_name = "#{HOME}/config/#{application_name}.yml"

if not File.exists?(config_name)
if not File.exist?(config_name)
say "Unknown application #{application_name}"
exit(1)
end
Expand All @@ -89,7 +89,7 @@ class BuildCommand
:require_revision_change => false}

def initialize(application_name, cli_options = {})
unless File.exists?("#{HOME}/config/#{application_name}.yml")
unless File.exist?("#{HOME}/config/#{application_name}.yml")
say "Project '#{application_name}' does not exist in Cerberus. Type 'cerberus list' to see the list of all active projects."
end

Expand Down
2 changes: 1 addition & 1 deletion lib/cerberus/status.rb
Expand Up @@ -18,7 +18,7 @@ def initialize(param)
@already_kept = true
else
@path = param
value = File.exists?(@path) ? YAML.load(IO.read(@path)) : nil
value = File.exist?(@path) ? YAML.load(IO.read(@path)) : nil

@hash =
case value
Expand Down
4 changes: 2 additions & 2 deletions lib/cerberus/utils.rb
Expand Up @@ -22,14 +22,14 @@ def os
end

def dump_yml(file, what, overwrite = true)
if overwrite or not File.exists?(file)
if overwrite or not File.exist?(file)
FileUtils.mkpath(File.dirname(file))
File.open(file, 'w') { |f| YAML::dump(what, f) }
end
end

def load_yml(file_name, default = {})
File.exists?(file_name) ? YAML::load(IO.read(file_name)) : default
File.exist?(file_name) ? YAML::load(IO.read(file_name)) : default
end

def silence_stream(stream)
Expand Down
24 changes: 12 additions & 12 deletions test/functional_test.rb
Expand Up @@ -19,17 +19,17 @@ def teardown
end

def test_add_by_url
assert !File.exists?(HOME + '/config/svn_repo.yml')
assert !File.exist?(HOME + '/config/svn_repo.yml')

command = Cerberus::AddCommand.new(" #{SVN_URL} ", :quiet => true)
command.run

assert File.exists?(HOME + '/config/svn_repo.yml')
assert File.exist?(HOME + '/config/svn_repo.yml')
scm_conf = load_yml(HOME + '/config/svn_repo.yml')['scm']
assert_equal 'svn', scm_conf['type']
assert_equal SVN_URL, scm_conf['url']

assert File.exists?(HOME + '/config.yml')
assert File.exist?(HOME + '/config.yml')
end

def test_add_by_dir
Expand All @@ -42,14 +42,14 @@ def test_add_by_dir

project_config = HOME + "/config/#{File.basename(File.expand_path(sources_dir))}.yml" #name of added application should be calculated from File System path

assert File.exists?(project_config)
assert File.exist?(project_config)
scm_conf = load_yml(project_config)['scm']
assert_equal 'svn', scm_conf['type']
scm_uri = URI.parse(scm_conf['url'])
# FIXME - this assert needs to be fixed
# assert_match 'rubyforge.org', scm_uri.host

assert File.exists?(HOME + '/config.yml')
assert File.exist?(HOME + '/config.yml')
end

def test_build
Expand All @@ -68,14 +68,14 @@ def test_build
assert output =~ %r{http://someurl.changeset.com/2}

status_file = HOME + '/work/myapp/status.log'
assert File.exists?(status_file)
assert File.exist?(status_file)
assert build_successful?(status_file)
assert 1, Dir[HOME + "/work/rake_cust/logs/*-setup.log"].size

FileUtils.rm status_file
build = Cerberus::BuildCommand.new('myapp')
build.run
assert File.exists?(status_file)
assert File.exist?(status_file)
assert build_successful?(status_file)
assert_equal :setup, build.status.current_state
assert_equal 2, ActionMailer::Base.deliveries.size #first email that project was setup
Expand Down Expand Up @@ -176,7 +176,7 @@ def test_batch_running

for i in 1..4
status_file = HOME + "/work/myapp#{i}/status.log"
assert File.exists?(status_file)
assert File.exist?(status_file)
assert build_successful?(status_file)
end
end
Expand Down Expand Up @@ -210,7 +210,7 @@ def test_logs_disabled
build = Cerberus::BuildAllCommand.new
build.run

assert !File.exists?(HOME + "/work/rake_cust/logs")
assert !File.exist?(HOME + "/work/rake_cust/logs")
end

def test_darcs
Expand All @@ -229,7 +229,7 @@ def test_darcs
# assert_equal '[darcsapp] Cerberus set up for project (#20061010090920)', mail.subject

# status_file = HOME + '/work/darcsapp/status.log'
# assert File.exists?(status_file)
# assert File.exist?(status_file)
# assert build_successful?(status_file)
# assert 1, Dir[HOME + "/work/darcsapp/logs/*.log"].size

Expand Down Expand Up @@ -292,7 +292,7 @@ def test_git
assert_match /\[gitapp\] Cerberus set up for project/, mail.subject

status_file = HOME + '/work/gitapp/status.log'
assert File.exists?(status_file)
assert File.exist?(status_file)
assert build_successful?(status_file)
assert 1, Dir[HOME + "/work/gitapp/logs/*.log"].size

Expand Down Expand Up @@ -362,7 +362,7 @@ def test_mercurial
assert_match /\[hgapp\] Cerberus set up for project/, mail.subject

status_file = HOME + '/work/hgapp/status.log'
assert File.exists?(status_file)
assert File.exist?(status_file)
assert build_successful?(status_file)
assert 1, Dir[HOME + "/work/hgapp/logs/*.log"].size

Expand Down
12 changes: 6 additions & 6 deletions test/integration_test.rb
Expand Up @@ -14,13 +14,13 @@ def teardown
def test_add_project_as_url_subversion
output = run_cerb(" add #{SVN_URL} ")
assert_match /has been added to Cerberus successfully/, output
assert File.exists?(HOME + '/config/svn_repo.yml')
assert File.exist?(HOME + '/config/svn_repo.yml')
assert_equal SVN_URL, load_yml(HOME + '/config/svn_repo.yml')['scm']['url']

#try to add second time
output = run_cerb("add #{SVN_URL}")
assert_match /already present/, output
assert File.exists?(HOME + '/config/svn_repo.yml')
assert File.exist?(HOME + '/config/svn_repo.yml')
assert_equal SVN_URL, load_yml(HOME + '/config/svn_repo.yml')['scm']['url']
end

Expand All @@ -44,7 +44,7 @@ def test_add_project_with_parameters
output = run_cerb(" add #{SVN_URL} APPLICATION_NAME=hello_world RECIPIENTS=aa@gmail.com BUILDER=maven2")
assert_match /has been added to Cerberus successfully/, output

assert File.exists?(HOME + '/config/hello_world.yml')
assert File.exist?(HOME + '/config/hello_world.yml')
cfg = load_yml(HOME + '/config/hello_world.yml')

assert_equal 'svn', cfg['scm']['type']
Expand All @@ -57,15 +57,15 @@ def test_run_project
add_application('svn_repo', SVN_URL, 'quiet' => true)

run_cerb("build svn_repo")
assert File.exists?(HOME + '/work/svn_repo/status.log')
assert File.exist?(HOME + '/work/svn_repo/status.log')
assert build_successful?(HOME + '/work/svn_repo/status.log')
end

def test_add_darcs_scm
output = run_cerb(" add #{DARCS_URL} SCM=darcs")
assert_match /has been added to Cerberus successfully/, output

assert File.exists?(HOME + '/config/darcs_repo.yml')
assert File.exist?(HOME + '/config/darcs_repo.yml')
cfg = load_yml(HOME + '/config/darcs_repo.yml')

assert_equal 'darcs', cfg['scm']['type']
Expand All @@ -76,7 +76,7 @@ def test_add_git_scm
output = run_cerb(" add #{GIT_URL} SCM=git")
assert_match /has been added to Cerberus successfully/, output

assert File.exists?(HOME + '/config/git_repo.yml')
assert File.exist?(HOME + '/config/git_repo.yml')
cfg = load_yml(HOME + '/config/git_repo.yml')

assert_equal 'git', cfg['scm']['type']
Expand Down

0 comments on commit b804a45

Please sign in to comment.