Skip to content

Commit

Permalink
Update the customer matchers so they're actually useful.
Browse files Browse the repository at this point in the history
  • Loading branch information
blatyo committed Mar 27, 2012
1 parent 969815b commit 5537b5e
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions spec/custom_matchers.rb
@@ -1,10 +1,11 @@
RSpec::Matchers.define :bencode_to do |expected|
match do |actual|
actual.bencode.should equal(expected)
@got = actual.bencode
@got.should equal(expected)
end

failure_message_for_should do |actual|
"expected that #{actual} would bencode to #{expected}"
"expected that #{actual.inspect} would bencode to #{expected.inspect}, but got #{@got.inspect}}"
end
end

Expand All @@ -14,11 +15,12 @@
end

match do |klass|
klass.bencode(actual).should == @_expected
@got = klass.bencode(actual)
@got.should == @_expected
end

failure_message_for_should do |klass|
"expected #{klass.name} to bencode #{actual} to #{@_expected}"
"expected #{klass.name} to bencode #{actual.inspect} to #{@_expected.inspect}, but got #{@got.inspect}"
end
end

Expand All @@ -33,11 +35,12 @@

match do |klass|
scanner = StringScanner.new(actual)
klass.send(:"parse_#{@type}", scanner).should == @_expected
@got = klass.send(:"parse_#{@type}", scanner)
@got.should == @_expected
end

failure_message_for_should do |klass|
"expected #{klass.name} to bdencode #{actual} as #{@type} to #{@_expected}"
"expected #{klass.name} to bdencode #{actual.inspect} as #{@type} to #{@_expected.inspect}, but got #{@got.inspect}"
end
end

Expand Down

0 comments on commit 5537b5e

Please sign in to comment.