Skip to content
This repository
  • 19 commits
  • 12 files changed
  • 0 comments
  • 3 contributors
Mar 17, 2012
David Chelimsky dev: add a script to download ruby-debug-base19-0.11.26.gem and linec…
…ache19-0.5.13.gem to a local cache

[ci skip]
564487b
David Chelimsky Require kernel extensions (should) from block_aliases in case it is
loaded first.
e290fe3
David Chelimsky fix bug diffing single strings with multiline strings 07dd19c
David Chelimsky Revert "fix bug diffing single strings with multiline strings"
This reverts commit 07dd19c.
2c23be3
David Chelimsky better fix for bug when diffing multiline strings e4d8dcb
David Chelimsky formatting tweaks in the changelog 0492d87
Mar 22, 2012
Justin Ko Remove unnecessary "else" clause. 584e764
Justin Ko Provide a helpful message if the diff between two objects is empty. F…
…ixes #123
e12a2d9
Mar 24, 2012
David Chelimsky Changelog for #125 [ci skip] 0458ac1
Mar 29, 2012
Fix error with using custom matchers inside other custom matcher rspe… 77243d9
David Chelimsky Merge pull request #126 from mirasrael/master
Fix for error with using custom matchers inside other custom matchers
6fe6c9f
David Chelimsky changelog for #126 8f822b0
David Chelimsky tweak docstring #126 [ci skip] e5cd722
Mar 30, 2012
Fix using execution context methods in nested DSL matchers
- Fixes #127.
abba439
Mar 31, 2012
Fix RSpec::Matchers::DSL#define for compatibility with 1.8.x 21752df
Fix naming 70dd175
Apr 01, 2012
Justin Ko Merge pull request #128 from mirasrael/master
Fix using execution context methods in nested DSL matchers
5ffc547
Apr 02, 2012
David Chelimsky Changelog for #128
[ci skip]
ca5cc09
Apr 03, 2012
David Chelimsky bump to 2.9.1 b110213
13  Changelog.md
Source Rendered
... ...
@@ -1,3 +1,14 @@
  1
+### 2.9.1 / 2012-04-03
  2
+[full changelog](http://github.com/rspec/rspec-expectations/compare/v2.9.0...2.9.1)
  3
+
  4
+Bug fixes
  5
+
  6
+* Provide a helpful message if the diff between two objects is empty.
  7
+* Fix bug diffing single strings with multiline strings.
  8
+* Fix for error with using custom matchers inside other custom matchers
  9
+  (mirasrael)
  10
+* Fix using execution context methods in nested DSL matchers (mirasrael)
  11
+
1 12
 ### 2.9.0 / 2012-03-17
2 13
 [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.8.0...v2.9.0)
3 14
 
@@ -9,7 +20,7 @@ Enhancements
9 20
 
10 21
 Bug fixes
11 22
 
12  
-* Align respond_to? and method_missing in DSL-defined matchers.
  23
+* Align `respond_to?` and `method_missing` in DSL-defined matchers.
13 24
 * Clear out user-defined instance variables between invocations of DSL-defined
14 25
   matchers.
15 26
 * Dup the instance of a DSL generated matcher so its state is not changed by
15  Gemfile-custom.sample
... ...
@@ -1,10 +1,10 @@
1 1
 group :development do
2 2
   gem 'interactive_rspec'
3  
-  gem 'yard'
  3
+  gem 'yard', "~> 0.7.4"
4 4
   gem "relish", "~> 0.5.0"
5 5
   gem "guard-rspec", "0.5.0"
6 6
   gem "growl", "1.0.3"
7  
-  gem "spork", "0.9.0.rc9"
  7
+  gem "spork", "0.9.0"
8 8
 
9 9
   platforms :mri_18, :jruby do
10 10
     gem "rcov", "0.9.10"
@@ -21,9 +21,16 @@ group :development do
21 21
       gem 'ruby-debug-base19', '0.11.25'
22 22
       gem 'linecache19',       '0.5.12'
23 23
     when '1.9.3'
24  
-      # NOTE - see http://blog.wyeworks.com/2011/11/1/ruby-1-9-3-and-ruby-debug
25  
-      # for help setting up ruby-debug19 on ruby 1.9.3
26 24
       gem 'ruby-debug19',      '0.11.6'
  25
+      # NOTE - as of 2012-03-17 the following two gems have not been released,
  26
+      # so if you see either of these errors when trying to install the bundle:
  27
+      #
  28
+      #   Could not find gem 'ruby-debug-base19 (= 0.11.26) ruby' in the gems available on this machine.
  29
+      #   Could not find gem 'linecache19 (= 0.5.13) ruby' in the gems available on this machine.
  30
+      #
  31
+      # ... run 'script/download-ruby-debug-19-dependencies' and try again
  32
+      #
  33
+      # See http://blog.wyeworks.com/2011/11/1/ruby-1-9-3-and-ruby-debug for more info.
27 34
       gem 'ruby-debug-base19', '0.11.26'
28 35
       gem 'linecache19',       '0.5.13'
29 36
     end
21  lib/rspec/expectations/differ.rb
@@ -5,15 +5,12 @@
5 5
 module RSpec
6 6
   module Expectations
7 7
     class Differ
8  
-      def initialize(ignore=nil)
9  
-      end
10  
-
11 8
       # This is snagged from diff/lcs/ldiff.rb (which is a commandline tool)
12 9
       def diff_as_string(data_new, data_old)
13 10
         data_old = data_old.split(/\n/).map! { |e| e.chomp }
14 11
         data_new = data_new.split(/\n/).map! { |e| e.chomp }
15  
-        output = ""
16 12
         diffs = Diff::LCS.diff(data_old, data_new)
  13
+        output = ""
17 14
         return output if diffs.empty?
18 15
         oldhunk = hunk = nil
19 16
         file_length_difference = 0
@@ -41,10 +38,18 @@ def diff_as_string(data_new, data_old)
41 38
         output << oldhunk.diff(format) << "\n"
42 39
       end
43 40
 
44  
-      def diff_as_object(actual,expected)
45  
-        actual = object_to_string(actual)
46  
-        expected = object_to_string(expected)
47  
-        diff_as_string(actual, expected)
  41
+      def diff_as_object(actual, expected)
  42
+        actual_as_string = object_to_string(actual)
  43
+        expected_as_string = object_to_string(expected)
  44
+        diff = diff_as_string(actual_as_string, expected_as_string)
  45
+
  46
+        if diff.empty?
  47
+          "#{actual}.==(#{expected}) returned false even though the diff " \
  48
+          "between #{actual} and #{expected} is empty. Check the " \
  49
+          "implementation of #{actual}.==."
  50
+        else
  51
+          diff
  52
+        end
48 53
       end
49 54
 
50 55
     protected
3  lib/rspec/expectations/fail_with.rb
@@ -5,7 +5,7 @@ class << self
5 5
       def differ
6 6
         @differ ||= Differ.new
7 7
       end
8  
-      
  8
+
9 9
       # Raises an RSpec::Expectations::ExpectationNotMetError with message.
10 10
       # @param [String] message
11 11
       # @param [Object] expected
@@ -22,6 +22,7 @@ def fail_with(message, expected=nil, actual=nil)
22 22
         if actual && expected
23 23
           if all_strings?(actual, expected)
24 24
             if any_multiline_strings?(actual, expected)
  25
+              expected = expected.join(',') if Array === expected
25 26
               message << "\nDiff:" << differ.diff_as_string(actual, expected)
26 27
             end
27 28
           elsif no_procs?(actual, expected) && no_numbers?(actual, expected)
2  lib/rspec/expectations/version.rb
@@ -2,7 +2,7 @@ module RSpec
2 2
   module Expectations
3 3
     # @private
4 4
     module Version
5  
-      STRING = '2.9.0'
  5
+      STRING = '2.9.1'
6 6
     end
7 7
   end
8 8
 end
1  lib/rspec/matchers/block_aliases.rb
... ...
@@ -1,3 +1,4 @@
  1
+require 'rspec/expectations/extensions/kernel'
1 2
 module RSpec
2 3
   module Matchers
3 4
     module BlockAliases
7  lib/rspec/matchers/dsl.rb
@@ -4,10 +4,11 @@ module DSL
4 4
       # Defines a custom matcher.
5 5
       # @see RSpec::Matchers
6 6
       def define(name, &declarations)
7  
-        matcher = RSpec::Matchers::DSL::Matcher.new(name, &declarations)
  7
+        matcher_template = RSpec::Matchers::DSL::Matcher.new(name, &declarations)
8 8
         define_method name do |*expected|
9  
-          $matcher_execution_context = self
10  
-          matcher.for_expected(*expected)
  9
+          matcher = matcher_template.for_expected(*expected)
  10
+          matcher.matcher_execution_context = @matcher_execution_context || self
  11
+          matcher
11 12
         end
12 13
       end
13 14
 
11  lib/rspec/matchers/matcher.rb
@@ -11,6 +11,7 @@ class Matcher
11 11
         include RSpec::Matchers
12 12
 
13 13
         attr_reader :expected, :actual, :rescued_exception
  14
+        attr_accessor :matcher_execution_context
14 15
 
15 16
         # @api private
16 17
         def initialize(name, &declarations)
@@ -23,7 +24,7 @@ def initialize(name, &declarations)
23 24
           @messages = {}
24 25
         end
25 26
 
26  
-        PERSISENT_INSTANCE_VARIABLES = [
  27
+        PERSISTENT_INSTANCE_VARIABLES = [
27 28
           :@name, :@declarations, :@diffable, :@messages,
28 29
           :@match_block, :@match_for_should_not_block,
29 30
           :@expected_exception
@@ -34,7 +35,7 @@ def for_expected(*expected)
34 35
           @expected = expected
35 36
           dup.instance_eval do
36 37
             instance_variables.map {|ivar| ivar.intern}.each do |ivar|
37  
-              instance_variable_set(ivar, nil) unless (PERSISENT_INSTANCE_VARIABLES + [:@expected]).include?(ivar)
  38
+              instance_variable_set(ivar, nil) unless (PERSISTENT_INSTANCE_VARIABLES + [:@expected]).include?(ivar)
38 39
             end
39 40
             making_declared_methods_public do
40 41
               instance_eval_with_args(*@expected, &@declarations)
@@ -222,14 +223,14 @@ def does_not_match?(actual)
222 223
         end
223 224
 
224 225
         def respond_to?(method, include_private=false)
225  
-          $matcher_execution_context.respond_to?(method, include_private) || super
  226
+          super || @matcher_execution_context.respond_to?(method, include_private)
226 227
         end
227 228
 
228 229
         private
229 230
 
230 231
         def method_missing(method, *args, &block)
231  
-          if $matcher_execution_context.respond_to?(method)
232  
-            $matcher_execution_context.send method, *args, &block
  232
+          if @matcher_execution_context.respond_to?(method)
  233
+            @matcher_execution_context.send method, *args, &block
233 234
           else
234 235
             super(method, *args, &block)
235 236
           end
4  script/download-ruby-debug-19-dependencies
... ...
@@ -0,0 +1,4 @@
  1
+mkdir -p vendor/cache
  2
+cd vendor/cache
  3
+wget http://rubyforge.org/frs/download.php/75414/linecache19-0.5.13.gem
  4
+wget http://rubyforge.org/frs/download.php/75415/ruby-debug-base19-0.11.26.gem
159  spec/rspec/expectations/differ_spec.rb
@@ -2,34 +2,15 @@
2 2
 require 'ostruct'
3 3
 
4 4
 module RSpec
5  
-  module Fixtures
6  
-    class Animal
7  
-      def initialize(name,species)
8  
-        @name,@species = name,species
9  
-      end
  5
+  module Expectations
  6
+    describe Differ do
  7
+      let(:differ) { RSpec::Expectations::Differ.new }
10 8
 
11  
-      def inspect
12  
-        <<-EOA
13  
-<Animal
14  
-  name=#{@name},
15  
-  species=#{@species}
16  
->
17  
-        EOA
18  
-      end
19  
-    end
20  
-  end
21  
-end
22  
-
23  
-describe "Diff" do
24  
-  before(:each) do
25  
-    @options = OpenStruct.new(:diff_format => :unified, :context_lines => 3)
26  
-    @differ = RSpec::Expectations::Differ.new(@options)
27  
-  end
28  
-
29  
-  it "outputs unified diff of two strings" do
30  
-    expected="foo\nbar\nzap\nthis\nis\nsoo\nvery\nvery\nequal\ninsert\na\nline\n"
31  
-    actual="foo\nzap\nbar\nthis\nis\nsoo\nvery\nvery\nequal\ninsert\na\nanother\nline\n"
32  
-    expected_diff= <<'EOD'
  9
+      describe '#diff_as_string' do
  10
+        it "outputs unified diff of two strings" do
  11
+          expected="foo\nbar\nzap\nthis\nis\nsoo\nvery\nvery\nequal\ninsert\na\nline\n"
  12
+          actual="foo\nzap\nbar\nthis\nis\nsoo\nvery\nvery\nequal\ninsert\na\nanother\nline\n"
  13
+          expected_diff= <<'EOD'
33 14
 
34 15
 
35 16
 @@ -1,6 +1,6 @@
@@ -48,15 +29,58 @@ def inspect
48 29
  line
49 30
 EOD
50 31
 
51  
-    diff = @differ.diff_as_string(expected, actual)
52  
-    diff.should eql(expected_diff)
53  
-  end
  32
+          diff = differ.diff_as_string(expected, actual)
  33
+          diff.should eql(expected_diff)
  34
+        end
  35
+      end
  36
+
  37
+      describe '#diff_as_object' do
  38
+        it "outputs unified diff message of two objects" do
  39
+          animal_class = Class.new do
  40
+            def initialize(name, species)
  41
+              @name, @species = name, species
  42
+            end
54 43
 
55  
-  it "outputs unified diff message of two arrays" do
56  
-    expected = [ :foo, 'bar', :baz, 'quux', :metasyntactic, 'variable', :delta, 'charlie', :width, 'quite wide' ]
57  
-    actual   = [ :foo, 'bar', :baz, 'quux', :metasyntactic, 'variable', :delta, 'tango'  , :width, 'very wide'  ]
  44
+            def inspect
  45
+              <<-EOA
  46
+<Animal
  47
+  name=#{@name},
  48
+  species=#{@species}
  49
+>
  50
+              EOA
  51
+            end
  52
+          end
58 53
 
59  
-    expected_diff = <<EOD
  54
+          expected = animal_class.new "bob", "giraffe"
  55
+          actual   = animal_class.new "bob", "tortoise"
  56
+
  57
+          expected_diff = <<'EOD'
  58
+
  59
+@@ -1,5 +1,5 @@
  60
+ <Animal
  61
+   name=bob,
  62
+-  species=tortoise
  63
++  species=giraffe
  64
+ >
  65
+EOD
  66
+
  67
+          diff = differ.diff_as_object(expected,actual)
  68
+          diff.should == expected_diff
  69
+        end
  70
+
  71
+        it "outputs a message if the diff is empty" do
  72
+          diff = differ.diff_as_object('foo', 'foo')
  73
+          diff.should eq(
  74
+            "foo.==(foo) returned false even though the diff between " \
  75
+            "foo and foo is empty. Check the implementation of foo.==."
  76
+          )
  77
+        end
  78
+
  79
+        it "outputs unified diff message of two arrays" do
  80
+          expected = [ :foo, 'bar', :baz, 'quux', :metasyntactic, 'variable', :delta, 'charlie', :width, 'quite wide' ]
  81
+          actual   = [ :foo, 'bar', :baz, 'quux', :metasyntactic, 'variable', :delta, 'tango'  , :width, 'very wide'  ]
  82
+
  83
+          expected_diff = <<'EOD'
60 84
 
61 85
 
62 86
 @@ -5,7 +5,7 @@
@@ -70,33 +94,15 @@ def inspect
70 94
 + "quite wide"]
71 95
 EOD
72 96
 
73  
-    diff = @differ.diff_as_object(expected,actual)
74  
-    diff.should == expected_diff
75  
-  end
76  
-
77  
-  it "outputs unified diff message of two objects" do
78  
-    expected = RSpec::Fixtures::Animal.new "bob", "giraffe"
79  
-    actual   = RSpec::Fixtures::Animal.new "bob", "tortoise"
80  
-
81  
-    expected_diff = <<'EOD'
82  
-
83  
-@@ -1,5 +1,5 @@
84  
- <Animal
85  
-   name=bob,
86  
--  species=tortoise
87  
-+  species=giraffe
88  
- >
89  
-EOD
90  
-
91  
-    diff = @differ.diff_as_object(expected,actual)
92  
-    diff.should == expected_diff
93  
-  end
  97
+          diff = differ.diff_as_object(expected,actual)
  98
+          diff.should == expected_diff
  99
+        end
94 100
 
95  
-  it "outputs unified diff message of two hashes" do
96  
-    expected = { :foo => 'bar', :baz => 'quux', :metasyntactic => 'variable', :delta => 'charlie', :width =>'quite wide' }
97  
-    actual   = { :foo => 'bar', :metasyntactic => 'variable', :delta => 'charlotte', :width =>'quite wide' }
  101
+        it "outputs unified diff message of two hashes" do
  102
+          expected = { :foo => 'bar', :baz => 'quux', :metasyntactic => 'variable', :delta => 'charlie', :width =>'quite wide' }
  103
+          actual   = { :foo => 'bar', :metasyntactic => 'variable', :delta => 'charlotte', :width =>'quite wide' }
98 104
 
99  
-    expected_diff = <<'EOD'
  105
+          expected_diff = <<'EOD'
100 106
 
101 107
 @@ -1,4 +1,5 @@
102 108
 -:delta => "charlotte",
@@ -107,30 +113,30 @@ def inspect
107 113
  :width => "quite wide"
108 114
 EOD
109 115
 
110  
-    diff = @differ.diff_as_object(expected,actual)
111  
-    diff.should == expected_diff
112  
-  end
  116
+          diff = differ.diff_as_object(expected,actual)
  117
+          diff.should == expected_diff
  118
+        end
113 119
 
114  
-  it "outputs unified diff of single line strings" do
115  
-    expected = "this is one string"
116  
-    actual   = "this is another string"
  120
+        it "outputs unified diff of single line strings" do
  121
+          expected = "this is one string"
  122
+          actual   = "this is another string"
117 123
 
118  
-    expected_diff = <<EOD
  124
+          expected_diff = <<'EOD'
119 125
 
120 126
 @@ -1,2 +1,2 @@
121 127
 -"this is another string"
122 128
 +"this is one string"
123 129
 EOD
124 130
 
125  
-    diff = @differ.diff_as_object(expected,actual)
126  
-    diff.should == expected_diff
127  
-  end
  131
+          diff = differ.diff_as_object(expected,actual)
  132
+          diff.should == expected_diff
  133
+        end
128 134
 
129  
-  it "outputs unified diff of multi line strings" do
130  
-    expected = "this is:\n  one string"
131  
-    actual   = "this is:\n  another string"
  135
+        it "outputs unified diff of multi line strings" do
  136
+          expected = "this is:\n  one string"
  137
+          actual   = "this is:\n  another string"
132 138
 
133  
-    expected_diff = <<EOD
  139
+          expected_diff = <<'EOD'
134 140
 
135 141
 @@ -1,3 +1,3 @@
136 142
  this is:
@@ -138,7 +144,10 @@ def inspect
138 144
 +  one string
139 145
 EOD
140 146
 
141  
-    diff = @differ.diff_as_object(expected,actual)
142  
-    diff.should == expected_diff
  147
+          diff = differ.diff_as_object(expected,actual)
  148
+          diff.should == expected_diff
  149
+        end
  150
+      end
  151
+    end
143 152
   end
144 153
 end
16  spec/rspec/matchers/dsl_spec.rb
@@ -5,6 +5,22 @@ def question?
5 5
     :answer
6 6
   end
7 7
 
  8
+  def ok
  9
+    "ok"
  10
+  end
  11
+
  12
+  it "supports calling custom matchers from within other custom matchers" do
  13
+    RSpec::Matchers.define :be_ok do
  14
+      match { |actual| actual == ok }
  15
+    end
  16
+
  17
+    RSpec::Matchers.define :be_well do
  18
+      match { |actual| actual.should be_ok }
  19
+    end
  20
+
  21
+    ok.should be_well
  22
+  end
  23
+
8 24
   it "has access to methods available in the scope of the example" do
9 25
     RSpec::Matchers::define(:ignore) {}
10 26
     ignore.question?.should eq(:answer)
12  spec/rspec/matchers/include_spec.rb
@@ -16,6 +16,18 @@
16 16
           "abc".should include("d")
17 17
         }.should fail_matching("expected \"abc\" to include \"d\"")
18 18
       end
  19
+
  20
+      it "includes a diff when actual is multiline" do
  21
+        lambda {
  22
+          "abc\ndef".should include("g")
  23
+        }.should fail_matching("expected \"abc\\ndef\" to include \"g\"\nDiff")
  24
+      end
  25
+
  26
+      it "includes a diff when actual is multiline and there are multiple expecteds" do
  27
+        lambda {
  28
+          "abc\ndef".should include("g", "h")
  29
+        }.should fail_matching("expected \"abc\\ndef\" to include \"g\" and \"h\"\nDiff")
  30
+      end
19 31
     end
20 32
 
21 33
     context "for an array target" do

No commit comments for this range

Something went wrong with that request. Please try again.