rspec-expectations 2.0.0.beta.8 → 2.0.0.beta.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. data/README.markdown +1 -1
  2. data/Rakefile +8 -7
  3. data/Upgrade.markdown +6 -6
  4. data/VERSION +1 -1
  5. data/features/expectations/customized_message.feature +1 -1
  6. data/features/expectations/implicit_docstrings.feature +2 -2
  7. data/features/matchers/access_running_example.feature +5 -5
  8. data/features/matchers/define_diffable_matcher.feature +2 -2
  9. data/features/matchers/define_matcher.feature +14 -14
  10. data/features/matchers/define_matcher_outside_rspec.feature +2 -2
  11. data/features/matchers/define_matcher_with_fluent_interface.feature +2 -2
  12. data/features/matchers/expect_change.feature +2 -2
  13. data/features/matchers/expect_error.feature +2 -2
  14. data/lib/rspec/expectations.rb +7 -5
  15. data/lib/rspec/expectations/backward_compatibility.rb +16 -0
  16. data/lib/rspec/expectations/differ.rb +58 -0
  17. data/lib/rspec/expectations/errors.rb +1 -1
  18. data/lib/rspec/expectations/extensions/kernel.rb +4 -4
  19. data/lib/rspec/expectations/extensions/rspec/core/example_group.rb +1 -1
  20. data/lib/rspec/expectations/fail_with.rb +6 -4
  21. data/lib/rspec/expectations/handler.rb +11 -11
  22. data/lib/rspec/expectations/version.rb +1 -1
  23. data/lib/rspec/matchers.rb +7 -8
  24. data/lib/rspec/matchers/be.rb +6 -6
  25. data/lib/rspec/matchers/be_close.rb +1 -1
  26. data/lib/rspec/matchers/be_instance_of.rb +1 -1
  27. data/lib/rspec/matchers/be_kind_of.rb +1 -1
  28. data/lib/rspec/matchers/change.rb +1 -1
  29. data/lib/rspec/matchers/compatibility.rb +2 -2
  30. data/lib/rspec/matchers/dsl.rb +4 -4
  31. data/lib/rspec/matchers/eq.rb +1 -1
  32. data/lib/rspec/matchers/eql.rb +1 -1
  33. data/lib/rspec/matchers/equal.rb +1 -1
  34. data/lib/rspec/matchers/errors.rb +1 -1
  35. data/lib/rspec/matchers/exist.rb +1 -1
  36. data/lib/rspec/matchers/extensions/instance_exec.rb +1 -1
  37. data/lib/rspec/matchers/generated_descriptions.rb +1 -1
  38. data/lib/rspec/matchers/has.rb +1 -1
  39. data/lib/rspec/matchers/have.rb +1 -1
  40. data/lib/rspec/matchers/include.rb +1 -1
  41. data/lib/rspec/matchers/match.rb +1 -1
  42. data/lib/rspec/matchers/match_array.rb +3 -3
  43. data/lib/rspec/matchers/matcher.rb +13 -13
  44. data/lib/rspec/matchers/method_missing.rb +1 -1
  45. data/lib/rspec/matchers/operator_matcher.rb +4 -4
  46. data/lib/rspec/matchers/pretty.rb +1 -1
  47. data/lib/rspec/matchers/raise_error.rb +1 -1
  48. data/lib/rspec/matchers/respond_to.rb +1 -1
  49. data/lib/rspec/matchers/satisfy.rb +1 -1
  50. data/lib/rspec/matchers/throw_symbol.rb +1 -1
  51. data/rspec-expectations.gemspec +17 -14
  52. data/spec/rspec/expectations/{differs/default_spec.rb → differ_spec.rb} +4 -36
  53. data/spec/rspec/expectations/fail_with_spec.rb +6 -50
  54. data/spec/rspec/expectations/handler_spec.rb +22 -22
  55. data/spec/rspec/matchers/be_close_spec.rb +1 -1
  56. data/spec/rspec/matchers/be_instance_of_spec.rb +1 -1
  57. data/spec/rspec/matchers/be_kind_of_spec.rb +1 -1
  58. data/spec/rspec/matchers/change_spec.rb +3 -3
  59. data/spec/rspec/matchers/compatibility_spec.rb +3 -3
  60. data/spec/rspec/matchers/description_generation_spec.rb +28 -28
  61. data/spec/rspec/matchers/dsl_spec.rb +3 -3
  62. data/spec/rspec/matchers/eq_spec.rb +1 -1
  63. data/spec/rspec/matchers/eql_spec.rb +1 -1
  64. data/spec/rspec/matchers/equal_spec.rb +1 -1
  65. data/spec/rspec/matchers/exist_spec.rb +1 -1
  66. data/spec/rspec/matchers/have_spec.rb +3 -3
  67. data/spec/rspec/matchers/match_array_spec.rb +3 -0
  68. data/spec/rspec/matchers/matcher_spec.rb +25 -25
  69. data/spec/rspec/matchers/operator_matcher_spec.rb +12 -12
  70. data/spec/rspec/matchers/throw_symbol_spec.rb +1 -1
  71. data/spec/spec_helper.rb +6 -7
  72. data/spec/support/classes.rb +1 -1
  73. metadata +35 -21
  74. data/lib/rspec/expectations/differs/default.rb +0 -62
  75. data/lib/rspec/expectations/differs/load-diff-lcs.rb +0 -7
@@ -1,4 +1,4 @@
1
- module Rspec
1
+ module RSpec
2
2
  module Expectations
3
3
  # If Test::Unit is loaed, we'll use its error as baseclass, so that Test::Unit
4
4
  # will report unmet RSpec expectations as failures rather than errors.
@@ -17,14 +17,14 @@ module Kernel
17
17
  # receiver.should =~ regexp
18
18
  # => Passes if (receiver =~ regexp)
19
19
  #
20
- # See Rspec::Matchers for more information about matchers
20
+ # See RSpec::Matchers for more information about matchers
21
21
  #
22
22
  # == Warning
23
23
  #
24
24
  # NOTE that this does NOT support receiver.should != expected.
25
25
  # Instead, use receiver.should_not == expected
26
26
  def should(matcher=nil, message=nil, &block)
27
- Rspec::Expectations::PositiveExpectationHandler.handle_matcher(self, matcher, message, &block)
27
+ RSpec::Expectations::PositiveExpectationHandler.handle_matcher(self, matcher, message, &block)
28
28
  end
29
29
 
30
30
  # :call-seq:
@@ -45,8 +45,8 @@ module Kernel
45
45
  # receiver.should_not =~ regexp
46
46
  # => Passes unless (receiver =~ regexp)
47
47
  #
48
- # See Rspec::Matchers for more information about matchers
48
+ # See RSpec::Matchers for more information about matchers
49
49
  def should_not(matcher=nil, message=nil, &block)
50
- Rspec::Expectations::NegativeExpectationHandler.handle_matcher(self, matcher, message, &block)
50
+ RSpec::Expectations::NegativeExpectationHandler.handle_matcher(self, matcher, message, &block)
51
51
  end
52
52
  end
@@ -1,4 +1,4 @@
1
- module Rspec
1
+ module RSpec
2
2
  module Core
3
3
  class ExampleGroup
4
4
  module BlockAliases
@@ -1,9 +1,11 @@
1
- module Rspec
1
+ module RSpec
2
2
  module Expectations
3
3
  class << self
4
- attr_accessor :differ
4
+ def differ
5
+ @differ ||= Differ.new
6
+ end
5
7
 
6
- # raises a Rspec::Expectations::ExpectationNotMetError with message
8
+ # raises a RSpec::Expectations::ExpectationNotMetError with message
7
9
  #
8
10
  # When a differ has been assigned and fail_with is passed
9
11
  # <code>expected</code> and <code>target</code>, passes them
@@ -20,7 +22,7 @@ module Rspec
20
22
  message << "\nDiff:" << self.differ.diff_as_object(target, expected)
21
23
  end
22
24
  end
23
- Kernel::raise(Rspec::Expectations::ExpectationNotMetError.new(message))
25
+ Kernel::raise(RSpec::Expectations::ExpectationNotMetError.new(message))
24
26
  end
25
27
  end
26
28
  end
@@ -1,12 +1,12 @@
1
- module Rspec
1
+ module RSpec
2
2
  module Expectations
3
3
  class InvalidMatcherError < ArgumentError; end
4
4
 
5
5
  class PositiveExpectationHandler
6
6
  def self.handle_matcher(actual, matcher, message=nil, &block)
7
- ::Rspec::Matchers.last_should = :should
8
- ::Rspec::Matchers.last_matcher = matcher
9
- return ::Rspec::Matchers::PositiveOperatorMatcher.new(actual) if matcher.nil?
7
+ ::RSpec::Matchers.last_should = :should
8
+ ::RSpec::Matchers.last_matcher = matcher
9
+ return ::RSpec::Matchers::PositiveOperatorMatcher.new(actual) if matcher.nil?
10
10
 
11
11
  match = matcher.matches?(actual, &block)
12
12
  return match if match
@@ -16,18 +16,18 @@ module Rspec
16
16
  matcher.failure_message
17
17
 
18
18
  if matcher.respond_to?(:diffable?) && matcher.diffable?
19
- ::Rspec::Expectations.fail_with message, matcher.expected.first, matcher.actual
19
+ ::RSpec::Expectations.fail_with message, matcher.expected.first, matcher.actual
20
20
  else
21
- ::Rspec::Expectations.fail_with message
21
+ ::RSpec::Expectations.fail_with message
22
22
  end
23
23
  end
24
24
  end
25
25
 
26
26
  class NegativeExpectationHandler
27
27
  def self.handle_matcher(actual, matcher, message=nil, &block)
28
- ::Rspec::Matchers.last_should = :should_not
29
- ::Rspec::Matchers.last_matcher = matcher
30
- return ::Rspec::Matchers::NegativeOperatorMatcher.new(actual) if matcher.nil?
28
+ ::RSpec::Matchers.last_should = :should_not
29
+ ::RSpec::Matchers.last_matcher = matcher
30
+ return ::RSpec::Matchers::NegativeOperatorMatcher.new(actual) if matcher.nil?
31
31
 
32
32
  match = matcher.respond_to?(:does_not_match?) ?
33
33
  !matcher.does_not_match?(actual, &block) :
@@ -39,9 +39,9 @@ module Rspec
39
39
  matcher.negative_failure_message
40
40
 
41
41
  if matcher.respond_to?(:diffable?) && matcher.diffable?
42
- ::Rspec::Expectations.fail_with message, matcher.expected.first, matcher.actual
42
+ ::RSpec::Expectations.fail_with message, matcher.expected.first, matcher.actual
43
43
  else
44
- ::Rspec::Expectations.fail_with message
44
+ ::RSpec::Expectations.fail_with message
45
45
  end
46
46
  end
47
47
  end
@@ -1,4 +1,4 @@
1
- module Rspec # :nodoc:
1
+ module RSpec # :nodoc:
2
2
  module Expectations # :nodoc:
3
3
  module Version # :nodoc:
4
4
  STRING = File.readlines(File.expand_path('../../../../VERSION', __FILE__)).first
@@ -1,4 +1,4 @@
1
- module Rspec
1
+ module RSpec
2
2
  # RSpec ships with a number of useful Expression Matchers. An Expression Matcher
3
3
  # is any object that responds to the following methods:
4
4
  #
@@ -17,7 +17,7 @@ module Rspec
17
17
  # failure_message (use failure_message_for_should instead)
18
18
  # negative_failure_message (use failure_message_for_should_not instead)
19
19
  #
20
- # See Rspec::Expectations to learn how to use these as Expectation Matchers.
20
+ # See RSpec::Expectations to learn how to use these as Expectation Matchers.
21
21
  #
22
22
  # == Predicates
23
23
  #
@@ -78,7 +78,7 @@ module Rspec
78
78
  #
79
79
  # You can create such a matcher like so:
80
80
  #
81
- # Rspec::Matchers.define :be_in_zone do |zone|
81
+ # RSpec::Matchers.define :be_in_zone do |zone|
82
82
  # match do |player|
83
83
  # player.in_zone?(zone)
84
84
  # end
@@ -88,7 +88,7 @@ module Rspec
88
88
  # with logical default messages for failures. You can override the failure
89
89
  # messages and the generated description as follows:
90
90
  #
91
- # Rspec::Matchers.define :be_in_zone do |zone|
91
+ # RSpec::Matchers.define :be_in_zone do |zone|
92
92
  # match do |player|
93
93
  # player.in_zone?(zone)
94
94
  # end
@@ -157,13 +157,13 @@ module Rspec
157
157
  # or you can include in globally in a spec_helper.rb file <tt>require</tt>d
158
158
  # from your spec file(s):
159
159
  #
160
- # Rspec::Runner.configure do |config|
160
+ # RSpec::Runner.configure do |config|
161
161
  # config.include(CustomGameMatchers)
162
162
  # end
163
163
  #
164
164
  module Matchers
165
- if Rspec.respond_to?(:configure)
166
- Rspec.configure {|c| c.include self}
165
+ if RSpec.respond_to?(:configure)
166
+ RSpec.configure {|c| c.include self}
167
167
  end
168
168
  end
169
169
  end
@@ -195,4 +195,3 @@ require 'rspec/matchers/satisfy'
195
195
  require 'rspec/matchers/throw_symbol'
196
196
  require 'rspec/matchers/compatibility'
197
197
  require 'rspec/matchers/dsl'
198
-
@@ -1,18 +1,18 @@
1
1
  require 'rspec/matchers/dsl'
2
2
 
3
- Rspec::Matchers.define :be_true do
3
+ RSpec::Matchers.define :be_true do
4
4
  match do |actual|
5
5
  !!actual
6
6
  end
7
7
  end
8
8
 
9
- Rspec::Matchers.define :be_false do
9
+ RSpec::Matchers.define :be_false do
10
10
  match do |actual|
11
11
  !actual
12
12
  end
13
13
  end
14
14
 
15
- Rspec::Matchers.define :be_nil do
15
+ RSpec::Matchers.define :be_nil do
16
16
  match do |actual|
17
17
  actual.nil?
18
18
  end
@@ -26,11 +26,11 @@ Rspec::Matchers.define :be_nil do
26
26
  end
27
27
  end
28
28
 
29
- module Rspec
29
+ module RSpec
30
30
  module Matchers
31
31
 
32
32
  class Be #:nodoc:
33
- include Rspec::Matchers::Pretty
33
+ include RSpec::Matchers::Pretty
34
34
 
35
35
  def initialize(*args, &block)
36
36
  @args = args
@@ -216,7 +216,7 @@ it is a bit confusing.
216
216
  # the caller should satisfy an if condition (to be or not to be).
217
217
  #
218
218
  # Predicates are any Ruby method that ends in a "?" and returns true or false.
219
- # Given be_ followed by arbitrary_predicate (without the "?"), Rspec will match
219
+ # Given be_ followed by arbitrary_predicate (without the "?"), RSpec will match
220
220
  # convert that into a query against the target object.
221
221
  #
222
222
  # The arbitrary_predicate feature will handle any predicate
@@ -1,4 +1,4 @@
1
- module Rspec
1
+ module RSpec
2
2
  module Matchers
3
3
  # :call-seq:
4
4
  # should be_close(expected, delta)
@@ -1,4 +1,4 @@
1
- module Rspec
1
+ module RSpec
2
2
  module Matchers
3
3
  # :call-seq:
4
4
  # should be_instance_of(expected)
@@ -1,4 +1,4 @@
1
- module Rspec
1
+ module RSpec
2
2
  module Matchers
3
3
  # :call-seq:
4
4
  # should be_kind_of(expected)
@@ -1,4 +1,4 @@
1
- module Rspec
1
+ module RSpec
2
2
  module Matchers
3
3
 
4
4
  #Based on patch from Wilson Bilkovich
@@ -1,5 +1,5 @@
1
- Rspec::Matchers.constants.each do |c|
2
- if Class === (klass = Rspec::Matchers.const_get(c))
1
+ RSpec::Matchers.constants.each do |c|
2
+ if Class === (klass = RSpec::Matchers.const_get(c))
3
3
  if klass.public_instance_methods.any? {|m| ['failure_message_for_should',:failure_message_for_should].include?(m)}
4
4
  klass.class_eval do
5
5
  alias_method :failure_message, :failure_message_for_should
@@ -1,15 +1,15 @@
1
- module Rspec
1
+ module RSpec
2
2
  module Matchers
3
3
  module DSL
4
- # See Rspec::Matchers
4
+ # See RSpec::Matchers
5
5
  def define(name, &declarations)
6
6
  define_method name do |*expected|
7
7
  $matcher_execution_context = self
8
- Rspec::Matchers::Matcher.new name, *expected, &declarations
8
+ RSpec::Matchers::Matcher.new name, *expected, &declarations
9
9
  end
10
10
  end
11
11
  end
12
12
  end
13
13
  end
14
14
 
15
- Rspec::Matchers.extend Rspec::Matchers::DSL
15
+ RSpec::Matchers.extend RSpec::Matchers::DSL
@@ -1,4 +1,4 @@
1
- module Rspec
1
+ module RSpec
2
2
  module Matchers
3
3
  # :call-seq:
4
4
  # should eq(expected)
@@ -1,4 +1,4 @@
1
- module Rspec
1
+ module RSpec
2
2
  module Matchers
3
3
  # :call-seq:
4
4
  # should eql(expected)
@@ -1,4 +1,4 @@
1
- module Rspec
1
+ module RSpec
2
2
  module Matchers
3
3
 
4
4
  # :call-seq:
@@ -1,4 +1,4 @@
1
- module Rspec
1
+ module RSpec
2
2
  module Matchers
3
3
  class MatcherError < StandardError; end
4
4
  end
@@ -1,4 +1,4 @@
1
- module Rspec
1
+ module RSpec
2
2
  module Matchers
3
3
  # :call-seq:
4
4
  # should exist
@@ -1,4 +1,4 @@
1
- module Rspec
1
+ module RSpec
2
2
  module Matchers
3
3
  module InstanceExec
4
4
  unless respond_to?(:instance_exec)
@@ -1,4 +1,4 @@
1
- module Rspec
1
+ module RSpec
2
2
  module Matchers
3
3
  class << self
4
4
  attr_accessor :last_matcher, :last_should # :nodoc:
@@ -1,4 +1,4 @@
1
- module Rspec
1
+ module RSpec
2
2
  module Matchers
3
3
 
4
4
  class Has
@@ -1,4 +1,4 @@
1
- module Rspec
1
+ module RSpec
2
2
  module Matchers
3
3
  class Have #:nodoc:
4
4
  def initialize(expected, relativity=:exactly)
@@ -1,4 +1,4 @@
1
- module Rspec
1
+ module RSpec
2
2
  module Matchers
3
3
  # :call-seq:
4
4
  # should include(expected)
@@ -1,4 +1,4 @@
1
- module Rspec
1
+ module RSpec
2
2
  module Matchers
3
3
  # :call-seq:
4
4
  # should match(pattern)
@@ -1,8 +1,8 @@
1
- module Rspec
1
+ module RSpec
2
2
  module Matchers
3
3
 
4
4
  class MatchArray #:nodoc:
5
- include Rspec::Matchers::Pretty
5
+ include RSpec::Matchers::Pretty
6
6
 
7
7
  def initialize(expected)
8
8
  @expected = expected
@@ -66,6 +66,6 @@ module Rspec
66
66
  # [1,2,3,4].should =~ [1,2,3] # => would fail
67
67
  # [1,2,2,3].should =~ [1,2,3] # => would fail
68
68
  # [1,2,3].should =~ [1,2,3,4] # => would fail
69
- OperatorMatcher.register(Array, '=~', Rspec::Matchers::MatchArray)
69
+ OperatorMatcher.register(Array, '=~', RSpec::Matchers::MatchArray)
70
70
  end
71
71
  end
@@ -1,9 +1,9 @@
1
- module Rspec
1
+ module RSpec
2
2
  module Matchers
3
3
  class Matcher
4
- include Rspec::Matchers::InstanceExec
5
- include Rspec::Matchers::Pretty
6
- include Rspec::Matchers
4
+ include RSpec::Matchers::InstanceExec
5
+ include RSpec::Matchers::Pretty
6
+ include RSpec::Matchers
7
7
 
8
8
  attr_reader :expected, :actual
9
9
  def initialize(name, *expected, &declarations)
@@ -35,34 +35,34 @@ module Rspec
35
35
  else
36
36
  begin
37
37
  instance_exec(actual, &@match_block)
38
- rescue Rspec::Expectations::ExpectationNotMetError
38
+ rescue RSpec::Expectations::ExpectationNotMetError
39
39
  false
40
40
  end
41
41
  end
42
42
  end
43
43
 
44
- # See Rspec::Matchers
44
+ # See RSpec::Matchers
45
45
  def match(&block)
46
46
  @match_block = block
47
47
  end
48
48
 
49
- # See Rspec::Matchers
49
+ # See RSpec::Matchers
50
50
  def match_unless_raises(exception=Exception, &block)
51
51
  @expected_exception = exception
52
52
  match(&block)
53
53
  end
54
54
 
55
- # See Rspec::Matchers
55
+ # See RSpec::Matchers
56
56
  def failure_message_for_should(&block)
57
57
  cache_or_call_cached(:failure_message_for_should, &block)
58
58
  end
59
59
 
60
- # See Rspec::Matchers
60
+ # See RSpec::Matchers
61
61
  def failure_message_for_should_not(&block)
62
62
  cache_or_call_cached(:failure_message_for_should_not, &block)
63
63
  end
64
64
 
65
- # See Rspec::Matchers
65
+ # See RSpec::Matchers
66
66
  def description(&block)
67
67
  cache_or_call_cached(:description, &block)
68
68
  end
@@ -72,12 +72,12 @@ module Rspec
72
72
  @diffable
73
73
  end
74
74
 
75
- # See Rspec::Matchers
75
+ # See RSpec::Matchers
76
76
  def diffable
77
77
  @diffable = true
78
78
  end
79
79
 
80
- # See Rspec::Matchers
80
+ # See RSpec::Matchers
81
81
  def chain(method, &block)
82
82
  self.class.class_eval do
83
83
  define_method method do |*args|
@@ -105,7 +105,7 @@ module Rspec
105
105
  #
106
106
  # Also, due some crazy scoping that I don't understand, these methods
107
107
  # are actually available in the specs (something about the matcher being
108
- # defined in the scope of Rspec::Matchers or within an example), so not
108
+ # defined in the scope of RSpec::Matchers or within an example), so not
109
109
  # doing the following will not cause specs to fail, but they *will*
110
110
  # cause features to fail and that will make users unhappy. So don't.
111
111
  orig_private_methods = private_methods