Permalink
Browse files

Update the customer matchers so they're actually useful.

  • Loading branch information...
1 parent 969815b commit 5537b5e5cb52b562ac33440c436fc5bf68a143f4 @blatyo blatyo committed Mar 27, 2012
Showing with 9 additions and 6 deletions.
  1. +9 −6 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
@@ -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
@@ -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

0 comments on commit 5537b5e

Please sign in to comment.