Sha256: 303616385013e9077c42e245318ae039c92da4b7b8c794ea34cbd3f4bdb154a4

Contents?: true

Size: 908 Bytes

Versions: 18

Compression:

Stored size: 908 Bytes

Contents

RSpec::Matchers.define :create_files do |expected|

  match do |block|
    @before = false
    @after = true
    expected.each do |file|
      @before |= exists?(file)
    end
    block.call
    expected.each do |file|
      @after &= exists?(file)
    end
    !@before && @after
  end

  failure_message_for_should do |block|
    existed_before_message expected do
      "One or more files in [#{expected.inspect}] was not created."
    end
  end

  failure_message_for_should_not do |block|
    existed_before_message expected do
      "The files in [#{expected.inspect}] were created."
    end
  end

  def exists?(expected)
    # Allows us to use wildcard checks for existence.
    !Dir.glob(expected).empty?
  end

  def existed_before_message(expected)
    if @before
      "One or more files in  [#{expected.inspect}] existed before, so this test doesn't work"
    else
      yield
    end
  end

end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
metric_fu-4.10.0 spec/support/matcher_create_files.rb
metric_fu-4.9.0 spec/support/matcher_create_files.rb
metric_fu-4.8.0 spec/support/matcher_create_files.rb
metric_fu-4.7.4 spec/support/matcher_create_files.rb
metric_fu-4.7.3 spec/support/matcher_create_files.rb
metric_fu-4.7.2 spec/support/matcher_create_files.rb
metric_fu-4.7.1 spec/support/matcher_create_files.rb
metric_fu-4.7.0 spec/support/matcher_create_files.rb
metric_fu-4.6.0 spec/support/matcher_create_files.rb
metric_fu-4.5.2 spec/support/matcher_create_files.rb
metric_fu-4.5.1 spec/support/matcher_create_files.rb
metric_fu-4.4.4 spec/support/matcher_create_files.rb
metric_fu-4.4.3 spec/support/matcher_create_files.rb
metric_fu-4.4.2 spec/support/matcher_create_files.rb
metric_fu-4.4.1 spec/support/matcher_create_files.rb
metric_fu-4.4.0 spec/support/matcher_create_files.rb
metric_fu-4.3.1 spec/support/matcher_create_files.rb
metric_fu-4.3.0 spec/support/matcher_create_files.rb