forked from rspec/rspec-expectations
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d372603
commit a23000e
Showing
4 changed files
with
84 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
module Rspec | ||
module Matchers | ||
# :call-seq: | ||
# should eq(expected) | ||
# should_not eq(expected) | ||
# | ||
# Passes if actual == expected. | ||
# | ||
# See http://www.ruby-doc.org/core/classes/Object.html#M001057 for more information about equality in Ruby. | ||
# | ||
# == Examples | ||
# | ||
# 5.should eq(5) | ||
# 5.should_not eq(3) | ||
def eq(expected) | ||
Matcher.new :eq, expected do |_expected_| | ||
match do |actual| | ||
actual == _expected_ | ||
end | ||
|
||
failure_message_for_should do |actual| | ||
<<-MESSAGE | ||
expected #{_expected_.inspect} | ||
got #{actual.inspect} | ||
(compared using ==) | ||
MESSAGE | ||
end | ||
|
||
failure_message_for_should_not do |actual| | ||
<<-MESSAGE | ||
expected #{actual.inspect} not to equal #{_expected_.inspect} | ||
(compared using ==) | ||
MESSAGE | ||
end | ||
|
||
description do | ||
"== #{_expected_}" | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require 'spec_helper' | ||
|
||
module Rspec | ||
module Matchers | ||
describe "eq" do | ||
it "matches when actual == expected" do | ||
1.should eq(1) | ||
end | ||
|
||
it "does not match when actual != expected" do | ||
1.should_not eq(2) | ||
end | ||
|
||
it "describes itself" do | ||
matcher = eq(1) | ||
matcher.matches?(1) | ||
matcher.description.should == "== 1" | ||
end | ||
|
||
it "provides message, expected and actual on #failure_message" do | ||
matcher = eq("1") | ||
matcher.matches?(1) | ||
matcher.failure_message_for_should.should == "\nexpected \"1\"\n got 1\n\n(compared using ==)\n" | ||
end | ||
|
||
it "provides message, expected and actual on #negative_failure_message" do | ||
matcher = eq(1) | ||
matcher.matches?(1) | ||
matcher.failure_message_for_should_not.should == "\nexpected 1 not to equal 1\n\n(compared using ==)\n" | ||
end | ||
end | ||
end | ||
end | ||
|