Sha256: 1c6a4b6a1566ea7551dc69a1557ae83a4cf4ffa8c7524d5be18df75e55ed5c47

Contents?: true

Size: 799 Bytes

Versions: 9

Compression:

Stored size: 799 Bytes

Contents

RSpec::Matchers.define :create_file do |expected|
  match do |block|
    @before = exists?(expected)
    block.call
    @after = exists?(expected)
    !@before && @after
  end

  failure_message do |_block|
    existed_before_message expected do
      "The file #{expected.inspect} was not created"
    end
  end

  failure_message_when_negated do |_block|
    existed_before_message expected do
      "The file #{expected.inspect} was created"
    end
  end

  def supports_block_expectations?
    true
  end

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

  def existed_before_message(expected)
    if @before
      "The file #{expected.inspect} existed before, so this test doesn't work"
    else
      yield
    end
  end
end

Version data entries

9 entries across 9 versions & 3 rubygems

Version Path
metric_fu-4.13.0 spec/support/matcher_create_file.rb
fastruby-metric_fu-5.0.0 spec/support/matcher_create_file.rb
code_metric_fu-4.14.4 spec/support/matcher_create_file.rb
code_metric_fu-4.14.3 spec/support/matcher_create_file.rb
code_metric_fu-4.14.2 spec/support/matcher_create_file.rb
code_metric_fu-4.14.1 spec/support/matcher_create_file.rb
code_metric_fu-4.14.0 spec/support/matcher_create_file.rb
metric_fu-4.12.0 spec/support/matcher_create_file.rb
metric_fu-4.11.4 spec/support/matcher_create_file.rb