Sha256: 43e7a660c7e9cf64612a6c94cfea14dcd99b60ef525852ef065ab8c21cb9e664

Contents?: true

Size: 608 Bytes

Versions: 5

Compression:

Stored size: 608 Bytes

Contents

RSpec::Matchers.define :contain do |expected_content|
  match do |file_path|
    @actual_contents = File.new(file_path).read
    case expected_content
      when String
        @actual_contents == expected_content
      when Regexp
        @actual_contents =~ expected_content
    end
  end
  
  failure_message_for_should do |file_path|
    "expected the file #{file_path} to contain #{expected_content.inspect} but it contained #{@actual_contents.inspect}"
  end
  
  failure_message_for_should_not do |relative|
    "expected the file #{file_path} to not contain #{expected_content} but it did"
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ammeter-0.1.1 lib/ammeter/rspec/generator/matchers/contain.rb
ammeter-0.1.0 lib/ammeter/rspec/generator/matchers/contain.rb
ammeter-0.0.3 lib/ammeter/rspec/generator/matchers/contain.rb
ammeter-0.0.2 lib/ammeter/rspec/generator/matchers/contain.rb
ammeter-0.0.1 lib/ammeter/rspec/generator/matchers/contain.rb