Sha256: f440cf4a31f0ee9c314856d9f2bb716e54335c9d1590374e9622e8ba4e2921cc

Contents?: true

Size: 1.71 KB

Versions: 34

Compression:

Stored size: 1.71 KB

Contents

require 'rspec/expectations/version'

# @!method have_file_content(content)
#   This matchers checks if <file> has content. `content` can be a string,
#   regexp or an RSpec matcher.
#
#   @param [String, Regexp, Matcher] content
#     Specifies the content of the file
#
#   @return [TrueClass, FalseClass] The result
#
#     false:
#     * if file does not exist
#     * if file content is not equal string
#     * if file content does not include regexp
#     * if file content does not match the content specification
#
#     true:
#     * if file content includes regexp
#     * if file content is equal string
#     * if file content matches the content specification
#
#   @example Use matcher with string
#
#     RSpec.describe do
#       it { expect(file1).to have_file_content('a') }
#     end
#
#   @example Use matcher with regexp
#
#     RSpec.describe do
#       it { expect(file1).to have_file_content(/a/) }
#     end
#
#   @example Use matcher with an RSpec matcher
#
#     RSpec.describe do
#       it { expect(file1).to have_file_content(a_string_starting_with 'a') }
#       it { expect(files1).to include a_file_having_content(a_string_starting_with 'a') }
#     end
RSpec::Matchers.define :have_file_content do |expected|
  match do |actual|
    stop_all_commands

    next false unless file? actual

    @actual   = read(actual).join("\n").chomp
    @expected = if expected.is_a? String
                  expected.chomp
                else
                  expected
                end

    values_match?(@expected, @actual)
  end

  description { "have file content: #{description_of expected}" }
end

if RSpec::Expectations::Version::STRING >= '3.0'
  RSpec::Matchers.alias_matcher :a_file_having_content, :have_file_content
end

Version data entries

34 entries across 34 versions & 3 rubygems

Version Path
aruba-0.14.14 lib/aruba/matchers/file/have_file_content.rb
aruba-0.14.13 lib/aruba/matchers/file/have_file_content.rb
honeybadger-4.5.3 vendor/bundle/ruby/2.6.0/gems/aruba-0.14.12/lib/aruba/matchers/file/have_file_content.rb
aruba-0.14.12 lib/aruba/matchers/file/have_file_content.rb
aruba-0.14.11 lib/aruba/matchers/file/have_file_content.rb
aruba-0.14.10 lib/aruba/matchers/file/have_file_content.rb
aruba-0.14.9 lib/aruba/matchers/file/have_file_content.rb
aruba-0.14.8 lib/aruba/matchers/file/have_file_content.rb
aruba-0.14.7 lib/aruba/matchers/file/have_file_content.rb
aruba-0.14.6 lib/aruba/matchers/file/have_file_content.rb
aruba-0.14.5 lib/aruba/matchers/file/have_file_content.rb
aruba-0.14.4 lib/aruba/matchers/file/have_file_content.rb
aruba-0.14.3 lib/aruba/matchers/file/have_file_content.rb
aruba-1.0.0.pre.alpha.2 lib/aruba/matchers/file/have_file_content.rb
aruba-1.0.0.pre.alpha.1 lib/aruba/matchers/file/have_file_content.rb
aruba-win-fix-0.14.2 lib/aruba/matchers/file/have_file_content.rb
aruba-0.14.2 lib/aruba/matchers/file/have_file_content.rb
aruba-0.14.1 lib/aruba/matchers/file/have_file_content.rb
aruba-0.14.0 lib/aruba/matchers/file/have_file_content.rb
aruba-0.13.0 lib/aruba/matchers/file/have_file_content.rb