Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add eq matcher (for ==)

  • Loading branch information...
commit a23000ef6dbccfe6655265c3f30ac7b826f1943d 1 parent d372603
@dchelimsky dchelimsky authored
View
1  lib/rspec/matchers.rb
@@ -7,6 +7,7 @@
require 'rspec/matchers/be_instance_of'
require 'rspec/matchers/be_kind_of'
require 'rspec/matchers/change'
+require 'rspec/matchers/eq'
require 'rspec/matchers/eql'
require 'rspec/matchers/equal'
require 'rspec/matchers/errors'
View
47 lib/rspec/matchers/eq.rb
@@ -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
+
View
5 rspec-expectations.gemspec
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
s.authors = ["David Chelimsky", "Chad Humphries"]
- s.date = %q{2010-01-29}
+ s.date = %q{2010-01-31}
s.email = %q{dchelimsky@gmail.com;chad.humphries@gmail.com}
s.extra_rdoc_files = [
"README.markdown"
@@ -79,7 +79,6 @@ Gem::Specification.new do |s|
"spec/rspec/matchers/include_spec.rb",
"spec/rspec/matchers/match_array_spec.rb",
"spec/rspec/matchers/match_spec.rb",
- "spec/rspec/matchers/matcher_methods_spec.rb",
"spec/rspec/matchers/matcher_spec.rb",
"spec/rspec/matchers/matchers_spec.rb",
"spec/rspec/matchers/operator_matcher_spec.rb",
@@ -110,6 +109,7 @@ Gem::Specification.new do |s|
"spec/rspec/matchers/compatibility_spec.rb",
"spec/rspec/matchers/description_generation_spec.rb",
"spec/rspec/matchers/dsl_spec.rb",
+ "spec/rspec/matchers/eq_spec.rb",
"spec/rspec/matchers/eql_spec.rb",
"spec/rspec/matchers/equal_spec.rb",
"spec/rspec/matchers/exist_spec.rb",
@@ -118,7 +118,6 @@ Gem::Specification.new do |s|
"spec/rspec/matchers/include_spec.rb",
"spec/rspec/matchers/match_array_spec.rb",
"spec/rspec/matchers/match_spec.rb",
- "spec/rspec/matchers/matcher_methods_spec.rb",
"spec/rspec/matchers/matcher_spec.rb",
"spec/rspec/matchers/matchers_spec.rb",
"spec/rspec/matchers/operator_matcher_spec.rb",
View
34 spec/rspec/matchers/eq_spec.rb
@@ -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
+
Please sign in to comment.
Something went wrong with that request. Please try again.