Sha256: ebf721c8fc3cb2b4c2cd98efaca01bbc4becb8f9420a07deb1271b9313bd2abb

Contents?: true

Size: 1.46 KB

Versions: 143

Compression:

Stored size: 1.46 KB

Contents

require 'spec_helper'
require 'aruba/rspec'

Aruba.configure do |c|
  c.activate_announcer_on_command_failure = %i(stderr stdout)
end

describe "remove_matching()", type: :aruba do
  it "removes matching files" do
    here %w(foo bar/baz bar/xyzzy zork)
    there %w(foo bar/baz not)
    remove_matching
    expect(contents_of herepath).to match_array %w(zork bar bar/xyzzy)
  end
  
  it "also handles files with spaces in names" do
    here ['foo', 'bar/baz', 'with space', 'with', 'bar/another space']
    there ['with space', 'bar/another space here']
    remove_matching
    expect(contents_of herepath).to match_array ['foo', 'bar', 'bar/baz', 'with', 'bar/another space']
  end
  
  # auxiliary methods and setup
  let(:herepath) { Pathname.new Dir.mktmpdir }
  let(:therepath) { Pathname.new Dir.mktmpdir }
  after { [herepath, therepath].each &FileUtils.method(:remove_entry) }

  def contents_of dir
    Dir.chdir(dir) { Dir['**/*'] }
  end

  def remove_matching
    run_command_and_stop "bash -c 'source #{DEBIFY_UTILS_PATH}; cd #{herepath}; remove_matching #{therepath}'"
  end
  
  def here files
    mkfiles herepath, files
  end
  
  def there files
    mkfiles therepath, files
  end

  def mkfiles dir, files  
    return dir if files.empty?
    files.each do |path|
      fullpath = dir + path
      FileUtils.makedirs fullpath.dirname
      FileUtils.touch fullpath
    end
  end
  
  DEBIFY_UTILS_PATH = File.expand_path '../../lib/conjur/fpm/debify_utils.sh', __FILE__
end

Version data entries

143 entries across 143 versions & 1 rubygems

Version Path
conjur-debify-3.0.3.pre.216 spec/debify_utils_spec.rb
conjur-debify-3.0.3.pre.145 spec/debify_utils_spec.rb
conjur-debify-3.0.3.pre.10 spec/debify_utils_spec.rb
conjur-debify-3.0.3.pre.9 spec/debify_utils_spec.rb
conjur-debify-3.0.3.pre.2005 spec/debify_utils_spec.rb
conjur-debify-3.0.3.pre.1981 spec/debify_utils_spec.rb
conjur-debify-3.0.3.pre.1971 spec/debify_utils_spec.rb
conjur-debify-3.0.3.pre.1967 spec/debify_utils_spec.rb
conjur-debify-3.0.3.pre.1965 spec/debify_utils_spec.rb
conjur-debify-3.0.3.pre.1963 spec/debify_utils_spec.rb
conjur-debify-3.0.3.pre.1961 spec/debify_utils_spec.rb
conjur-debify-3.0.3.pre.1959 spec/debify_utils_spec.rb
conjur-debify-3.0.3.pre.1957 spec/debify_utils_spec.rb
conjur-debify-3.0.3.pre.1956 spec/debify_utils_spec.rb
conjur-debify-3.0.3.pre.1954 spec/debify_utils_spec.rb
conjur-debify-3.0.3.pre.1952 spec/debify_utils_spec.rb
conjur-debify-3.0.3.pre.1950 spec/debify_utils_spec.rb
conjur-debify-3.0.3.pre.1948 spec/debify_utils_spec.rb
conjur-debify-3.0.3.pre.1946 spec/debify_utils_spec.rb
conjur-debify-3.0.3.pre.1944 spec/debify_utils_spec.rb