Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: rspec/rspec-expectations
...
head fork: rspec/rspec-expectations
  • 20 commits
  • 20 files changed
  • 1 commit comment
  • 3 contributors
Commits on Aug 31, 2010
@justinko justinko equality.feature
- Closes #15.
7b52164
@dchelimsky dchelimsky beef up equality matchers feature 7cdb347
Commits on Sep 04, 2010
@dchelimsky dchelimsky delegate be(val) to equal(val) deb38c9
@dchelimsky dchelimsky un-pend pending example
- was failing on ruby-1.9.2-preview, but passes now on ruby-1.9.2 final
8f740ac
@myronmarston myronmarston Remove dependency on jeweler.
- Allows us to have an always-up-to-date gemspec.
- Use bundler's build/install/release rake tasks rather than jeweler's.
- One less development dependency.
- No need for a separate VERSION file.
15060b8
@dchelimsky dchelimsky add ruby-debug to Gemfile 04eeba1
@dchelimsky dchelimsky Make eq and eql matchers diffable and clean up when to/not diff e7303e9
@dchelimsky dchelimsky Diff when comparing a multiline string to a regexp
- Closes #8.
76434fa
Commits on Sep 08, 2010
@dchelimsky dchelimsky remove ruby-debug from Gemfile for 1.9.1 b43f107
@dchelimsky dchelimsky remove unnecessary requirement from feature
- output of paths changed subtly and caused this feature to fail
  unnecessarily. No need to bind this feature to that part of the
  output.
ed7e32a
Commits on Sep 09, 2010
@dchelimsky dchelimsky should[_not] change now handles boolean values correctly
- Closes #16.
ecd24f5
@dchelimsky dchelimsky clean up the change matcher c249173
Commits on Sep 11, 2010
@dchelimsky dchelimsky add beginnings of History f859a68
@dchelimsky dchelimsky history 6c31cbf
@dchelimsky dchelimsky fix changelog link in History f5aac62
Commits on Sep 12, 2010
@dchelimsky dchelimsky prep for beta.21 c4e6875
@dchelimsky dchelimsky bump version to 2.0.0.beta.21 76b9667
@dchelimsky dchelimsky stop using the old shared example API d13d9b7
Commits on Sep 13, 2010
@dchelimsky dchelimsky adjust history for beta.22 release 51f64b1
@dchelimsky dchelimsky bump version to 2.0.0.beta.22 311ba91
View
8 Gemfile
@@ -1,7 +1,6 @@
source "http://rubygems.org"
gem "rake"
-gem "jeweler"
gem "cucumber"
gem "aruba", ">= 0.2.0"
gem "autotest"
@@ -10,3 +9,10 @@ gem "rspec-expectations", :path => "."
gem "rspec-core", :path => "../rspec-core"
gem "rspec-mocks", :path => "../rspec-mocks"
gem "watchr"
+
+case RUBY_VERSION
+when '1.9.2'
+ gem 'ruby-debug19'
+when /^1\.8/
+ gem 'ruby-debug'
+end
View
16 History.md
@@ -0,0 +1,16 @@
+## rspec-expectations release history (incomplete)
+
+### 2.0.0.beta.22 / 2010-09-12
+
+[full changelog](http://github.com/rspec/rspec-expectations/compare/v2.0.0.beta.20...v2.0.0.beta.22)
+
+* Enhancements
+ * diffing improvements
+ * diff multiline strings
+ * don't diff single line strings
+ * don't diff numbers (silly)
+ * diff regexp + multiline string
+
+* Bug fixes
+ * should[_not] change now handles boolean values correctly
+
View
43 Rakefile
@@ -1,41 +1,12 @@
require 'bundler'
Bundler.setup
+Bundler::GemHelper.install_tasks
-$LOAD_PATH << File.expand_path("../lib", __FILE__)
require 'rake'
require 'rake/rdoctask'
-require 'rspec/expectations/version'
require 'rspec/core/rake_task'
require 'cucumber/rake/task'
-begin
- require 'jeweler'
- Jeweler::Tasks.new do |gem|
- gem.name = "rspec-expectations"
- gem.version = RSpec::Expectations::Version::STRING
- gem.summary = "rspec-expectations-#{RSpec::Expectations::Version::STRING}"
- gem.description = "rspec expectations (should[_not] and matchers)"
- gem.rubyforge_project = "rspec"
- gem.email = "dchelimsky@gmail.com;chad.humphries@gmail.com"
- gem.homepage = "http://github.com/rspec/expectations"
- gem.authors = ["David Chelimsky", "Chad Humphries"]
- gem.add_dependency('diff-lcs', ">= 1.1.2")
- gem.add_development_dependency('cucumber', ">= 0.6.2")
- gem.add_development_dependency('aruba', ">= 0.1.1")
- gem.add_development_dependency('rspec-core', ">= #{RSpec::Expectations::Version::STRING}")
- gem.add_development_dependency('rspec-mocks', ">= #{RSpec::Expectations::Version::STRING}")
- end
-rescue LoadError
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
-end
-
-namespace :gem do
- desc "push to gemcutter"
- task :push => :build do
- system "gem push pkg/rspec-expectations-#{RSpec::Expectations::Version::STRING}.gem"
- end
-end
-
RSpec::Core::RakeTask.new(:spec)
class Cucumber::Rake::Task::ForkedCucumberRunner
@@ -50,18 +21,11 @@ Cucumber::Rake::Task.new do |t|
t.cucumber_opts = %w{--format progress}
end
-task :default => [:check_dependencies, :spec, :cucumber]
+task :default => [:spec, :cucumber]
Rake::RDocTask.new do |rdoc|
- if File.exist?('VERSION.yml')
- config = YAML.load(File.read('VERSION.yml'))
- version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
- else
- version = ""
- end
-
rdoc.rdoc_dir = 'rdoc'
- rdoc.title = "rspec-expectations #{version}"
+ rdoc.title = "rspec-expectations #{RSpec::Expectations::Version::STRING}"
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
end
@@ -73,4 +37,3 @@ task :clobber do
rm_rf 'coverage'
end
-
View
1  VERSION
@@ -1 +0,0 @@
-2.0.0.beta.20
View
85 features/expectations/diffing.feature
@@ -0,0 +1,85 @@
+Feature: diffing
+
+ When appropriate, failure messages will automatically include a diff.
+
+ Scenario: diff for a multiline string
+ Given a file named "example_spec.rb" with:
+ """
+ describe "a multiline string" do
+ it "is like another string" do
+ expected = <<-EXPECTED
+ this is the
+ expected
+ string
+ EXPECTED
+ actual = <<-ACTUAL
+ this is the
+ actual
+ string
+ ACTUAL
+ actual.should eq(expected)
+ end
+ end
+ """
+ When I run "rspec example_spec.rb"
+ Then the output should contain:
+ """
+ Diff:
+ @@ -1,4 +1,4 @@
+ this is the
+ - expected
+ + actual
+ string
+ """
+
+ Scenario: diff for a multiline string and a regexp
+ Given a file named "example_spec.rb" with:
+ """
+ describe "a multiline string" do
+ it "is like another string" do
+ expected = /expected/m
+ actual = <<-ACTUAL
+ this is the
+ actual
+ string
+ ACTUAL
+ actual.should =~ expected
+ end
+ end
+ """
+ When I run "rspec example_spec.rb"
+ Then the output should contain:
+ """
+ Diff:
+ @@ -1,2 +1,4 @@
+ -/expected/m
+ +this is the
+ + actual
+ + string
+ """
+
+ Scenario: no diff for a single line strings
+ Given a file named "example_spec.rb" with:
+ """
+ describe "a single line string" do
+ it "is like another string" do
+ expected = "this string"
+ actual = "that string"
+ actual.should eq(expected)
+ end
+ end
+ """
+ When I run "rspec example_spec.rb"
+ Then the output should not contain "Diff:"
+
+ Scenario: no diff for numbers
+ Given a file named "example_spec.rb" with:
+ """
+ describe "a number" do
+ it "is like another number" do
+ 1.should eq(2)
+ end
+ end
+ """
+ When I run "rspec example_spec.rb"
+ Then the output should not contain "Diff:"
View
142 features/matchers/equality.feature
@@ -0,0 +1,142 @@
+Feature: equality matchers
+
+ Ruby exposes several different methods for handling equality:
+
+ a.equal?(b) # object identity - a and b refer to the same object
+ a.eql?(b) # object equivalence - a and b have the same value
+ a == b # object equivalence - a and b have the same value with type conversions
+
+ Note that these descriptions are guidelines but are not forced by the
+ language. Any object can implement any of these methods with its own
+ semantics.
+
+ rspec-expectations ships with matchers that align with each of these methods:
+
+ a.should equal(b) # passes if a.equal?(b)
+ a.should eql(b) # passes if a.eql?(b)
+ a.should == b # passes if a == b
+
+ It also ships with two matchers that have more of a DSL feel to them:
+
+ a.should be(b) # passes if a.equal?(b)
+ a.should eq(b) # passes if a == b
+
+ Scenario: compare using eq (==)
+ Given a file named "compare_using_eq.rb" with:
+ """
+ require 'spec_helper'
+
+ describe "a string" do
+ it "is equal to another string of the same value" do
+ "this string".should eq("this string")
+ end
+
+ it "is not equal to another string of a different value" do
+ "this string".should_not eq("a different string")
+ end
+ end
+
+ describe "an integer" do
+ it "is equal to a float of the same value" do
+ 5.should eq(5.0)
+ end
+ end
+ """
+ When I run "rspec compare_using_eq.rb"
+ Then the output should contain "3 examples, 0 failures"
+
+ Scenario: compare using ==
+ Given a file named "compare_using_==.rb" with:
+ """
+ require 'spec_helper'
+
+ describe "a string" do
+ it "is equal to another string of the same value" do
+ "this string".should == "this string"
+ end
+
+ it "is not equal to another string of a different value" do
+ "this string".should_not == "a different string"
+ end
+ end
+
+ describe "an integer" do
+ it "is equal to a float of the same value" do
+ 5.should == 5.0
+ end
+ end
+ """
+ When I run "rspec compare_using_==.rb"
+ Then the output should contain "3 examples, 0 failures"
+
+ Scenario: compare using eql (eql?)
+ Given a file named "compare_using_eql.rb" with:
+ """
+ require 'spec_helper'
+
+ describe "an integer" do
+ it "is equal to another integer of the same value" do
+ 5.should eql(5)
+ end
+
+ it "is not equal to another integer of a different value" do
+ 5.should_not eql(6)
+ end
+
+ it "is not equal to a float of the same value" do
+ 5.should_not eql(5.0)
+ end
+
+ end
+ """
+ When I run "rspec compare_using_eql.rb"
+ Then the output should contain "3 examples, 0 failures"
+
+ Scenario: compare using equal (equal?)
+ Given a file named "compare_using_equal.rb" with:
+ """
+ require 'spec_helper'
+
+ describe "a string" do
+ it "is equal to itself" do
+ string = "this string"
+ string.should equal(string)
+ end
+
+ it "is not equal to another string of the same value" do
+ "this string".should_not equal("this string")
+ end
+
+ it "is not equal to another string of a different value" do
+ "this string".should_not equal("a different string")
+ end
+
+ end
+ """
+ When I run "rspec compare_using_equal.rb"
+ Then the output should contain "3 examples, 0 failures"
+
+ Scenario: compare using be (equal?)
+ Given a file named "compare_using_be.rb" with:
+ """
+ require 'spec_helper'
+
+ describe "a string" do
+ it "is equal to itself" do
+ string = "this string"
+ string.should be(string)
+ end
+
+ it "is not equal to another string of the same value" do
+ "this string".should_not be("this string")
+ end
+
+ it "is not equal to another string of a different value" do
+ "this string".should_not be("a different string")
+ end
+
+ end
+ """
+ When I run "rspec compare_using_be.rb"
+ Then the output should contain "3 examples, 0 failures"
+
View
6 lib/rspec/expectations/differ.rb
@@ -41,8 +41,10 @@ def diff_as_string(data_new, data_old)
output << oldhunk.diff(format) << "\n"
end
- def diff_as_object(target,expected)
- diff_as_string(PP.pp(target,""), PP.pp(expected,""))
+ def diff_as_object(actual,expected)
+ actual = String === actual ? actual : PP.pp(actual,"")
+ expected = String === expected ? expected : PP.pp(expected,"")
+ diff_as_string(actual, expected)
end
protected
View
6 lib/rspec/expectations/fail_with.rb
@@ -21,7 +21,7 @@ def fail_with(message, expected=nil, actual=nil) # :nodoc:
if any_multiline_strings?(actual, expected)
message << "\nDiff:" << self.differ.diff_as_string(actual, expected)
end
- elsif no_procs?(actual, expected)
+ elsif no_procs?(actual, expected) && no_numbers?(actual, expected)
message << "\nDiff:" << self.differ.diff_as_object(actual, expected)
end
end
@@ -42,6 +42,10 @@ def all_strings?(*args)
def any_multiline_strings?(*args)
all_strings?(*args) && args.any? {|a| a =~ /\n/}
end
+
+ def no_numbers?(*args)
+ args.none? {|a| Numeric === a}
+ end
end
end
end
View
2  lib/rspec/expectations/version.rb
@@ -1,7 +1,7 @@
module RSpec # :nodoc:
module Expectations # :nodoc:
module Version # :nodoc:
- STRING = File.readlines(File.expand_path('../../../../VERSION', __FILE__)).first
+ STRING = '2.0.0.beta.22'
end
end
end
View
29 lib/rspec/matchers/be.rb
@@ -177,32 +177,6 @@ def prefix_to_sentence
end
- class BeSameAs < Be
-
- def initialize(*args, &block)
- @expected = args.shift
- @args = args
- end
-
- def matches?(actual)
- @actual = actual
- @actual.equal?(@expected)
- end
-
- def failure_message_for_should
- "expected #{@expected}, got #{@actual.inspect}"
- end
-
- def failure_message_for_should_not
- "expected not #{@expected}, got #{@actual.inspect}"
- end
-
- def description
- "be #{expected_to_sentence}#{args_to_sentence}"
- end
-
- end
-
# :call-seq:
# should be_true
# should be_false
@@ -235,8 +209,7 @@ def description
# target.should_not be_old_enough(16) #passes unless target.old_enough?(16)
def be(*args)
args.empty? ?
- Matchers::Be.new :
- Matchers::BeSameAs.new(*args)
+ Matchers::Be.new : equal(*args)
end
# passes if target.kind_of?(klass)
View
65 lib/rspec/matchers/change.rb
@@ -4,9 +4,10 @@ module Matchers
#Based on patch from Wilson Bilkovich
class Change #:nodoc:
def initialize(receiver=nil, message=nil, &block)
- @message = message || "result"
+ @message = message
@value_proc = block || lambda {receiver.__send__(message)}
@to = @from = @minimum = @maximum = @amount = nil
+ @given_from = @given_to = false
end
def matches?(event_proc)
@@ -16,14 +17,9 @@ def matches?(event_proc)
event_proc.call
@after = evaluate_value_proc
- return (@to = false) if @from unless @from == @before
- return false if @to unless @to == @after
- return (@before + @amount == @after) if @amount
- return ((@after - @before) >= @minimum) if @minimum
- return ((@after - @before) <= @maximum) if @maximum
- return @before != @after
+ changed? && matches_before? && matches_after? && matches_amount? && matches_min? && matches_max?
end
-
+
def raise_block_syntax_error
raise MatcherError.new(<<-MESSAGE
block passed to should or should_not change must use {} instead of do/end
@@ -36,18 +32,18 @@ def evaluate_value_proc
end
def failure_message_for_should
- if @to
- "#{@message} should have been changed to #{@to.inspect}, but is now #{@after.inspect}"
- elsif @from
- "#{@message} should have initially been #{@from.inspect}, but was #{@before.inspect}"
+ if @given_from && @before != @from
+ "#{message} should have initially been #{@from.inspect}, but was #{@before.inspect}"
+ elsif @given_to && @to != @after
+ "#{message} should have been changed to #{@to.inspect}, but is now #{@after.inspect}"
elsif @amount
- "#{@message} should have been changed by #{@amount.inspect}, but was changed by #{actual_delta.inspect}"
+ "#{message} should have been changed by #{@amount.inspect}, but was changed by #{actual_delta.inspect}"
elsif @minimum
- "#{@message} should have been changed by at least #{@minimum.inspect}, but was changed by #{actual_delta.inspect}"
+ "#{message} should have been changed by at least #{@minimum.inspect}, but was changed by #{actual_delta.inspect}"
elsif @maximum
- "#{@message} should have been changed by at most #{@maximum.inspect}, but was changed by #{actual_delta.inspect}"
+ "#{message} should have been changed by at most #{@maximum.inspect}, but was changed by #{actual_delta.inspect}"
else
- "#{@message} should have changed, but is still #{@before.inspect}"
+ "#{message} should have changed, but is still #{@before.inspect}"
end
end
@@ -56,7 +52,7 @@ def actual_delta
end
def failure_message_for_should_not
- "#{@message} should not have changed, but did change from #{@before.inspect} to #{@after.inspect}"
+ "#{message} should not have changed, but did change from #{@before.inspect} to #{@after.inspect}"
end
def by(amount)
@@ -75,18 +71,51 @@ def by_at_most(maximum)
end
def to(to)
+ @given_to = true
@to = to
self
end
def from (from)
+ @given_from = true
@from = from
self
end
def description
- "change ##{@message}"
+ "change ##{message}"
+ end
+
+ private
+
+ def message
+ @message || "result"
+ end
+
+ def changed?
+ @before != @after
+ end
+
+ def matches_before?
+ @given_from ? @from == @before : true
end
+
+ def matches_after?
+ @given_to ? @to == @after : true
+ end
+
+ def matches_amount?
+ @amount ? (@before + @amount == @after) : true
+ end
+
+ def matches_min?
+ @minimum ? (@after - @before >= @minimum) : true
+ end
+
+ def matches_max?
+ @maximum ? (@after - @before <= @maximum) : true
+ end
+
end
# :call-seq:
View
3  lib/rspec/matchers/eq.rb
@@ -14,6 +14,9 @@ module Matchers
# 5.should_not eq(3)
def eq(expected)
Matcher.new :eq, expected do |_expected_|
+
+ diffable
+
match do |actual|
actual == _expected_
end
View
3  lib/rspec/matchers/eql.rb
@@ -14,6 +14,9 @@ module Matchers
# 5.should_not eql(3)
def eql(expected)
Matcher.new :eql, expected do |_expected_|
+
+ diffable
+
match do |actual|
actual.eql?(_expected_)
end
View
194 rspec-expectations.gemspec
@@ -1,179 +1,31 @@
-# Generated by jeweler
-# DO NOT EDIT THIS FILE DIRECTLY
-# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
# -*- encoding: utf-8 -*-
+$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
+require "rspec/expectations/version"
Gem::Specification.new do |s|
- s.name = %q{rspec-expectations}
- s.version = "2.0.0.beta.20"
+ s.name = "rspec-expectations"
+ s.version = RSpec::Expectations::Version::STRING
+ s.platform = Gem::Platform::RUBY
+ s.authors = ["David Chelimsky", "Chad Humphries"]
+ s.email = "dchelimsky@gmail.com;chad.humphries@gmail.com"
+ s.homepage = "http://github.com/rspec/rspec-expectations"
+ s.summary = "rspec-expectations-#{RSpec::Expectations::Version::STRING}"
+ s.description = "rspec expectations (should[_not] and matchers)"
- 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-08-24}
- s.description = %q{rspec expectations (should[_not] and matchers)}
- s.email = %q{dchelimsky@gmail.com;chad.humphries@gmail.com}
- s.extra_rdoc_files = [
- "README.markdown"
- ]
- s.files = [
- ".document",
- ".gitignore",
- "Gemfile",
- "License.txt",
- "README.markdown",
- "Rakefile",
- "Upgrade.markdown",
- "VERSION",
- "cucumber.yml",
- "features/README.markdown",
- "features/expectations/attribute_of_subject.feature",
- "features/expectations/customized_message.feature",
- "features/expectations/implicit_docstrings.feature",
- "features/matchers/access_running_example.feature",
- "features/matchers/define_diffable_matcher.feature",
- "features/matchers/define_matcher.feature",
- "features/matchers/define_matcher_outside_rspec.feature",
- "features/matchers/define_matcher_with_fluent_interface.feature",
- "features/matchers/expect_change.feature",
- "features/matchers/expect_error.feature",
- "features/support/env.rb",
- "lib/rspec-expectations.rb",
- "lib/rspec/expectations.rb",
- "lib/rspec/expectations/backward_compatibility.rb",
- "lib/rspec/expectations/differ.rb",
- "lib/rspec/expectations/errors.rb",
- "lib/rspec/expectations/extensions.rb",
- "lib/rspec/expectations/extensions/array.rb",
- "lib/rspec/expectations/extensions/kernel.rb",
- "lib/rspec/expectations/extensions/rspec/core/example_group.rb",
- "lib/rspec/expectations/fail_with.rb",
- "lib/rspec/expectations/handler.rb",
- "lib/rspec/expectations/version.rb",
- "lib/rspec/matchers.rb",
- "lib/rspec/matchers/be.rb",
- "lib/rspec/matchers/be_close.rb",
- "lib/rspec/matchers/be_instance_of.rb",
- "lib/rspec/matchers/be_kind_of.rb",
- "lib/rspec/matchers/change.rb",
- "lib/rspec/matchers/compatibility.rb",
- "lib/rspec/matchers/dsl.rb",
- "lib/rspec/matchers/eq.rb",
- "lib/rspec/matchers/eql.rb",
- "lib/rspec/matchers/equal.rb",
- "lib/rspec/matchers/errors.rb",
- "lib/rspec/matchers/exist.rb",
- "lib/rspec/matchers/extensions/instance_exec.rb",
- "lib/rspec/matchers/generated_descriptions.rb",
- "lib/rspec/matchers/has.rb",
- "lib/rspec/matchers/have.rb",
- "lib/rspec/matchers/include.rb",
- "lib/rspec/matchers/match.rb",
- "lib/rspec/matchers/match_array.rb",
- "lib/rspec/matchers/matcher.rb",
- "lib/rspec/matchers/method_missing.rb",
- "lib/rspec/matchers/operator_matcher.rb",
- "lib/rspec/matchers/pretty.rb",
- "lib/rspec/matchers/raise_error.rb",
- "lib/rspec/matchers/respond_to.rb",
- "lib/rspec/matchers/satisfy.rb",
- "lib/rspec/matchers/throw_symbol.rb",
- "rspec-expectations.gemspec",
- "spec/rspec/expectations/differ_spec.rb",
- "spec/rspec/expectations/extensions/kernel_spec.rb",
- "spec/rspec/expectations/fail_with_spec.rb",
- "spec/rspec/expectations/handler_spec.rb",
- "spec/rspec/matchers/be_close_spec.rb",
- "spec/rspec/matchers/be_instance_of_spec.rb",
- "spec/rspec/matchers/be_kind_of_spec.rb",
- "spec/rspec/matchers/be_spec.rb",
- "spec/rspec/matchers/change_spec.rb",
- "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",
- "spec/rspec/matchers/has_spec.rb",
- "spec/rspec/matchers/have_spec.rb",
- "spec/rspec/matchers/include_spec.rb",
- "spec/rspec/matchers/match_array_spec.rb",
- "spec/rspec/matchers/match_spec.rb",
- "spec/rspec/matchers/matcher_spec.rb",
- "spec/rspec/matchers/matchers_spec.rb",
- "spec/rspec/matchers/operator_matcher_spec.rb",
- "spec/rspec/matchers/raise_error_spec.rb",
- "spec/rspec/matchers/respond_to_spec.rb",
- "spec/rspec/matchers/satisfy_spec.rb",
- "spec/rspec/matchers/throw_symbol_spec.rb",
- "spec/spec_helper.rb",
- "spec/suite.rb",
- "spec/support/classes.rb",
- "specs.watchr"
- ]
- s.homepage = %q{http://github.com/rspec/expectations}
- s.rdoc_options = ["--charset=UTF-8"]
- s.require_paths = ["lib"]
- s.rubyforge_project = %q{rspec}
- s.rubygems_version = %q{1.3.7}
- s.summary = %q{rspec-expectations-2.0.0.beta.20}
- s.test_files = [
- "spec/rspec/expectations/differ_spec.rb",
- "spec/rspec/expectations/extensions/kernel_spec.rb",
- "spec/rspec/expectations/fail_with_spec.rb",
- "spec/rspec/expectations/handler_spec.rb",
- "spec/rspec/matchers/be_close_spec.rb",
- "spec/rspec/matchers/be_instance_of_spec.rb",
- "spec/rspec/matchers/be_kind_of_spec.rb",
- "spec/rspec/matchers/be_spec.rb",
- "spec/rspec/matchers/change_spec.rb",
- "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",
- "spec/rspec/matchers/has_spec.rb",
- "spec/rspec/matchers/have_spec.rb",
- "spec/rspec/matchers/include_spec.rb",
- "spec/rspec/matchers/match_array_spec.rb",
- "spec/rspec/matchers/match_spec.rb",
- "spec/rspec/matchers/matcher_spec.rb",
- "spec/rspec/matchers/matchers_spec.rb",
- "spec/rspec/matchers/operator_matcher_spec.rb",
- "spec/rspec/matchers/raise_error_spec.rb",
- "spec/rspec/matchers/respond_to_spec.rb",
- "spec/rspec/matchers/satisfy_spec.rb",
- "spec/rspec/matchers/throw_symbol_spec.rb",
- "spec/spec_helper.rb",
- "spec/suite.rb",
- "spec/support/classes.rb"
- ]
+ s.rubygems_version = "1.3.7"
+ s.rubyforge_project = "rspec"
- if s.respond_to? :specification_version then
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
- s.specification_version = 3
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.extra_rdoc_files = [ "README.markdown" ]
+ s.rdoc_options = ["--charset=UTF-8"]
+ s.require_path = "lib"
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
- s.add_runtime_dependency(%q<diff-lcs>, [">= 1.1.2"])
- s.add_development_dependency(%q<cucumber>, [">= 0.6.2"])
- s.add_development_dependency(%q<aruba>, [">= 0.1.1"])
- s.add_development_dependency(%q<rspec-core>, [">= 2.0.0.beta.20"])
- s.add_development_dependency(%q<rspec-mocks>, [">= 2.0.0.beta.20"])
- else
- s.add_dependency(%q<diff-lcs>, [">= 1.1.2"])
- s.add_dependency(%q<cucumber>, [">= 0.6.2"])
- s.add_dependency(%q<aruba>, [">= 0.1.1"])
- s.add_dependency(%q<rspec-core>, [">= 2.0.0.beta.20"])
- s.add_dependency(%q<rspec-mocks>, [">= 2.0.0.beta.20"])
- end
- else
- s.add_dependency(%q<diff-lcs>, [">= 1.1.2"])
- s.add_dependency(%q<cucumber>, [">= 0.6.2"])
- s.add_dependency(%q<aruba>, [">= 0.1.1"])
- s.add_dependency(%q<rspec-core>, [">= 2.0.0.beta.20"])
- s.add_dependency(%q<rspec-mocks>, [">= 2.0.0.beta.20"])
- end
+ s.add_runtime_dependency 'diff-lcs', '>= 1.1.2'
+ s.add_development_dependency 'cucumber', ">= 0.6.2"
+ s.add_development_dependency 'aruba', ">= 0.1.1"
+ s.add_development_dependency 'rspec-core', ">= #{RSpec::Expectations::Version::STRING}"
+ s.add_development_dependency 'rspec-mocks', ">= #{RSpec::Expectations::Version::STRING}"
end
View
65 spec/rspec/expectations/fail_with_spec.rb
@@ -6,35 +6,62 @@
before(:each) do
RSpec::Expectations.stub(:differ) { differ }
end
-
+
+ it "calls differ if expected/actual are not strings (or numbers or procs)" do
+ differ.should_receive(:diff_as_object).and_return("diff")
+ lambda {
+ RSpec::Expectations.fail_with "the message", Object.new, Object.new
+ }.should fail_with("the message\nDiff:diff")
+ end
+
+ context "with two strings" do
+ context "and actual is multiline" do
+ it "calls differ" do
+ differ.should_receive(:diff_as_string).and_return("diff")
+ lambda {
+ RSpec::Expectations.fail_with "the message", "expected\nthis", "actual"
+ }.should fail_with("the message\nDiff:diff")
+ end
+ end
+
+ context "and expected is multiline" do
+ it "calls differ" do
+ differ.should_receive(:diff_as_string).and_return("diff")
+ lambda {
+ RSpec::Expectations.fail_with "the message", "expected", "actual\nthat"
+ }.should fail_with("the message\nDiff:diff")
+ end
+ end
+
+ context "and both are single line strings" do
+ it "does not call differ" do
+ differ.should_not_receive(:diff_as_string)
+ lambda {
+ RSpec::Expectations.fail_with("the message", "expected", "actual")
+ }.should fail_with("the message")
+ end
+ end
+ end
+
it "does not call differ if no expected/actual" do
lambda {
RSpec::Expectations.fail_with "the message"
}.should fail_with("the message")
end
-
- it "calls differ if expected/actual are presented separately" do
- differ.should_receive(:diff_as_string).and_return("diff")
+
+ it "does not call differ expected is Numeric" do
lambda {
- RSpec::Expectations.fail_with "the message", "expected\nthis", "actual"
- }.should fail_with("the message\nDiff:diff")
- end
-
- it "does not call differ if expected/actual are single line strings" do
- differ.should_not_receive(:diff_as_string)
- RSpec::Expectations.fail_with("the message", "expected", "actual") rescue nil
+ RSpec::Expectations.fail_with "the message", 1, "1"
+ }.should fail_with("the message")
end
-
- it "calls differ if expected/actual are not strings" do
- differ.should_receive(:diff_as_object).and_return("diff")
+
+ it "does not call differ when actual is Numeric" do
lambda {
- RSpec::Expectations.fail_with "the message", Object.new, Object.new
- }.should fail_with("the message\nDiff:diff")
+ RSpec::Expectations.fail_with "the message", "1", 1
+ }.should fail_with("the message")
end
-
+
it "does not call differ if expected or actual are procs" do
- differ.should_not_receive(:diff_as_string)
- differ.should_not_receive(:diff_as_object)
lambda {
RSpec::Expectations.fail_with "the message", lambda {}, lambda {}
}.should fail_with("the message")
View
20 spec/rspec/matchers/be_spec.rb
@@ -386,25 +386,16 @@
end
describe "should be(value)" do
- it "passes if actual.equal?(value)" do
+ it "delegates to equal" do
+ self.should_receive(:equal).with(5)
5.should be(5)
end
-
- it "fails if !actual.equal?(value)" do
- lambda { 5.should be(6) }.should fail_with("expected 6, got 5")
- end
-
- it "describes itself" do
- be(5).description.should == "be 5"
- end
end
describe "should_not be(value)" do
- it "passes if !actual.equal?(value)" do
- 5.should_not be(6)
- end
- it "fails if !actual.equal?(value)" do
- lambda { 5.should_not be(5) }.should fail_with("expected not 5, got 5")
+ it "delegates to equal" do
+ self.should_receive(:equal).with(4)
+ 5.should_not be(4)
end
end
@@ -420,7 +411,6 @@
describe "arbitrary predicate with DelegateClass" do
it "accesses methods defined in the delegating class (LH[#48])" do
- pending("this fails in 1.9.2-preview3") unless RUBY_VERSION.to_s =~ /^1.8/
require 'delegate'
class ArrayDelegate < DelegateClass(Array)
def initialize(array)
View
136 spec/rspec/matchers/change_spec.rb
@@ -1,28 +1,48 @@
#Based on patch from Wilson Bilkovich
require 'spec_helper'
+
class SomethingExpected
attr_accessor :some_value
end
describe "should change(actual, message)" do
- before(:each) do
- @instance = SomethingExpected.new
- @instance.some_value = 5
+ context "with a numeric value" do
+ before(:each) do
+ @instance = SomethingExpected.new
+ @instance.some_value = 5
+ end
+
+ it "passes when actual is modified by the block" do
+ expect {@instance.some_value = 6}.to change(@instance, :some_value)
+ end
+
+ it "fails when actual is not modified by the block" do
+ expect do
+ expect {}.to change(@instance, :some_value)
+ end.to fail_with("some_value should have changed, but is still 5")
+ end
+
+ it "provides a #description" do
+ change(@instance, :some_value).description.should == "change #some_value"
+ end
end
- it "passes when actual is modified by the block" do
- expect {@instance.some_value = 6}.to change(@instance, :some_value)
- end
+ context "with boolean values" do
+ before(:each) do
+ @instance = SomethingExpected.new
+ @instance.some_value = true
+ end
- it "fails when actual is not modified by the block" do
- expect do
- expect {}.to change(@instance, :some_value)
- end.to fail_with("some_value should have changed, but is still 5")
- end
-
- it "provides a #description" do
- change(@instance, :some_value).description.should == "change #some_value"
+ it "passes when actual is modified by the block" do
+ expect {@instance.some_value = false}.to change(@instance, :some_value)
+ end
+
+ it "fails when actual is not modified by the block" do
+ expect do
+ expect {}.to change(@instance, :some_value)
+ end.to fail_with("some_value should have changed, but is still true")
+ end
end
end
@@ -227,19 +247,37 @@ class SomethingExpected
end
describe "should change(actual, message).from(old)" do
- before(:each) do
- @instance = SomethingExpected.new
- @instance.some_value = 'string'
- end
-
- it "passes when attribute is == to expected value before executing block" do
- expect { @instance.some_value = "astring" }.to change(@instance, :some_value).from("string")
- end
-
- it "fails when attribute is not == to expected value before executing block" do
- expect do
- expect { @instance.some_value = "knot" }.to change(@instance, :some_value).from("cat")
- end.to fail_with("some_value should have initially been \"cat\", but was \"string\"")
+ context "with boolean values" do
+ before(:each) do
+ @instance = SomethingExpected.new
+ @instance.some_value = true
+ end
+
+ it "passes when attribute is == to expected value before executing block" do
+ expect { @instance.some_value = false }.to change(@instance, :some_value).from(true)
+ end
+
+ it "fails when attribute is not == to expected value before executing block" do
+ expect do
+ expect { @instance.some_value = 'foo' }.to change(@instance, :some_value).from(false)
+ end.to fail_with("some_value should have initially been false, but was true")
+ end
+ end
+ context "with non-boolean values" do
+ before(:each) do
+ @instance = SomethingExpected.new
+ @instance.some_value = 'string'
+ end
+
+ it "passes when attribute is == to expected value before executing block" do
+ expect { @instance.some_value = "astring" }.to change(@instance, :some_value).from("string")
+ end
+
+ it "fails when attribute is not == to expected value before executing block" do
+ expect do
+ expect { @instance.some_value = "knot" }.to change(@instance, :some_value).from("cat")
+ end.to fail_with("some_value should have initially been \"cat\", but was \"string\"")
+ end
end
end
@@ -261,19 +299,37 @@ class SomethingExpected
end
describe "should change(actual, message).to(new)" do
- before(:each) do
- @instance = SomethingExpected.new
- @instance.some_value = 'string'
- end
-
- it "passes when attribute is == to expected value after executing block" do
- expect { @instance.some_value = "cat" }.to change(@instance, :some_value).to("cat")
- end
-
- it "fails when attribute is not == to expected value after executing block" do
- expect do
- expect { @instance.some_value = "cat" }.to change(@instance, :some_value).from("string").to("dog")
- end.to fail_with("some_value should have been changed to \"dog\", but is now \"cat\"")
+ context "with boolean values" do
+ before(:each) do
+ @instance = SomethingExpected.new
+ @instance.some_value = true
+ end
+
+ it "passes when attribute is == to expected value after executing block" do
+ expect { @instance.some_value = false }.to change(@instance, :some_value).to(false)
+ end
+
+ it "fails when attribute is not == to expected value after executing block" do
+ expect do
+ expect { @instance.some_value = 1 }.to change(@instance, :some_value).from(true).to(false)
+ end.to fail_with("some_value should have been changed to false, but is now 1")
+ end
+ end
+ context "with non-boolean values" do
+ before(:each) do
+ @instance = SomethingExpected.new
+ @instance.some_value = 'string'
+ end
+
+ it "passes when attribute is == to expected value after executing block" do
+ expect { @instance.some_value = "cat" }.to change(@instance, :some_value).to("cat")
+ end
+
+ it "fails when attribute is not == to expected value after executing block" do
+ expect do
+ expect { @instance.some_value = "cat" }.to change(@instance, :some_value).from("string").to("dog")
+ end.to fail_with("some_value should have been changed to \"dog\", but is now \"cat\"")
+ end
end
end
View
4 spec/rspec/matchers/eq_spec.rb
@@ -3,6 +3,10 @@
module RSpec
module Matchers
describe "eq" do
+ it "is diffable" do
+ eq(1).should be_diffable
+ end
+
it "matches when actual == expected" do
1.should eq(1)
end
View
4 spec/rspec/matchers/eql_spec.rb
@@ -3,6 +3,10 @@
module RSpec
module Matchers
describe "eql" do
+ it "is diffable" do
+ eql(1).should be_diffable
+ end
+
it "matches when actual.eql?(expected)" do
1.should eql(1)
end
View
33 spec/rspec/matchers/have_spec.rb
@@ -1,15 +1,8 @@
require 'spec_helper'
require 'stringio'
-share_as :HaveSpecHelper do
- def create_collection_owner_with(n)
- owner = RSpec::Expectations::Helper::CollectionOwner.new
- (1..n).each do |number|
- owner.add_to_collection_with_length_method(number)
- owner.add_to_collection_with_size_method(number)
- end
- owner
- end
+describe "have matcher" do
+
before(:each) do
if defined?(::ActiveSupport::Inflector)
@active_support_was_defined = true
@@ -24,10 +17,17 @@ def self.pluralize(string)
end
end
end
-end
+
+ def create_collection_owner_with(n)
+ owner = RSpec::Expectations::Helper::CollectionOwner.new
+ (1..n).each do |number|
+ owner.add_to_collection_with_length_method(number)
+ owner.add_to_collection_with_size_method(number)
+ end
+ owner
+ end
describe "should have(n).items" do
- include HaveSpecHelper
it "passes if target has a collection of items with n members" do
owner = create_collection_owner_with(3)
@@ -63,7 +63,6 @@ def self.pluralize(string)
end
describe 'should have(1).item when ActiveSupport::Inflector is defined' do
- include HaveSpecHelper
it 'pluralizes the collection name' do
owner = create_collection_owner_with(1)
@@ -78,7 +77,6 @@ def self.pluralize(string)
end
describe 'should have(1).item when Inflector is defined' do
- include HaveSpecHelper
before(:each) do
if defined?(Inflector)
@@ -119,7 +117,6 @@ def items
end
describe "should_not have(n).items" do
- include HaveSpecHelper
it "passes if target has a collection of items with < n members" do
owner = create_collection_owner_with(3)
@@ -145,7 +142,6 @@ def items
end
describe "should have_exactly(n).items" do
- include HaveSpecHelper
it "passes if target has a collection of items with n members" do
owner = create_collection_owner_with(3)
@@ -181,7 +177,6 @@ def items
end
describe "should have_at_least(n).items" do
- include HaveSpecHelper
it "passes if target has a collection of items with n members" do
owner = create_collection_owner_with(3)
@@ -235,8 +230,6 @@ def items
end
describe "should have_at_most(n).items" do
- include HaveSpecHelper
-
it "passes if target has a collection of items with n members" do
owner = create_collection_owner_with(3)
owner.should have_at_most(3).items_in_collection_with_length_method
@@ -330,8 +323,6 @@ def items
end
describe RSpec::Matchers::Have, "for a collection owner that implements #send" do
- include HaveSpecHelper
-
before(:each) do
@collection = Object.new
def @collection.floozles; [1,2] end
@@ -406,3 +397,5 @@ module Matchers
end
end
end
+
+end

Showing you all comments on commits in this comparison.

@justinko

Documentation doesn't get any better than this!

Something went wrong with that request. Please try again.