rspec-expectations 2.0.0.beta.8 → 2.0.0.beta.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.markdown +1 -1
- data/Rakefile +8 -7
- data/Upgrade.markdown +6 -6
- data/VERSION +1 -1
- data/features/expectations/customized_message.feature +1 -1
- data/features/expectations/implicit_docstrings.feature +2 -2
- data/features/matchers/access_running_example.feature +5 -5
- data/features/matchers/define_diffable_matcher.feature +2 -2
- data/features/matchers/define_matcher.feature +14 -14
- data/features/matchers/define_matcher_outside_rspec.feature +2 -2
- data/features/matchers/define_matcher_with_fluent_interface.feature +2 -2
- data/features/matchers/expect_change.feature +2 -2
- data/features/matchers/expect_error.feature +2 -2
- data/lib/rspec/expectations.rb +7 -5
- data/lib/rspec/expectations/backward_compatibility.rb +16 -0
- data/lib/rspec/expectations/differ.rb +58 -0
- data/lib/rspec/expectations/errors.rb +1 -1
- data/lib/rspec/expectations/extensions/kernel.rb +4 -4
- data/lib/rspec/expectations/extensions/rspec/core/example_group.rb +1 -1
- data/lib/rspec/expectations/fail_with.rb +6 -4
- data/lib/rspec/expectations/handler.rb +11 -11
- data/lib/rspec/expectations/version.rb +1 -1
- data/lib/rspec/matchers.rb +7 -8
- data/lib/rspec/matchers/be.rb +6 -6
- data/lib/rspec/matchers/be_close.rb +1 -1
- data/lib/rspec/matchers/be_instance_of.rb +1 -1
- data/lib/rspec/matchers/be_kind_of.rb +1 -1
- data/lib/rspec/matchers/change.rb +1 -1
- data/lib/rspec/matchers/compatibility.rb +2 -2
- data/lib/rspec/matchers/dsl.rb +4 -4
- data/lib/rspec/matchers/eq.rb +1 -1
- data/lib/rspec/matchers/eql.rb +1 -1
- data/lib/rspec/matchers/equal.rb +1 -1
- data/lib/rspec/matchers/errors.rb +1 -1
- data/lib/rspec/matchers/exist.rb +1 -1
- data/lib/rspec/matchers/extensions/instance_exec.rb +1 -1
- data/lib/rspec/matchers/generated_descriptions.rb +1 -1
- data/lib/rspec/matchers/has.rb +1 -1
- data/lib/rspec/matchers/have.rb +1 -1
- data/lib/rspec/matchers/include.rb +1 -1
- data/lib/rspec/matchers/match.rb +1 -1
- data/lib/rspec/matchers/match_array.rb +3 -3
- data/lib/rspec/matchers/matcher.rb +13 -13
- data/lib/rspec/matchers/method_missing.rb +1 -1
- data/lib/rspec/matchers/operator_matcher.rb +4 -4
- data/lib/rspec/matchers/pretty.rb +1 -1
- data/lib/rspec/matchers/raise_error.rb +1 -1
- data/lib/rspec/matchers/respond_to.rb +1 -1
- data/lib/rspec/matchers/satisfy.rb +1 -1
- data/lib/rspec/matchers/throw_symbol.rb +1 -1
- data/rspec-expectations.gemspec +17 -14
- data/spec/rspec/expectations/{differs/default_spec.rb → differ_spec.rb} +4 -36
- data/spec/rspec/expectations/fail_with_spec.rb +6 -50
- data/spec/rspec/expectations/handler_spec.rb +22 -22
- data/spec/rspec/matchers/be_close_spec.rb +1 -1
- data/spec/rspec/matchers/be_instance_of_spec.rb +1 -1
- data/spec/rspec/matchers/be_kind_of_spec.rb +1 -1
- data/spec/rspec/matchers/change_spec.rb +3 -3
- data/spec/rspec/matchers/compatibility_spec.rb +3 -3
- data/spec/rspec/matchers/description_generation_spec.rb +28 -28
- data/spec/rspec/matchers/dsl_spec.rb +3 -3
- data/spec/rspec/matchers/eq_spec.rb +1 -1
- data/spec/rspec/matchers/eql_spec.rb +1 -1
- data/spec/rspec/matchers/equal_spec.rb +1 -1
- data/spec/rspec/matchers/exist_spec.rb +1 -1
- data/spec/rspec/matchers/have_spec.rb +3 -3
- data/spec/rspec/matchers/match_array_spec.rb +3 -0
- data/spec/rspec/matchers/matcher_spec.rb +25 -25
- data/spec/rspec/matchers/operator_matcher_spec.rb +12 -12
- data/spec/rspec/matchers/throw_symbol_spec.rb +1 -1
- data/spec/spec_helper.rb +6 -7
- data/spec/support/classes.rb +1 -1
- metadata +35 -21
- data/lib/rspec/expectations/differs/default.rb +0 -62
- data/lib/rspec/expectations/differs/load-diff-lcs.rb +0 -7
@@ -17,14 +17,14 @@ module Kernel
|
|
17
17
|
# receiver.should =~ regexp
|
18
18
|
# => Passes if (receiver =~ regexp)
|
19
19
|
#
|
20
|
-
# See
|
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
|
-
|
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
|
48
|
+
# See RSpec::Matchers for more information about matchers
|
49
49
|
def should_not(matcher=nil, message=nil, &block)
|
50
|
-
|
50
|
+
RSpec::Expectations::NegativeExpectationHandler.handle_matcher(self, matcher, message, &block)
|
51
51
|
end
|
52
52
|
end
|
@@ -1,9 +1,11 @@
|
|
1
|
-
module
|
1
|
+
module RSpec
|
2
2
|
module Expectations
|
3
3
|
class << self
|
4
|
-
|
4
|
+
def differ
|
5
|
+
@differ ||= Differ.new
|
6
|
+
end
|
5
7
|
|
6
|
-
# raises a
|
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(
|
25
|
+
Kernel::raise(RSpec::Expectations::ExpectationNotMetError.new(message))
|
24
26
|
end
|
25
27
|
end
|
26
28
|
end
|
@@ -1,12 +1,12 @@
|
|
1
|
-
module
|
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
|
-
::
|
8
|
-
::
|
9
|
-
return ::
|
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
|
-
::
|
19
|
+
::RSpec::Expectations.fail_with message, matcher.expected.first, matcher.actual
|
20
20
|
else
|
21
|
-
::
|
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
|
-
::
|
29
|
-
::
|
30
|
-
return ::
|
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
|
-
::
|
42
|
+
::RSpec::Expectations.fail_with message, matcher.expected.first, matcher.actual
|
43
43
|
else
|
44
|
-
::
|
44
|
+
::RSpec::Expectations.fail_with message
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
data/lib/rspec/matchers.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
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
|
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
|
-
#
|
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
|
-
#
|
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
|
-
#
|
160
|
+
# RSpec::Runner.configure do |config|
|
161
161
|
# config.include(CustomGameMatchers)
|
162
162
|
# end
|
163
163
|
#
|
164
164
|
module Matchers
|
165
|
-
if
|
166
|
-
|
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
|
-
|
data/lib/rspec/matchers/be.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
require 'rspec/matchers/dsl'
|
2
2
|
|
3
|
-
|
3
|
+
RSpec::Matchers.define :be_true do
|
4
4
|
match do |actual|
|
5
5
|
!!actual
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
9
|
-
|
9
|
+
RSpec::Matchers.define :be_false do
|
10
10
|
match do |actual|
|
11
11
|
!actual
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
|
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
|
29
|
+
module RSpec
|
30
30
|
module Matchers
|
31
31
|
|
32
32
|
class Be #:nodoc:
|
33
|
-
include
|
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 "?"),
|
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,5 +1,5 @@
|
|
1
|
-
|
2
|
-
if Class === (klass =
|
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
|
data/lib/rspec/matchers/dsl.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
module
|
1
|
+
module RSpec
|
2
2
|
module Matchers
|
3
3
|
module DSL
|
4
|
-
# See
|
4
|
+
# See RSpec::Matchers
|
5
5
|
def define(name, &declarations)
|
6
6
|
define_method name do |*expected|
|
7
7
|
$matcher_execution_context = self
|
8
|
-
|
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
|
-
|
15
|
+
RSpec::Matchers.extend RSpec::Matchers::DSL
|
data/lib/rspec/matchers/eq.rb
CHANGED
data/lib/rspec/matchers/eql.rb
CHANGED
data/lib/rspec/matchers/equal.rb
CHANGED
data/lib/rspec/matchers/exist.rb
CHANGED
data/lib/rspec/matchers/has.rb
CHANGED
data/lib/rspec/matchers/have.rb
CHANGED
data/lib/rspec/matchers/match.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
module
|
1
|
+
module RSpec
|
2
2
|
module Matchers
|
3
3
|
|
4
4
|
class MatchArray #:nodoc:
|
5
|
-
include
|
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, '=~',
|
69
|
+
OperatorMatcher.register(Array, '=~', RSpec::Matchers::MatchArray)
|
70
70
|
end
|
71
71
|
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
module
|
1
|
+
module RSpec
|
2
2
|
module Matchers
|
3
3
|
class Matcher
|
4
|
-
include
|
5
|
-
include
|
6
|
-
include
|
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
|
38
|
+
rescue RSpec::Expectations::ExpectationNotMetError
|
39
39
|
false
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
# See
|
44
|
+
# See RSpec::Matchers
|
45
45
|
def match(&block)
|
46
46
|
@match_block = block
|
47
47
|
end
|
48
48
|
|
49
|
-
# See
|
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
|
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
|
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
|
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
|
75
|
+
# See RSpec::Matchers
|
76
76
|
def diffable
|
77
77
|
@diffable = true
|
78
78
|
end
|
79
79
|
|
80
|
-
# See
|
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
|
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
|