rspec-expectations 2.9.0 → 2.9.1

Sign up to get free protection for your applications and to get access to all the features.
data/Changelog.md CHANGED
@@ -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
@@ -5,15 +5,12 @@ require 'pp'
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 @@ module RSpec
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
@@ -5,7 +5,7 @@ module RSpec
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 @@ module RSpec
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,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,3 +1,4 @@
1
+ require 'rspec/expectations/extensions/kernel'
1
2
  module RSpec
2
3
  module Matchers
3
4
  module BlockAliases
@@ -4,10 +4,11 @@ module RSpec
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,6 +11,7 @@ module RSpec
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 @@ module RSpec
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 @@ module RSpec
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 @@ module RSpec
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
@@ -2,34 +2,15 @@ require 'spec_helper'
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 @@ describe "Diff" do
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 @@ EOD
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 @@ EOD
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 @@ EOD
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
@@ -5,6 +5,22 @@ describe "a matcher defined using the matcher DSL" do
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)
@@ -16,6 +16,18 @@ describe "#include matcher" do
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
metadata CHANGED
@@ -1,96 +1,87 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rspec-expectations
3
- version: !ruby/object:Gem::Version
4
- hash: 43
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.9.1
5
5
  prerelease:
6
- segments:
7
- - 2
8
- - 9
9
- - 0
10
- version: 2.9.0
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Steven Baker
14
9
  - David Chelimsky
15
10
  autorequire:
16
11
  bindir: bin
17
12
  cert_chain: []
18
-
19
- date: 2012-03-17 00:00:00 Z
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- version_requirements: &id001 !ruby/object:Gem::Requirement
13
+ date: 2012-04-03 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: diff-lcs
17
+ requirement: !ruby/object:Gem::Requirement
23
18
  none: false
24
- requirements:
19
+ requirements:
25
20
  - - ~>
26
- - !ruby/object:Gem::Version
27
- hash: 21
28
- segments:
29
- - 1
30
- - 1
31
- - 3
21
+ - !ruby/object:Gem::Version
32
22
  version: 1.1.3
33
- prerelease: false
34
- requirement: *id001
35
- name: diff-lcs
36
23
  type: :runtime
37
- - !ruby/object:Gem::Dependency
38
- version_requirements: &id002 !ruby/object:Gem::Requirement
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
39
26
  none: false
40
- requirements:
27
+ requirements:
41
28
  - - ~>
42
- - !ruby/object:Gem::Version
43
- hash: 63
44
- segments:
45
- - 0
46
- - 9
47
- - 2
48
- version: 0.9.2
49
- prerelease: false
50
- requirement: *id002
29
+ - !ruby/object:Gem::Version
30
+ version: 1.1.3
31
+ - !ruby/object:Gem::Dependency
51
32
  name: rake
52
- type: :development
53
- - !ruby/object:Gem::Dependency
54
- version_requirements: &id003 !ruby/object:Gem::Requirement
33
+ requirement: !ruby/object:Gem::Requirement
55
34
  none: false
56
- requirements:
35
+ requirements:
57
36
  - - ~>
58
- - !ruby/object:Gem::Version
59
- hash: 1
60
- segments:
61
- - 1
62
- - 1
63
- - 9
64
- version: 1.1.9
37
+ - !ruby/object:Gem::Version
38
+ version: 0.9.2
39
+ type: :development
65
40
  prerelease: false
66
- requirement: *id003
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: 0.9.2
47
+ - !ruby/object:Gem::Dependency
67
48
  name: cucumber
68
- type: :development
69
- - !ruby/object:Gem::Dependency
70
- version_requirements: &id004 !ruby/object:Gem::Requirement
49
+ requirement: !ruby/object:Gem::Requirement
71
50
  none: false
72
- requirements:
51
+ requirements:
73
52
  - - ~>
74
- - !ruby/object:Gem::Version
75
- hash: 25
76
- segments:
77
- - 0
78
- - 4
79
- - 11
80
- version: 0.4.11
53
+ - !ruby/object:Gem::Version
54
+ version: 1.1.9
55
+ type: :development
81
56
  prerelease: false
82
- requirement: *id004
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: 1.1.9
63
+ - !ruby/object:Gem::Dependency
83
64
  name: aruba
65
+ requirement: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ~>
69
+ - !ruby/object:Gem::Version
70
+ version: 0.4.11
84
71
  type: :development
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ~>
77
+ - !ruby/object:Gem::Version
78
+ version: 0.4.11
85
79
  description: rspec expectations (should[_not] and matchers)
86
80
  email: rspec-users@rubyforge.org
87
81
  executables: []
88
-
89
82
  extensions: []
90
-
91
83
  extra_rdoc_files: []
92
-
93
- files:
84
+ files:
94
85
  - lib/rspec-expectations.rb
95
86
  - lib/rspec/expectations.rb
96
87
  - lib/rspec/expectations/deprecation.rb
@@ -207,39 +198,38 @@ files:
207
198
  - spec/support/matchers.rb
208
199
  - spec/support/ruby_version.rb
209
200
  homepage: http://github.com/rspec/rspec-expectations
210
- licenses:
201
+ licenses:
211
202
  - MIT
212
203
  post_install_message:
213
- rdoc_options:
204
+ rdoc_options:
214
205
  - --charset=UTF-8
215
- require_paths:
206
+ require_paths:
216
207
  - lib
217
- required_ruby_version: !ruby/object:Gem::Requirement
208
+ required_ruby_version: !ruby/object:Gem::Requirement
218
209
  none: false
219
- requirements:
220
- - - ">="
221
- - !ruby/object:Gem::Version
222
- hash: 3
223
- segments:
210
+ requirements:
211
+ - - ! '>='
212
+ - !ruby/object:Gem::Version
213
+ version: '0'
214
+ segments:
224
215
  - 0
225
- version: "0"
226
- required_rubygems_version: !ruby/object:Gem::Requirement
216
+ hash: -382523939105044110
217
+ required_rubygems_version: !ruby/object:Gem::Requirement
227
218
  none: false
228
- requirements:
229
- - - ">="
230
- - !ruby/object:Gem::Version
231
- hash: 3
232
- segments:
219
+ requirements:
220
+ - - ! '>='
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
223
+ segments:
233
224
  - 0
234
- version: "0"
225
+ hash: -382523939105044110
235
226
  requirements: []
236
-
237
227
  rubyforge_project: rspec
238
- rubygems_version: 1.8.15
228
+ rubygems_version: 1.8.21
239
229
  signing_key:
240
230
  specification_version: 3
241
- summary: rspec-expectations-2.9.0
242
- test_files:
231
+ summary: rspec-expectations-2.9.1
232
+ test_files:
243
233
  - features/README.markdown
244
234
  - features/Upgrade.md
245
235
  - features/built_in_matchers/README.md
@@ -306,4 +296,3 @@ test_files:
306
296
  - spec/support/classes.rb
307
297
  - spec/support/matchers.rb
308
298
  - spec/support/ruby_version.rb
309
- has_rdoc: