Sha256: 10c8f30a1aeedc9e7e538c3a1db6db13a230eae084af8479f4e8e3ad0e75e87c

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

module RSpec::FileMatchers
  class HaveFileItems
    attr_accessor :file_items

    def initialize(*file_items)
      self.file_items = file_items.flatten
    end

    def matches? x=nil, &block
      file_item_names.each do |location|       
        return false if  !File.send(:"#{artifact}?", location)
      end
      true
    end          

    def file_item_names
      @file_item_names ||= file_items.map(&:to_s)
    end

    def artifact
      raise "artifact method must be overridden by subclass"
    end
  
    def failure_message                                                               
      return "Expected #{artifact} #{file_item_names.first} to exist, but it did not" if file_items.size == 1
      "Expected #{artifact.pluralize} [#{file_item_names}] to exist, but they did not"
    end

    def negative_failure_message
      return "Did not expect #{artifact} #{file_item_names.first} to exist, but it did" if file_items.size == 1
      "Did not expect #{artifact.pluralize} [#{file_item_names}] to exist, but they did"
    end    
  end

  def have_file_items(*args)
    HaveFileItems.new(args)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
file-spec-0.1.0 lib/file_spec/matchers/abstract/have_file_items.rb