Sha256: b23960c75281bf95ecc31186ceb965c50911322b3302fd0d3ba4e8375ebfb91e

Contents?: true

Size: 1.26 KB

Versions: 27

Compression:

Stored size: 1.26 KB

Contents

require "rspec/expectations"

# expect('/path/to/directory').to be_a_directory
RSpec::Matchers.define :be_a_directory do
  match do |actual|
    File.directory?(actual)
  end
end

# expect('/path/to/directory').to be_a_file
RSpec::Matchers.define :be_a_file do
  match do |actual|
    File.file?(actual)
  end
end

# expect('/path/to/file').to have_content
RSpec::Matchers.define :have_content do |content|
  match do |actual|
    IO.read(actual) == content
  end
end

# expect('/path/to/file').to have_permissions
RSpec::Matchers.define :have_permissions do |perm|
  match do |actual|
    m = sprintf("%o", File.stat(actual).mode)
    m == perm
  end
end

# expect('/path/to/directory').to be_a_symlink
RSpec::Matchers.define :be_a_symlink do
  match do |actual|
    File.symlink?(actual)
  end
end

# expect('/path/to/directory').to be_a_symlink_to
RSpec::Matchers.define :be_a_symlink_to do |path|
  match do |actual|
    File.symlink?(actual) && File.readlink(actual) == path
  end
end

# expect('/path/to/file').to be_an_executable
RSpec::Matchers.define :be_an_executable do
  match do |actual|
    File.executable?(actual)
  end
end

# expect('/path/to/file').to be_a_hardlink
RSpec::Matchers.define :be_a_hardlink do |path|
  match do |actual|
    File.stat(actual).nlink > 2
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
omnibus-9.0.24 spec/support/matchers.rb
omnibus-9.0.23 spec/support/matchers.rb
omnibus-9.0.22 spec/support/matchers.rb
omnibus-9.0.17 spec/support/matchers.rb
omnibus-9.0.12 spec/support/matchers.rb
omnibus-9.0.11 spec/support/matchers.rb
omnibus-9.0.8 spec/support/matchers.rb
omnibus-8.3.2 spec/support/matchers.rb
omnibus-8.2.2 spec/support/matchers.rb
omnibus-8.1.15 spec/support/matchers.rb
omnibus-8.0.15 spec/support/matchers.rb
omnibus-8.0.9 spec/support/matchers.rb
omnibus-7.0.34 spec/support/matchers.rb
omnibus-7.0.13 spec/support/matchers.rb
omnibus-7.0.12 spec/support/matchers.rb
omnibus-6.1.9 spec/support/matchers.rb
omnibus-6.1.7 spec/support/matchers.rb
omnibus-6.1.4 spec/support/matchers.rb
omnibus-6.0.30 spec/support/matchers.rb
omnibus-6.0.25 spec/support/matchers.rb