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.2.pre.1905 spec/debify_utils_spec.rb
conjur-debify-3.0.2.pre.1899 spec/debify_utils_spec.rb
conjur-debify-3.0.2.pre.1898 spec/debify_utils_spec.rb
conjur-debify-3.0.2.pre.1896 spec/debify_utils_spec.rb
conjur-debify-3.0.2.pre.1894 spec/debify_utils_spec.rb
conjur-debify-3.0.2.pre.1893 spec/debify_utils_spec.rb
conjur-debify-3.0.2.pre.1891 spec/debify_utils_spec.rb
conjur-debify-3.0.2.pre.1890 spec/debify_utils_spec.rb
conjur-debify-3.0.2.pre.1888 spec/debify_utils_spec.rb
conjur-debify-3.0.2.pre.1886 spec/debify_utils_spec.rb
conjur-debify-3.0.2.pre.1884 spec/debify_utils_spec.rb
conjur-debify-3.0.2.pre.1882 spec/debify_utils_spec.rb
conjur-debify-3.0.2.pre.1880 spec/debify_utils_spec.rb
conjur-debify-3.0.2.pre.1878 spec/debify_utils_spec.rb
conjur-debify-3.0.2.pre.1875 spec/debify_utils_spec.rb
conjur-debify-3.0.2.pre.1873 spec/debify_utils_spec.rb
conjur-debify-3.0.2.pre.1871 spec/debify_utils_spec.rb
conjur-debify-3.0.2.pre.1868 spec/debify_utils_spec.rb
conjur-debify-3.0.2.pre.1866 spec/debify_utils_spec.rb
conjur-debify-3.0.2.pre.1865 spec/debify_utils_spec.rb