-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmatchers.rb
More file actions
33 lines (26 loc) · 745 Bytes
/
matchers.rb
File metadata and controls
33 lines (26 loc) · 745 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# frozen_string_literal: true
require "rspec/expectations"
RSpec::Matchers.define :have_content do |expected|
match do |actual|
File.read(actual) == expected
end
failure_message do |actual|
"expected that `#{actual}' would have content '#{expected}', but it has '#{File.read(actual)}'"
end
end
RSpec::Matchers.define :be_found do
match do |actual|
subject.exist?(actual)
end
failure_message do |actual|
"expected `#{actual}' to exist"
end
end
RSpec::Matchers.define :have_file_contents do |expected|
match do |actual|
subject.read(actual) == expected
end
failure_message do |actual|
"expected that `#{actual}' would have content '#{expected}', but it has '#{subject.read(actual)}'"
end
end