CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/spec/support/matchers/match_table.rb
Views: 11623
1
RSpec::Matchers.define :match_table do |expected|
2
diffable
3
4
match do |actual|
5
@actual = actual.to_s.strip
6
@expected = expected.to_s.strip
7
8
@actual == @expected
9
end
10
11
failure_message do |actual|
12
<<~MSG
13
Expected:
14
#{with_whitespace_highlighted(expected.to_s.strip)}
15
Received:
16
#{with_whitespace_highlighted(actual.to_s.strip)}
17
Raw Result:
18
#{actual}
19
MSG
20
end
21
22
def with_whitespace_highlighted(string)
23
string.lines.map { |line| "'#{line.gsub("\n", '')}'" }.join("\n")
24
end
25
end
26
27