rspec 1.1.4 → 1.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/{CHANGES → History.txt} +116 -64
- data/Manifest.txt +403 -0
- data/{MIT-LICENSE → README.txt} +43 -0
- data/Rakefile +39 -212
- data/{TODO → TODO.txt} +0 -0
- data/bin/autospec +4 -0
- data/bin/spec +1 -1
- data/examples/pure/yielding_example.rb +33 -0
- data/examples/stories/game-of-life/.loadpath +5 -0
- data/examples/stories/game-of-life/behaviour/everything.rb +1 -1
- data/examples/stories/game-of-life/behaviour/stories/CellsWithMoreThanThreeNeighboursDie.story +17 -17
- data/init.rb +9 -0
- data/lib/autotest/discover.rb +1 -1
- data/lib/autotest/rspec.rb +3 -29
- data/lib/spec.rb +10 -12
- data/lib/spec/adapters.rb +1 -0
- data/lib/spec/adapters/ruby_engine.rb +26 -0
- data/lib/spec/adapters/ruby_engine/mri.rb +8 -0
- data/lib/spec/adapters/ruby_engine/rubinius.rb +8 -0
- data/lib/spec/example/errors.rb +6 -0
- data/lib/spec/example/example_group_methods.rb +17 -14
- data/lib/spec/example/example_matcher.rb +2 -0
- data/lib/spec/example/example_methods.rb +4 -9
- data/lib/spec/example/module_inclusion_warnings.rb +2 -1
- data/lib/spec/expectations/extensions/object.rb +2 -2
- data/lib/spec/expectations/handler.rb +8 -16
- data/lib/spec/extensions/main.rb +2 -17
- data/lib/spec/matchers.rb +8 -2
- data/lib/spec/matchers/be.rb +0 -3
- data/lib/spec/matchers/change.rb +44 -40
- data/lib/spec/matchers/has.rb +1 -1
- data/lib/spec/matchers/have.rb +17 -12
- data/lib/spec/matchers/operator_matcher.rb +10 -4
- data/lib/spec/matchers/simple_matcher.rb +113 -10
- data/lib/spec/mocks.rb +1 -1
- data/lib/spec/mocks/argument_constraints.rb +185 -0
- data/lib/spec/mocks/argument_expectation.rb +35 -173
- data/lib/spec/mocks/framework.rb +1 -1
- data/lib/spec/mocks/message_expectation.rb +30 -5
- data/lib/spec/mocks/methods.rb +14 -2
- data/lib/spec/mocks/mock.rb +4 -0
- data/lib/spec/mocks/proxy.rb +46 -5
- data/lib/spec/mocks/spec_methods.rb +9 -1
- data/lib/spec/rake/spectask.rb +14 -22
- data/lib/spec/rake/verify_rcov.rb +3 -3
- data/lib/spec/runner.rb +18 -6
- data/lib/spec/runner/backtrace_tweaker.rb +6 -7
- data/lib/spec/runner/command_line.rb +6 -17
- data/lib/spec/runner/drb_command_line.rb +1 -1
- data/lib/spec/runner/formatter/base_formatter.rb +3 -1
- data/lib/spec/runner/formatter/base_text_formatter.rb +5 -9
- data/lib/spec/runner/formatter/html_formatter.rb +1 -1
- data/lib/spec/runner/formatter/nested_text_formatter.rb +1 -1
- data/lib/spec/runner/formatter/progress_bar_formatter.rb +2 -2
- data/lib/spec/runner/formatter/specdoc_formatter.rb +1 -1
- data/lib/spec/runner/formatter/story/html_formatter.rb +62 -16
- data/lib/spec/runner/formatter/story/plain_text_formatter.rb +68 -16
- data/lib/spec/runner/formatter/story/progress_bar_formatter.rb +42 -0
- data/lib/spec/runner/heckle_runner.rb +2 -2
- data/lib/spec/runner/option_parser.rb +2 -1
- data/lib/spec/runner/options.rb +18 -9
- data/lib/spec/runner/reporter.rb +24 -4
- data/lib/spec/runner/spec_parser.rb +1 -1
- data/lib/spec/story/runner.rb +1 -2
- data/lib/spec/story/runner/story_mediator.rb +14 -0
- data/lib/spec/story/runner/story_parser.rb +20 -0
- data/lib/spec/story/step.rb +40 -28
- data/lib/spec/story/step_mother.rb +2 -1
- data/lib/spec/story/world.rb +6 -2
- data/lib/spec/version.rb +13 -22
- data/rake_tasks/failing_examples_with_html.rake +1 -1
- data/rake_tasks/verify_rcov.rake +2 -2
- data/rspec.gemspec +33 -0
- data/spec/autotest/rspec_spec.rb +90 -141
- data/spec/spec/adapters/ruby_engine_spec.rb +16 -0
- data/spec/spec/example/base_formatter_spec.rb +112 -0
- data/spec/spec/example/example_group_factory_spec.rb +2 -2
- data/spec/spec/example/example_group_methods_spec.rb +55 -4
- data/spec/spec/example/example_group_spec.rb +4 -3
- data/spec/spec/example/example_methods_spec.rb +18 -14
- data/spec/spec/example/pending_module_spec.rb +38 -0
- data/spec/spec/example/shared_example_group_spec.rb +1 -1
- data/spec/spec/expectations/extensions/object_spec.rb +0 -12
- data/spec/spec/extensions/main_spec.rb +3 -8
- data/spec/spec/matchers/change_spec.rb +16 -6
- data/spec/spec/matchers/handler_spec.rb +58 -37
- data/spec/spec/matchers/has_spec.rb +10 -0
- data/spec/spec/matchers/have_spec.rb +105 -2
- data/spec/spec/matchers/operator_matcher_spec.rb +35 -2
- data/spec/spec/matchers/simple_matcher_spec.rb +64 -2
- data/spec/spec/mocks/any_number_of_times_spec.rb +7 -0
- data/spec/spec/mocks/bug_report_496.rb +17 -0
- data/spec/spec/mocks/failing_mock_argument_constraints_spec.rb +7 -1
- data/spec/spec/mocks/hash_including_matcher_spec.rb +45 -24
- data/spec/spec/mocks/mock_spec.rb +55 -10
- data/spec/spec/mocks/nil_expectation_warning_spec.rb +54 -0
- data/spec/spec/mocks/null_object_mock_spec.rb +14 -0
- data/spec/spec/mocks/options_hash_spec.rb +18 -28
- data/spec/spec/mocks/partial_mock_spec.rb +2 -0
- data/spec/spec/mocks/passing_mock_argument_constraints_spec.rb +20 -6
- data/spec/spec/mocks/stub_spec.rb +7 -0
- data/spec/spec/runner/command_line_spec.rb +5 -12
- data/spec/spec/runner/drb_command_line_spec.rb +13 -6
- data/spec/spec/runner/formatter/html_formatter_spec.rb +2 -1
- data/spec/spec/runner/formatter/nested_text_formatter_spec.rb +3 -3
- data/spec/spec/runner/formatter/progress_bar_formatter_spec.rb +20 -2
- data/spec/spec/runner/formatter/spec_mate_formatter_spec.rb +2 -1
- data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +3 -3
- data/spec/spec/runner/formatter/story/html_formatter_spec.rb +76 -2
- data/spec/spec/runner/formatter/story/plain_text_formatter_spec.rb +161 -0
- data/spec/spec/runner/formatter/story/progress_bar_formatter_spec.rb +82 -0
- data/spec/spec/runner/heckle_runner_spec.rb +8 -8
- data/spec/spec/runner/option_parser_spec.rb +21 -6
- data/spec/spec/runner/output_one_time_fixture_runner.rb +1 -1
- data/spec/spec/runner/quiet_backtrace_tweaker_spec.rb +6 -0
- data/spec/spec/runner/reporter_spec.rb +51 -5
- data/spec/spec/runner/spec_parser_spec.rb +4 -4
- data/spec/spec/story/runner/plain_text_story_runner_spec.rb +2 -5
- data/spec/spec/story/runner/story_mediator_spec.rb +10 -0
- data/spec/spec/story/runner/story_parser_spec.rb +23 -6
- data/spec/spec/story/scenario_spec.rb +1 -3
- data/spec/spec/story/step_mother_spec.rb +12 -0
- data/spec/spec/story/step_spec.rb +57 -4
- data/spec/spec/story/story_spec.rb +1 -3
- data/spec/spec/story/world_spec.rb +1 -1
- data/spec/spec_helper.rb +21 -68
- data/stories/all.rb +1 -1
- data/stories/configuration/before_blocks.story +21 -0
- data/stories/configuration/stories.rb +7 -0
- data/stories/example_groups/stories.rb +3 -4
- data/stories/resources/spec/before_blocks_example.rb +32 -0
- data/stories/stories/multiline_steps.story +23 -0
- data/stories/stories/steps/multiline_steps.rb +13 -0
- data/stories/stories/stories.rb +6 -0
- data/story_server/prototype/javascripts/builder.js +136 -0
- data/story_server/prototype/javascripts/controls.js +972 -0
- data/story_server/prototype/javascripts/dragdrop.js +976 -0
- data/story_server/prototype/javascripts/effects.js +1117 -0
- data/story_server/prototype/javascripts/prototype.js +4140 -0
- data/story_server/prototype/javascripts/rspec.js +149 -0
- data/story_server/prototype/javascripts/scriptaculous.js +58 -0
- data/story_server/prototype/javascripts/slider.js +276 -0
- data/story_server/prototype/javascripts/sound.js +55 -0
- data/story_server/prototype/javascripts/unittest.js +568 -0
- data/story_server/prototype/lib/server.rb +24 -0
- data/story_server/prototype/stories.html +176 -0
- data/story_server/prototype/stylesheets/rspec.css +136 -0
- data/story_server/prototype/stylesheets/test.css +90 -0
- metadata +166 -166
- data/README +0 -36
- data/UPGRADE +0 -7
- data/bin/spec_translator +0 -8
- data/lib/spec/mocks/argument_constraint_matchers.rb +0 -31
- data/lib/spec/translator.rb +0 -114
- data/spec/spec/example/example_spec.rb +0 -53
- data/spec/spec/runner/execution_context_spec.rb +0 -37
- data/spec/spec/translator_spec.rb +0 -265
data/lib/spec/mocks.rb
CHANGED
@@ -0,0 +1,185 @@
|
|
1
|
+
module Spec
|
2
|
+
module Mocks
|
3
|
+
|
4
|
+
# ArgumentConstraints are messages that you can include in message
|
5
|
+
# expectations to match arguments against a broader check than simple
|
6
|
+
# equality.
|
7
|
+
#
|
8
|
+
# With the exception of any_args() and no_args(), the constraints
|
9
|
+
# are all positional - they match against the arg in the given position.
|
10
|
+
module ArgumentConstraints
|
11
|
+
|
12
|
+
class AnyArgsConstraint
|
13
|
+
def description
|
14
|
+
"any args"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class AnyArgConstraint
|
19
|
+
def initialize(ignore)
|
20
|
+
end
|
21
|
+
|
22
|
+
def ==(other)
|
23
|
+
true
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class NoArgsConstraint
|
28
|
+
def description
|
29
|
+
"no args"
|
30
|
+
end
|
31
|
+
|
32
|
+
def ==(args)
|
33
|
+
args == []
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class RegexpArgConstraint
|
38
|
+
def initialize(regexp)
|
39
|
+
@regexp = regexp
|
40
|
+
end
|
41
|
+
|
42
|
+
def ==(value)
|
43
|
+
return value =~ @regexp unless value.is_a?(Regexp)
|
44
|
+
value == @regexp
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class BooleanArgConstraint
|
49
|
+
def initialize(ignore)
|
50
|
+
end
|
51
|
+
|
52
|
+
def ==(value)
|
53
|
+
TrueClass === value || FalseClass === value
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
class HashIncludingConstraint
|
58
|
+
def initialize(expected)
|
59
|
+
@expected = expected
|
60
|
+
end
|
61
|
+
|
62
|
+
def ==(actual)
|
63
|
+
@expected.each do | key, value |
|
64
|
+
return false unless actual.has_key?(key) && value == actual[key]
|
65
|
+
end
|
66
|
+
true
|
67
|
+
rescue NoMethodError => ex
|
68
|
+
return false
|
69
|
+
end
|
70
|
+
|
71
|
+
def description
|
72
|
+
"hash_including(#{@expected.inspect.sub(/^\{/,"").sub(/\}$/,"")})"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
class DuckTypeArgConstraint
|
77
|
+
def initialize(*methods_to_respond_to)
|
78
|
+
@methods_to_respond_to = methods_to_respond_to
|
79
|
+
end
|
80
|
+
|
81
|
+
def ==(value)
|
82
|
+
@methods_to_respond_to.all? { |sym| value.respond_to?(sym) }
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
class MatcherConstraint
|
87
|
+
def initialize(matcher)
|
88
|
+
@matcher = matcher
|
89
|
+
end
|
90
|
+
|
91
|
+
def ==(value)
|
92
|
+
@matcher.matches?(value)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
class EqualityProxy
|
97
|
+
def initialize(given)
|
98
|
+
@given = given
|
99
|
+
end
|
100
|
+
|
101
|
+
def ==(expected)
|
102
|
+
@given == expected
|
103
|
+
end
|
104
|
+
end
|
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
|
+
# :call-seq:
|
127
|
+
# object.should_receive(:message).with(any_args())
|
128
|
+
#
|
129
|
+
# Passes if object receives :message with any args at all. This is
|
130
|
+
# really a more explicit variation of object.should_receive(:message)
|
131
|
+
def any_args
|
132
|
+
AnyArgsConstraint.new
|
133
|
+
end
|
134
|
+
|
135
|
+
# :call-seq:
|
136
|
+
# object.should_receive(:message).with(anything())
|
137
|
+
#
|
138
|
+
# Passes as long as there is an argument.
|
139
|
+
def anything
|
140
|
+
AnyArgConstraint.new(nil)
|
141
|
+
end
|
142
|
+
|
143
|
+
# :call-seq:
|
144
|
+
# object.should_receive(:message).with(no_args)
|
145
|
+
#
|
146
|
+
# Passes if no arguments are passed along with the message
|
147
|
+
def no_args
|
148
|
+
NoArgsConstraint.new
|
149
|
+
end
|
150
|
+
|
151
|
+
# :call-seq:
|
152
|
+
# object.should_receive(:message).with(duck_type(:hello))
|
153
|
+
# object.should_receive(:message).with(duck_type(:hello, :goodbye))
|
154
|
+
#
|
155
|
+
# Passes if the argument responds to the specified messages.
|
156
|
+
#
|
157
|
+
# == Examples
|
158
|
+
#
|
159
|
+
# array = []
|
160
|
+
# display = mock('display')
|
161
|
+
# display.should_receive(:present_names).with(duck_type(:length, :each))
|
162
|
+
# => passes
|
163
|
+
def duck_type(*args)
|
164
|
+
DuckTypeArgConstraint.new(*args)
|
165
|
+
end
|
166
|
+
|
167
|
+
# :call-seq:
|
168
|
+
# object.should_receive(:message).with(boolean())
|
169
|
+
#
|
170
|
+
# Passes if the argument is boolean.
|
171
|
+
def boolean
|
172
|
+
BooleanArgConstraint.new(nil)
|
173
|
+
end
|
174
|
+
|
175
|
+
# :call-seq:
|
176
|
+
# object.should_receive(:message).with(hash_including(:this => that))
|
177
|
+
#
|
178
|
+
# Passes if the argument is a hash that includes the specified key/value
|
179
|
+
# pairs. If the hash includes other keys, it will still pass.
|
180
|
+
def hash_including(expected={})
|
181
|
+
HashIncludingConstraint.new(expected)
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
@@ -1,175 +1,40 @@
|
|
1
1
|
module Spec
|
2
2
|
module Mocks
|
3
|
-
|
4
|
-
class MatcherConstraint
|
5
|
-
def initialize(matcher)
|
6
|
-
@matcher = matcher
|
7
|
-
end
|
8
|
-
|
9
|
-
def matches?(value)
|
10
|
-
@matcher.matches?(value)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
class LiteralArgConstraint
|
15
|
-
def initialize(literal)
|
16
|
-
@literal_value = literal
|
17
|
-
end
|
18
|
-
|
19
|
-
def matches?(value)
|
20
|
-
@literal_value == value
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
class RegexpArgConstraint
|
25
|
-
def initialize(regexp)
|
26
|
-
@regexp = regexp
|
27
|
-
end
|
28
|
-
|
29
|
-
def matches?(value)
|
30
|
-
return value =~ @regexp unless value.is_a?(Regexp)
|
31
|
-
value == @regexp
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
class AnyArgConstraint
|
36
|
-
def initialize(ignore)
|
37
|
-
end
|
38
|
-
|
39
|
-
def ==(other)
|
40
|
-
true
|
41
|
-
end
|
42
|
-
|
43
|
-
# TODO - need this?
|
44
|
-
def matches?(value)
|
45
|
-
true
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
class AnyArgsConstraint
|
50
|
-
def description
|
51
|
-
"any args"
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
class NoArgsConstraint
|
56
|
-
def description
|
57
|
-
"no args"
|
58
|
-
end
|
59
|
-
|
60
|
-
def ==(args)
|
61
|
-
args == []
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
class NumericArgConstraint
|
66
|
-
def initialize(ignore)
|
67
|
-
end
|
68
|
-
|
69
|
-
def matches?(value)
|
70
|
-
value.is_a?(Numeric)
|
71
|
-
end
|
72
|
-
end
|
73
3
|
|
74
|
-
class BooleanArgConstraint
|
75
|
-
def initialize(ignore)
|
76
|
-
end
|
77
|
-
|
78
|
-
def ==(value)
|
79
|
-
matches?(value)
|
80
|
-
end
|
81
|
-
|
82
|
-
def matches?(value)
|
83
|
-
return true if value.is_a?(TrueClass)
|
84
|
-
return true if value.is_a?(FalseClass)
|
85
|
-
false
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
class StringArgConstraint
|
90
|
-
def initialize(ignore)
|
91
|
-
end
|
92
|
-
|
93
|
-
def matches?(value)
|
94
|
-
value.is_a?(String)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
class DuckTypeArgConstraint
|
99
|
-
def initialize(*methods_to_respond_to)
|
100
|
-
@methods_to_respond_to = methods_to_respond_to
|
101
|
-
end
|
102
|
-
|
103
|
-
def matches?(value)
|
104
|
-
@methods_to_respond_to.all? { |sym| value.respond_to?(sym) }
|
105
|
-
end
|
106
|
-
|
107
|
-
def description
|
108
|
-
"duck_type"
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
class HashIncludingConstraint
|
113
|
-
def initialize(expected)
|
114
|
-
@expected = expected
|
115
|
-
end
|
116
|
-
|
117
|
-
def ==(actual)
|
118
|
-
@expected.each do | key, value |
|
119
|
-
# check key for case that value evaluates to nil
|
120
|
-
return false unless actual.has_key?(key) && actual[key] == value
|
121
|
-
end
|
122
|
-
true
|
123
|
-
rescue NoMethodError => ex
|
124
|
-
return false
|
125
|
-
end
|
126
|
-
|
127
|
-
def matches?(value)
|
128
|
-
self == value
|
129
|
-
end
|
130
|
-
|
131
|
-
def description
|
132
|
-
"hash_including(#{@expected.inspect.sub(/^\{/,"").sub(/\}$/,"")})"
|
133
|
-
end
|
134
|
-
|
135
|
-
end
|
136
|
-
|
137
|
-
|
138
4
|
class ArgumentExpectation
|
139
5
|
attr_reader :args
|
140
|
-
@@constraint_classes = Hash.new
|
141
|
-
@@constraint_classes[:anything] = AnyArgConstraint
|
142
|
-
@@constraint_classes[:
|
143
|
-
@@constraint_classes[:
|
144
|
-
@@constraint_classes[:string] = StringArgConstraint
|
6
|
+
@@constraint_classes = Hash.new
|
7
|
+
@@constraint_classes[:anything] = ArgumentConstraints::AnyArgConstraint
|
8
|
+
@@constraint_classes[:boolean] = ArgumentConstraints::BooleanArgConstraint
|
9
|
+
@@constraint_classes[:numeric] = ArgumentConstraints::Deprecated::NumericArgConstraint
|
10
|
+
@@constraint_classes[:string] = ArgumentConstraints::Deprecated::StringArgConstraint
|
145
11
|
|
146
|
-
def initialize(args)
|
12
|
+
def initialize(args, &block)
|
147
13
|
@args = args
|
14
|
+
@constraints_block = block
|
15
|
+
|
148
16
|
if [:any_args] == args
|
149
|
-
@
|
150
|
-
|
151
|
-
elsif
|
17
|
+
@expected_args = nil
|
18
|
+
warn_constraint_symbol_deprecated(:any_args.inspect, "any_args()")
|
19
|
+
elsif ArgumentConstraints::AnyArgsConstraint === args.first
|
20
|
+
@expected_args = nil
|
152
21
|
elsif [:no_args] == args
|
153
|
-
@
|
154
|
-
|
155
|
-
elsif
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
def process_arg_constraints(constraints)
|
161
|
-
constraints.collect do |constraint|
|
162
|
-
convert_constraint(constraint)
|
22
|
+
@expected_args = []
|
23
|
+
warn_constraint_symbol_deprecated(:no_args.inspect, "no_args()")
|
24
|
+
elsif ArgumentConstraints::NoArgsConstraint === args.first
|
25
|
+
@expected_args = []
|
26
|
+
else
|
27
|
+
@expected_args = args.collect {|arg| constraint_for(arg)}
|
163
28
|
end
|
164
29
|
end
|
165
30
|
|
166
|
-
def
|
167
|
-
Kernel.warn "The #{deprecated_method} constraint is deprecated. Use #{instead} instead."
|
31
|
+
def warn_constraint_symbol_deprecated(deprecated_method, instead)
|
32
|
+
Kernel.warn "The #{deprecated_method} constraint is deprecated and will be removed after RSpec 1.1.5. Use #{instead} instead."
|
168
33
|
end
|
169
34
|
|
170
|
-
def
|
171
|
-
if [:anything, :numeric, :boolean, :string].include?(
|
172
|
-
case
|
35
|
+
def constraint_for(arg)
|
36
|
+
if [:anything, :numeric, :boolean, :string].include?(arg)
|
37
|
+
case arg
|
173
38
|
when :anything
|
174
39
|
instead = "anything()"
|
175
40
|
when :boolean
|
@@ -179,30 +44,27 @@ module Spec
|
|
179
44
|
when :string
|
180
45
|
instead = "an_instance_of(String)"
|
181
46
|
end
|
182
|
-
|
183
|
-
return @@constraint_classes[
|
47
|
+
warn_constraint_symbol_deprecated(arg.inspect, instead)
|
48
|
+
return @@constraint_classes[arg].new(arg)
|
184
49
|
end
|
185
|
-
return MatcherConstraint.new(
|
186
|
-
return RegexpArgConstraint.new(
|
187
|
-
return
|
50
|
+
return ArgumentConstraints::MatcherConstraint.new(arg) if is_matcher?(arg)
|
51
|
+
return ArgumentConstraints::RegexpArgConstraint.new(arg) if arg.is_a?(Regexp)
|
52
|
+
return ArgumentConstraints::EqualityProxy.new(arg)
|
188
53
|
end
|
189
54
|
|
190
55
|
def is_matcher?(obj)
|
191
56
|
return obj.respond_to?(:matches?) && obj.respond_to?(:description)
|
192
57
|
end
|
193
58
|
|
194
|
-
def
|
195
|
-
|
196
|
-
|
197
|
-
|
59
|
+
def args_match?(given_args)
|
60
|
+
if @constraints_block
|
61
|
+
@constraints_block.call(*given_args)
|
62
|
+
return true
|
63
|
+
end
|
64
|
+
|
65
|
+
@expected_args.nil? || @expected_args == given_args
|
198
66
|
end
|
199
67
|
|
200
|
-
def constraints_match?(args)
|
201
|
-
return false if args.length != @expected_params.length
|
202
|
-
@expected_params.each_index { |i| return false unless @expected_params[i].matches?(args[i]) }
|
203
|
-
return true
|
204
|
-
end
|
205
|
-
|
206
68
|
end
|
207
69
|
|
208
70
|
end
|
data/lib/spec/mocks/framework.rb
CHANGED
@@ -3,6 +3,10 @@ module Spec
|
|
3
3
|
|
4
4
|
class BaseExpectation
|
5
5
|
attr_reader :sym
|
6
|
+
attr_writer :expected_received_count, :method_block, :expected_from, :args_to_yield
|
7
|
+
protected :expected_received_count=, :method_block=, :expected_from=, :args_to_yield=
|
8
|
+
attr_accessor :error_generator
|
9
|
+
protected :error_generator, :error_generator=
|
6
10
|
|
7
11
|
def initialize(error_generator, expectation_ordering, expected_from, sym, method_block, expected_received_count=1, opts={})
|
8
12
|
@error_generator = error_generator
|
@@ -13,7 +17,7 @@ module Spec
|
|
13
17
|
@return_block = nil
|
14
18
|
@actual_received_count = 0
|
15
19
|
@expected_received_count = expected_received_count
|
16
|
-
@args_expectation = ArgumentExpectation.new([AnyArgsConstraint.new])
|
20
|
+
@args_expectation = ArgumentExpectation.new([ArgumentConstraints::AnyArgsConstraint.new])
|
17
21
|
@consecutive = false
|
18
22
|
@exception_to_raise = nil
|
19
23
|
@symbol_to_throw = nil
|
@@ -23,6 +27,23 @@ module Spec
|
|
23
27
|
@args_to_yield = []
|
24
28
|
end
|
25
29
|
|
30
|
+
def build_child(expected_from, method_block, expected_received_count, opts={})
|
31
|
+
child = clone
|
32
|
+
child.expected_from = expected_from
|
33
|
+
child.method_block = method_block
|
34
|
+
child.expected_received_count = expected_received_count
|
35
|
+
new_gen = error_generator.clone
|
36
|
+
new_gen.opts = opts
|
37
|
+
child.error_generator = new_gen
|
38
|
+
child.args_to_yield = @args_to_yield.clone
|
39
|
+
child
|
40
|
+
end
|
41
|
+
|
42
|
+
def error_generator_opts=(opts={})
|
43
|
+
@error_generator.opts = opts
|
44
|
+
end
|
45
|
+
protected :error_generator_opts=
|
46
|
+
|
26
47
|
def expected_args
|
27
48
|
@args_expectation.args
|
28
49
|
end
|
@@ -68,7 +89,7 @@ module Spec
|
|
68
89
|
end
|
69
90
|
|
70
91
|
def matches(sym, args)
|
71
|
-
@sym == sym and @args_expectation.
|
92
|
+
@sym == sym and @args_expectation.args_match?(args)
|
72
93
|
end
|
73
94
|
|
74
95
|
def invoke(args, block)
|
@@ -103,6 +124,11 @@ module Spec
|
|
103
124
|
@actual_received_count += 1
|
104
125
|
end
|
105
126
|
end
|
127
|
+
|
128
|
+
def called_max_times?
|
129
|
+
@expected_received_count != :any &&
|
130
|
+
@actual_received_count >= @expected_received_count
|
131
|
+
end
|
106
132
|
|
107
133
|
protected
|
108
134
|
|
@@ -152,7 +178,7 @@ module Spec
|
|
152
178
|
class MessageExpectation < BaseExpectation
|
153
179
|
|
154
180
|
def matches_name_but_not_args(sym, args)
|
155
|
-
@sym == sym and not @args_expectation.
|
181
|
+
@sym == sym and not @args_expectation.args_match?(args)
|
156
182
|
end
|
157
183
|
|
158
184
|
def verify_messages_received
|
@@ -202,8 +228,7 @@ module Spec
|
|
202
228
|
end
|
203
229
|
|
204
230
|
def with(*args, &block)
|
205
|
-
@
|
206
|
-
@args_expectation = ArgumentExpectation.new(args)
|
231
|
+
@args_expectation = ArgumentExpectation.new(args, &block)
|
207
232
|
self
|
208
233
|
end
|
209
234
|
|