rspec 1.1.5 → 1.1.6
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/History.txt +12 -1
- data/Manifest.txt +3 -3
- data/Rakefile +0 -1
- data/TODO.txt +8 -0
- data/bin/autospec +0 -1
- data/examples/pure/autogenerated_docstrings_example.rb +4 -4
- data/lib/autotest/discover.rb +1 -1
- data/lib/spec/example/errors.rb +19 -4
- data/lib/spec/example/example_group.rb +8 -1
- data/lib/spec/example/example_group_methods.rb +26 -20
- data/lib/spec/example/example_methods.rb +2 -7
- data/lib/spec/matchers/be.rb +18 -18
- data/lib/spec/matchers/be_close.rb +5 -5
- data/lib/spec/matchers/eql.rb +6 -6
- data/lib/spec/matchers/equal.rb +6 -6
- data/lib/spec/matchers/exist.rb +10 -5
- data/lib/spec/matchers/has.rb +2 -2
- data/lib/spec/matchers/have.rb +8 -8
- data/lib/spec/matchers/include.rb +5 -5
- data/lib/spec/matchers/match.rb +9 -9
- data/lib/spec/matchers/operator_matcher.rb +17 -17
- data/lib/spec/matchers/raise_error.rb +17 -17
- data/lib/spec/matchers/respond_to.rb +5 -4
- data/lib/spec/matchers/satisfy.rb +5 -5
- data/lib/spec/matchers/simple_matcher.rb +8 -8
- data/lib/spec/matchers/throw_symbol.rb +3 -3
- data/lib/spec/mocks.rb +0 -11
- data/lib/spec/mocks/argument_constraints.rb +5 -25
- data/lib/spec/mocks/argument_expectation.rb +19 -41
- data/lib/spec/mocks/message_expectation.rb +1 -1
- data/lib/spec/story/runner.rb +1 -1
- data/lib/spec/version.rb +2 -2
- data/rspec.gemspec +6 -6
- data/spec/{autotest_helper.rb → autotest/autotest_helper.rb} +2 -2
- data/spec/{autotest_matchers.rb → autotest/autotest_matchers.rb} +0 -0
- data/spec/autotest/discover_spec.rb +1 -1
- data/spec/autotest/rspec_spec.rb +1 -1
- data/spec/rspec_suite.rb +0 -1
- data/spec/spec/example/example_methods_spec.rb +36 -3
- data/spec/spec/example/pending_module_spec.rb +76 -0
- data/spec/spec/matchers/respond_to_spec.rb +6 -6
- data/spec/spec/mocks/failing_mock_argument_constraints_spec.rb +0 -34
- data/spec/spec/mocks/mock_spec.rb +6 -0
- data/spec/spec/mocks/passing_mock_argument_constraints_spec.rb +0 -44
- data/spec/spec/runner/drb_command_line_spec.rb +1 -1
- data/spec/spec/{example → runner/formatter}/base_formatter_spec.rb +1 -1
- data/spec/spec/runner/option_parser_spec.rb +1 -1
- data/spec/spec/runner/reporter_spec.rb +1 -1
- data/spec/spec/story/runner/story_runner_spec.rb +3 -3
- data/spec/spec/story/world_spec.rb +7 -7
- metadata +7 -7
data/lib/spec/matchers/has.rb
CHANGED
data/lib/spec/matchers/have.rb
CHANGED
@@ -24,12 +24,12 @@ module Spec
|
|
24
24
|
else
|
25
25
|
collection_owner.__send__(@collection_name, *@args, &@block)
|
26
26
|
end
|
27
|
-
@
|
28
|
-
@
|
29
|
-
raise not_a_collection if @
|
30
|
-
return @
|
31
|
-
return @
|
32
|
-
return @
|
27
|
+
@given = collection.size if collection.respond_to?(:size)
|
28
|
+
@given = collection.length if collection.respond_to?(:length)
|
29
|
+
raise not_a_collection if @given.nil?
|
30
|
+
return @given >= @expected if @relativity == :at_least
|
31
|
+
return @given <= @expected if @relativity == :at_most
|
32
|
+
return @given == @expected
|
33
33
|
end
|
34
34
|
|
35
35
|
def not_a_collection
|
@@ -37,12 +37,12 @@ module Spec
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def failure_message
|
40
|
-
"expected #{relative_expectation} #{@collection_name}, got #{@
|
40
|
+
"expected #{relative_expectation} #{@collection_name}, got #{@given}"
|
41
41
|
end
|
42
42
|
|
43
43
|
def negative_failure_message
|
44
44
|
if @relativity == :exactly
|
45
|
-
return "expected target not to have #{@expected} #{@collection_name}, got #{@
|
45
|
+
return "expected target not to have #{@expected} #{@collection_name}, got #{@given}"
|
46
46
|
elsif @relativity == :at_most
|
47
47
|
return <<-EOF
|
48
48
|
Isn't life confusing enough?
|
@@ -7,10 +7,10 @@ module Spec
|
|
7
7
|
@expecteds = expecteds
|
8
8
|
end
|
9
9
|
|
10
|
-
def matches?(
|
11
|
-
@
|
10
|
+
def matches?(given)
|
11
|
+
@given = given
|
12
12
|
@expecteds.each do |expected|
|
13
|
-
return false unless
|
13
|
+
return false unless given.include?(expected)
|
14
14
|
end
|
15
15
|
true
|
16
16
|
end
|
@@ -29,7 +29,7 @@ module Spec
|
|
29
29
|
|
30
30
|
private
|
31
31
|
def _message(maybe_not="")
|
32
|
-
"expected #{@
|
32
|
+
"expected #{@given.inspect} #{maybe_not}to include #{_pretty_print(@expecteds)}"
|
33
33
|
end
|
34
34
|
|
35
35
|
def _pretty_print(array)
|
@@ -51,7 +51,7 @@ module Spec
|
|
51
51
|
# should include(expected)
|
52
52
|
# should_not include(expected)
|
53
53
|
#
|
54
|
-
# Passes if
|
54
|
+
# Passes if given includes expected. This works for
|
55
55
|
# collections and Strings. You can also pass in multiple args
|
56
56
|
# and it will only pass if all args are found in collection.
|
57
57
|
#
|
data/lib/spec/matchers/match.rb
CHANGED
@@ -2,26 +2,26 @@ module Spec
|
|
2
2
|
module Matchers
|
3
3
|
|
4
4
|
class Match #:nodoc:
|
5
|
-
def initialize(
|
6
|
-
@
|
5
|
+
def initialize(regexp)
|
6
|
+
@regexp = regexp
|
7
7
|
end
|
8
8
|
|
9
|
-
def matches?(
|
10
|
-
@
|
11
|
-
return true if
|
9
|
+
def matches?(given)
|
10
|
+
@given = given
|
11
|
+
return true if given =~ @regexp
|
12
12
|
return false
|
13
13
|
end
|
14
14
|
|
15
15
|
def failure_message
|
16
|
-
return "expected #{@
|
16
|
+
return "expected #{@given.inspect} to match #{@regexp.inspect}", @regexp, @given
|
17
17
|
end
|
18
18
|
|
19
19
|
def negative_failure_message
|
20
|
-
return "expected #{@
|
20
|
+
return "expected #{@given.inspect} not to match #{@regexp.inspect}", @regexp, @given
|
21
21
|
end
|
22
22
|
|
23
23
|
def description
|
24
|
-
"match #{@
|
24
|
+
"match #{@regexp.inspect}"
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -29,7 +29,7 @@ module Spec
|
|
29
29
|
# should match(regexp)
|
30
30
|
# should_not match(regexp)
|
31
31
|
#
|
32
|
-
# Given a Regexp, passes if
|
32
|
+
# Given a Regexp, passes if given =~ regexp
|
33
33
|
#
|
34
34
|
# == Examples
|
35
35
|
#
|
@@ -3,47 +3,47 @@ module Spec
|
|
3
3
|
class BaseOperatorMatcher
|
4
4
|
attr_reader :generated_description
|
5
5
|
|
6
|
-
def initialize(
|
7
|
-
@
|
6
|
+
def initialize(given)
|
7
|
+
@given = given
|
8
8
|
end
|
9
9
|
|
10
10
|
def ==(expected)
|
11
11
|
@expected = expected
|
12
|
-
|
12
|
+
__delegate_method_missing_to_given("==", expected)
|
13
13
|
end
|
14
14
|
|
15
15
|
def ===(expected)
|
16
16
|
@expected = expected
|
17
|
-
|
17
|
+
__delegate_method_missing_to_given("===", expected)
|
18
18
|
end
|
19
19
|
|
20
20
|
def =~(expected)
|
21
21
|
@expected = expected
|
22
|
-
|
22
|
+
__delegate_method_missing_to_given("=~", expected)
|
23
23
|
end
|
24
24
|
|
25
25
|
def >(expected)
|
26
26
|
@expected = expected
|
27
|
-
|
27
|
+
__delegate_method_missing_to_given(">", expected)
|
28
28
|
end
|
29
29
|
|
30
30
|
def >=(expected)
|
31
31
|
@expected = expected
|
32
|
-
|
32
|
+
__delegate_method_missing_to_given(">=", expected)
|
33
33
|
end
|
34
34
|
|
35
35
|
def <(expected)
|
36
36
|
@expected = expected
|
37
|
-
|
37
|
+
__delegate_method_missing_to_given("<", expected)
|
38
38
|
end
|
39
39
|
|
40
40
|
def <=(expected)
|
41
41
|
@expected = expected
|
42
|
-
|
42
|
+
__delegate_method_missing_to_given("<=", expected)
|
43
43
|
end
|
44
44
|
|
45
45
|
def fail_with_message(message)
|
46
|
-
Spec::Expectations.fail_with(message, @expected, @
|
46
|
+
Spec::Expectations.fail_with(message, @expected, @given)
|
47
47
|
end
|
48
48
|
|
49
49
|
def description
|
@@ -54,23 +54,23 @@ module Spec
|
|
54
54
|
|
55
55
|
class PositiveOperatorMatcher < BaseOperatorMatcher #:nodoc:
|
56
56
|
|
57
|
-
def
|
57
|
+
def __delegate_method_missing_to_given(operator, expected)
|
58
58
|
@operator = operator
|
59
59
|
::Spec::Matchers.last_matcher = self
|
60
|
-
return true if @
|
61
|
-
return fail_with_message("expected: #{expected.inspect},\n got: #{@
|
62
|
-
return fail_with_message("expected: #{operator} #{expected.inspect},\n got: #{operator.gsub(/./, ' ')} #{@
|
60
|
+
return true if @given.__send__(operator, expected)
|
61
|
+
return fail_with_message("expected: #{expected.inspect},\n got: #{@given.inspect} (using #{operator})") if ['==','===', '=~'].include?(operator)
|
62
|
+
return fail_with_message("expected: #{operator} #{expected.inspect},\n got: #{operator.gsub(/./, ' ')} #{@given.inspect}")
|
63
63
|
end
|
64
64
|
|
65
65
|
end
|
66
66
|
|
67
67
|
class NegativeOperatorMatcher < BaseOperatorMatcher #:nodoc:
|
68
68
|
|
69
|
-
def
|
69
|
+
def __delegate_method_missing_to_given(operator, expected)
|
70
70
|
@operator = operator
|
71
71
|
::Spec::Matchers.last_matcher = self
|
72
|
-
return true unless @
|
73
|
-
return fail_with_message("expected not: #{operator} #{expected.inspect},\n got: #{operator.gsub(/./, ' ')} #{@
|
72
|
+
return true unless @given.__send__(operator, expected)
|
73
|
+
return fail_with_message("expected not: #{operator} #{expected.inspect},\n got: #{operator.gsub(/./, ' ')} #{@given.inspect}")
|
74
74
|
end
|
75
75
|
|
76
76
|
end
|
@@ -1,27 +1,27 @@
|
|
1
1
|
module Spec
|
2
2
|
module Matchers
|
3
3
|
class RaiseError #:nodoc:
|
4
|
-
def initialize(
|
4
|
+
def initialize(expected_error_or_message=Exception, expected_message=nil, &block)
|
5
5
|
@block = block
|
6
|
-
case
|
6
|
+
case expected_error_or_message
|
7
7
|
when String, Regexp
|
8
|
-
@expected_error, @expected_message = Exception,
|
8
|
+
@expected_error, @expected_message = Exception, expected_error_or_message
|
9
9
|
else
|
10
|
-
@expected_error, @expected_message =
|
10
|
+
@expected_error, @expected_message = expected_error_or_message, expected_message
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
def matches?(
|
14
|
+
def matches?(given_proc)
|
15
15
|
@raised_expected_error = false
|
16
16
|
@with_expected_message = false
|
17
17
|
@eval_block = false
|
18
18
|
@eval_block_passed = false
|
19
19
|
begin
|
20
|
-
|
21
|
-
rescue @expected_error => @
|
20
|
+
given_proc.call
|
21
|
+
rescue @expected_error => @given_error
|
22
22
|
@raised_expected_error = true
|
23
23
|
@with_expected_message = verify_message
|
24
|
-
rescue Exception => @
|
24
|
+
rescue Exception => @given_error
|
25
25
|
# This clause should be empty, but rcov will not report it as covered
|
26
26
|
# unless something (anything) is executed within the clause
|
27
27
|
rcov_error_report = "http://eigenclass.org/hiki.rb?rcov-0.8.0"
|
@@ -37,10 +37,10 @@ module Spec
|
|
37
37
|
def eval_block
|
38
38
|
@eval_block = true
|
39
39
|
begin
|
40
|
-
@block[@
|
40
|
+
@block[@given_error]
|
41
41
|
@eval_block_passed = true
|
42
42
|
rescue Exception => err
|
43
|
-
@
|
43
|
+
@given_error = err
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -49,22 +49,22 @@ module Spec
|
|
49
49
|
when nil
|
50
50
|
return true
|
51
51
|
when Regexp
|
52
|
-
return @expected_message =~ @
|
52
|
+
return @expected_message =~ @given_error.message
|
53
53
|
else
|
54
|
-
return @expected_message == @
|
54
|
+
return @expected_message == @given_error.message
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
58
|
def failure_message
|
59
59
|
if @eval_block
|
60
|
-
return @
|
60
|
+
return @given_error.message
|
61
61
|
else
|
62
|
-
return "expected #{expected_error}#{
|
62
|
+
return "expected #{expected_error}#{given_error}"
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
66
|
def negative_failure_message
|
67
|
-
"expected no #{expected_error}#{
|
67
|
+
"expected no #{expected_error}#{given_error}"
|
68
68
|
end
|
69
69
|
|
70
70
|
def description
|
@@ -83,8 +83,8 @@ module Spec
|
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
|
-
def
|
87
|
-
@
|
86
|
+
def given_error
|
87
|
+
@given_error.nil? ? " but nothing was raised" : ", got #{@given_error.inspect}"
|
88
88
|
end
|
89
89
|
|
90
90
|
def negative_expectation?
|
@@ -7,9 +7,10 @@ module Spec
|
|
7
7
|
@names_not_responded_to = []
|
8
8
|
end
|
9
9
|
|
10
|
-
def matches?(
|
10
|
+
def matches?(given)
|
11
|
+
@given = given
|
11
12
|
@names.each do |name|
|
12
|
-
unless
|
13
|
+
unless given.respond_to?(name)
|
13
14
|
@names_not_responded_to << name
|
14
15
|
end
|
15
16
|
end
|
@@ -17,11 +18,11 @@ module Spec
|
|
17
18
|
end
|
18
19
|
|
19
20
|
def failure_message
|
20
|
-
"expected
|
21
|
+
"expected #{@given.inspect} to respond to #{@names_not_responded_to.collect {|name| name.inspect }.join(', ')}"
|
21
22
|
end
|
22
23
|
|
23
24
|
def negative_failure_message
|
24
|
-
"expected
|
25
|
+
"expected #{@given.inspect} not to respond to #{@names.collect {|name| name.inspect }.join(', ')}"
|
25
26
|
end
|
26
27
|
|
27
28
|
def description
|
@@ -6,18 +6,18 @@ module Spec
|
|
6
6
|
@block = block
|
7
7
|
end
|
8
8
|
|
9
|
-
def matches?(
|
9
|
+
def matches?(given, &block)
|
10
10
|
@block = block if block
|
11
|
-
@
|
12
|
-
@block.call(
|
11
|
+
@given = given
|
12
|
+
@block.call(given)
|
13
13
|
end
|
14
14
|
|
15
15
|
def failure_message
|
16
|
-
"expected #{@
|
16
|
+
"expected #{@given} to satisfy block"
|
17
17
|
end
|
18
18
|
|
19
19
|
def negative_failure_message
|
20
|
-
"expected #{@
|
20
|
+
"expected #{@given} not to satisfy block"
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -8,13 +8,13 @@ module Spec
|
|
8
8
|
@match_block = match_block
|
9
9
|
end
|
10
10
|
|
11
|
-
def matches?(
|
12
|
-
@
|
11
|
+
def matches?(given)
|
12
|
+
@given = given
|
13
13
|
case @match_block.arity
|
14
14
|
when 2
|
15
|
-
@match_block.call(@
|
15
|
+
@match_block.call(@given, self)
|
16
16
|
else
|
17
|
-
@match_block.call(@
|
17
|
+
@match_block.call(@given)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -23,11 +23,11 @@ module Spec
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def failure_message
|
26
|
-
@failure_message || (@description.nil? ? explanation : %[expected #{@description.inspect} but got #{@
|
26
|
+
@failure_message || (@description.nil? ? explanation : %[expected #{@description.inspect} but got #{@given.inspect}])
|
27
27
|
end
|
28
28
|
|
29
29
|
def negative_failure_message
|
30
|
-
@negative_failure_message || (@description.nil? ? explanation : %[expected not to get #{@description.inspect}, but got #{@
|
30
|
+
@negative_failure_message || (@description.nil? ? explanation : %[expected not to get #{@description.inspect}, but got #{@given.inspect}])
|
31
31
|
end
|
32
32
|
|
33
33
|
def explanation
|
@@ -81,7 +81,7 @@ module Spec
|
|
81
81
|
# simple_matcher("rhyme with #{expected.inspect}") do |given, matcher|
|
82
82
|
# matcher.failure_message = "expected #{given.inspect} to rhyme with #{expected.inspect}"
|
83
83
|
# matcher.negative_failure_message = "expected #{given.inspect} not to rhyme with #{expected.inspect}"
|
84
|
-
#
|
84
|
+
# given.rhymes_with? expected
|
85
85
|
# end
|
86
86
|
# end
|
87
87
|
#
|
@@ -92,7 +92,7 @@ module Spec
|
|
92
92
|
# matcher.description = "rhyme with #{expected.inspect}"
|
93
93
|
# matcher.failure_message = "expected #{given.inspect} to rhyme with #{expected.inspect}"
|
94
94
|
# matcher.negative_failure_message = "expected #{given.inspect} not to rhyme with #{expected.inspect}"
|
95
|
-
#
|
95
|
+
# given.rhymes_with? expected
|
96
96
|
# end
|
97
97
|
# end
|
98
98
|
#
|
@@ -7,9 +7,9 @@ module Spec
|
|
7
7
|
@actual = nil
|
8
8
|
end
|
9
9
|
|
10
|
-
def matches?(
|
10
|
+
def matches?(given_proc)
|
11
11
|
begin
|
12
|
-
|
12
|
+
given_proc.call
|
13
13
|
rescue NameError => e
|
14
14
|
raise e unless e.message =~ /uncaught throw/
|
15
15
|
@actual = e.name.to_sym
|
@@ -56,7 +56,7 @@ module Spec
|
|
56
56
|
# should_not throw_symbol()
|
57
57
|
# should_not throw_symbol(:sym)
|
58
58
|
#
|
59
|
-
# Given a Symbol argument, matches if
|
59
|
+
# Given a Symbol argument, matches if the given proc throws the specified Symbol.
|
60
60
|
#
|
61
61
|
# Given no argument, matches if a proc throws any Symbol.
|
62
62
|
#
|
data/lib/spec/mocks.rb
CHANGED
@@ -1,16 +1,5 @@
|
|
1
1
|
require 'spec/mocks/framework'
|
2
|
-
require 'spec/mocks/methods'
|
3
|
-
require 'spec/mocks/argument_constraints'
|
4
|
-
require 'spec/mocks/spec_methods'
|
5
|
-
require 'spec/mocks/proxy'
|
6
|
-
require 'spec/mocks/mock'
|
7
|
-
require 'spec/mocks/argument_expectation'
|
8
|
-
require 'spec/mocks/message_expectation'
|
9
|
-
require 'spec/mocks/order_group'
|
10
|
-
require 'spec/mocks/errors'
|
11
|
-
require 'spec/mocks/error_generator'
|
12
2
|
require 'spec/mocks/extensions/object'
|
13
|
-
require 'spec/mocks/space'
|
14
3
|
|
15
4
|
module Spec
|
16
5
|
# == Mocks and Stubs
|
@@ -34,7 +34,7 @@ module Spec
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
class
|
37
|
+
class RegexpConstraint
|
38
38
|
def initialize(regexp)
|
39
39
|
@regexp = regexp
|
40
40
|
end
|
@@ -45,7 +45,7 @@ module Spec
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
class
|
48
|
+
class BooleanConstraint
|
49
49
|
def initialize(ignore)
|
50
50
|
end
|
51
51
|
|
@@ -73,7 +73,7 @@ module Spec
|
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
|
-
class
|
76
|
+
class DuckTypeConstraint
|
77
77
|
def initialize(*methods_to_respond_to)
|
78
78
|
@methods_to_respond_to = methods_to_respond_to
|
79
79
|
end
|
@@ -103,26 +103,6 @@ module Spec
|
|
103
103
|
end
|
104
104
|
end
|
105
105
|
|
106
|
-
module Deprecated
|
107
|
-
class NumericArgConstraint
|
108
|
-
def initialize(ignore)
|
109
|
-
end
|
110
|
-
|
111
|
-
def ==(value)
|
112
|
-
value.is_a?(Numeric)
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
class StringArgConstraint
|
117
|
-
def initialize(ignore)
|
118
|
-
end
|
119
|
-
|
120
|
-
def ==(value)
|
121
|
-
String === value
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
106
|
# :call-seq:
|
127
107
|
# object.should_receive(:message).with(any_args())
|
128
108
|
#
|
@@ -161,7 +141,7 @@ module Spec
|
|
161
141
|
# display.should_receive(:present_names).with(duck_type(:length, :each))
|
162
142
|
# => passes
|
163
143
|
def duck_type(*args)
|
164
|
-
|
144
|
+
DuckTypeConstraint.new(*args)
|
165
145
|
end
|
166
146
|
|
167
147
|
# :call-seq:
|
@@ -169,7 +149,7 @@ module Spec
|
|
169
149
|
#
|
170
150
|
# Passes if the argument is boolean.
|
171
151
|
def boolean
|
172
|
-
|
152
|
+
BooleanConstraint.new(nil)
|
173
153
|
end
|
174
154
|
|
175
155
|
# :call-seq:
|