Skip to content

Commit

Permalink
Merge pull request #8 from Fingertips/features/no-warnings
Browse files Browse the repository at this point in the history
Add an #eq matcher that works like ==
  • Loading branch information
Manfred committed Feb 13, 2017
2 parents 973acd0 + 22d714f commit bb710bc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/peck/expectations.rb
Expand Up @@ -132,6 +132,20 @@ def raise(exception_class=nil)
end
end

# Matches if the object equals another object using == internally. We use
# this method so you can write specs without triggering Ruby syntax
# warnings, but still test == equality.
def eq(other)
if @negated
description = "expected `#{@this}' to not == `#{other}'"
else
description = "expected `#{@this}' to == `#{other}'"
end
satisfy(description) do
@this == other
end
end

PREDICATE_METHOD_RE = /\w[^?]\z/
def method_missing(name, *args, &block)
name = "#{name}?" if name.to_s =~ PREDICATE_METHOD_RE
Expand Down
12 changes: 12 additions & 0 deletions spec/expectations_spec.rb
Expand Up @@ -65,4 +65,16 @@ def initialize
@should.not.object_id.should.eql(@should.object_id)
@should.instance_variable_get('@negated').should.eql(true)
end

it "equality is successful when objects are equal" do
lambda do
@should.eq(@subject)
end.should.not.raise
end

it "equality fails when objects are not equal" do
lambda do
@should.eq(12)
end.should.raise(Peck::Error)
end
end

0 comments on commit bb710bc

Please sign in to comment.