rspec 1.1.3 → 1.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +35 -0
- data/MIT-LICENSE +1 -1
- data/README +9 -44
- data/Rakefile +34 -51
- data/TODO +0 -1
- data/UPGRADE +0 -24
- data/bin/spec +0 -0
- data/bin/spec_translator +0 -0
- data/examples/pure/behave_as_example.rb +0 -0
- data/examples/pure/partial_mock_example.rb +1 -0
- data/examples/stories/calculator.rb +1 -1
- data/lib/autotest/rspec.rb +7 -9
- data/lib/spec/example.rb +1 -1
- data/lib/spec/example/configuration.rb +30 -16
- data/lib/spec/example/example_group.rb +2 -1
- data/lib/spec/example/example_group_factory.rb +23 -21
- data/lib/spec/example/example_group_methods.rb +18 -5
- data/lib/spec/example/example_matcher.rb +0 -0
- data/lib/spec/example/example_methods.rb +6 -0
- data/lib/spec/example/module_inclusion_warnings.rb +37 -0
- data/lib/spec/expectations/differs/default.rb +1 -1
- data/lib/spec/expectations/extensions/object.rb +4 -12
- data/lib/spec/expectations/handler.rb +8 -0
- data/lib/spec/extensions.rb +1 -0
- data/lib/spec/extensions/metaclass.rb +7 -0
- data/lib/spec/extensions/object.rb +0 -4
- data/lib/spec/matchers/change.rb +1 -1
- data/lib/spec/matchers/has.rb +1 -11
- data/lib/spec/matchers/operator_matcher.rb +0 -0
- data/lib/spec/matchers/raise_error.rb +53 -30
- data/lib/spec/mocks.rb +1 -1
- data/lib/spec/mocks/argument_constraint_matchers.rb +5 -1
- data/lib/spec/mocks/argument_expectation.rb +26 -0
- data/lib/spec/mocks/extensions.rb +1 -0
- data/lib/spec/mocks/framework.rb +15 -0
- data/lib/spec/mocks/message_expectation.rb +29 -5
- data/lib/spec/mocks/mock.rb +9 -7
- data/lib/spec/mocks/proxy.rb +26 -12
- data/lib/spec/rake/spectask.rb +5 -5
- data/lib/spec/runner/backtrace_tweaker.rb +1 -1
- data/lib/spec/runner/formatter/base_formatter.rb +2 -3
- data/lib/spec/runner/formatter/base_text_formatter.rb +2 -2
- data/lib/spec/runner/formatter/failing_example_groups_formatter.rb +4 -8
- data/lib/spec/runner/formatter/html_formatter.rb +18 -14
- data/lib/spec/runner/formatter/nested_text_formatter.rb +65 -0
- data/lib/spec/runner/formatter/profile_formatter.rb +4 -0
- data/lib/spec/runner/formatter/progress_bar_formatter.rb +5 -1
- data/lib/spec/runner/formatter/specdoc_formatter.rb +1 -1
- data/lib/spec/runner/formatter/story/plain_text_formatter.rb +18 -7
- data/lib/spec/runner/option_parser.rb +17 -15
- data/lib/spec/runner/options.rb +37 -14
- data/lib/spec/runner/reporter.rb +15 -11
- data/lib/spec/story/extensions/regexp.rb +2 -2
- data/lib/spec/story/extensions/string.rb +2 -2
- data/lib/spec/story/runner.rb +9 -5
- data/lib/spec/story/runner/plain_text_story_runner.rb +2 -2
- data/lib/spec/story/runner/scenario_runner.rb +8 -0
- data/lib/spec/story/runner/story_mediator.rb +1 -1
- data/lib/spec/story/runner/story_runner.rb +3 -1
- data/lib/spec/story/step.rb +4 -4
- data/lib/spec/story/story.rb +8 -11
- data/lib/spec/story/world.rb +0 -1
- data/lib/spec/version.rb +2 -2
- data/plugins/mock_frameworks/rspec.rb +2 -0
- data/spec/autotest/rspec_spec.rb +12 -10
- data/spec/spec/example/configuration_spec.rb +0 -0
- data/spec/spec/example/example_group/described_module_spec.rb +20 -0
- data/spec/spec/example/example_group/warning_messages_spec.rb +76 -0
- data/spec/spec/example/example_group_factory_spec.rb +117 -102
- data/spec/spec/example/example_group_methods_spec.rb +51 -17
- data/spec/spec/example/example_group_spec.rb +13 -1
- data/spec/spec/example/example_methods_spec.rb +28 -6
- data/spec/spec/example/nested_example_group_spec.rb +12 -0
- data/spec/spec/example/predicate_matcher_spec.rb +0 -0
- data/spec/spec/expectations/differs/default_spec.rb +27 -9
- data/spec/spec/matchers/be_spec.rb +24 -0
- data/spec/spec/matchers/has_spec.rb +16 -0
- data/spec/spec/matchers/raise_error_spec.rb +124 -0
- data/spec/spec/mocks/{bug_report_10263.rb → bug_report_10263_spec.rb} +0 -0
- data/spec/spec/mocks/bug_report_11545_spec.rb +2 -0
- data/spec/spec/mocks/failing_mock_argument_constraints_spec.rb +8 -0
- data/spec/spec/mocks/hash_including_matcher_spec.rb +32 -0
- data/spec/spec/mocks/mock_spec.rb +56 -37
- data/spec/spec/mocks/partial_mock_spec.rb +41 -5
- data/spec/spec/mocks/passing_mock_argument_constraints_spec.rb +6 -0
- data/spec/spec/runner/execution_context_spec.rb +7 -1
- data/spec/spec/runner/formatter/failing_example_groups_formatter_spec.rb +3 -2
- data/spec/spec/runner/formatter/html_formatted-1.8.6.html +30 -25
- data/spec/spec/runner/formatter/html_formatter_spec.rb +0 -3
- data/spec/spec/runner/formatter/nested_text_formatter_spec.rb +333 -0
- data/spec/spec/runner/formatter/progress_bar_formatter_spec.rb +12 -2
- data/spec/spec/runner/formatter/spec_mate_formatter_spec.rb +2 -2
- data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +110 -78
- data/spec/spec/runner/formatter/story/plain_text_formatter_spec.rb +105 -1
- data/spec/spec/runner/formatter/text_mate_formatted-1.8.6.html +33 -28
- data/spec/spec/runner/option_parser_spec.rb +65 -49
- data/spec/spec/runner/options_spec.rb +103 -17
- data/spec/spec/runner/reporter_spec.rb +10 -7
- data/spec/spec/runner/spec_drb.opts +1 -0
- data/spec/spec/runner/spec_parser_spec.rb +10 -4
- data/spec/spec/story/runner/plain_text_story_runner_spec.rb +14 -13
- data/spec/spec/story/runner/scenario_runner_spec.rb +124 -52
- data/spec/spec/story/runner/story_mediator_spec.rb +2 -2
- data/spec/spec/story/runner/story_runner_spec.rb +40 -2
- data/spec/spec/story/runner_spec.rb +59 -72
- data/spec/spec/story/step_spec.rb +20 -1
- data/spec/spec/story/story_spec.rb +2 -2
- data/stories/all.rb +1 -1
- data/stories/example_groups/stories.rb +4 -3
- data/stories/mock_framework_integration/stories.rb +7 -0
- data/stories/mock_framework_integration/use_flexmock.story +9 -0
- data/stories/resources/spec/spec_with_flexmock.rb +18 -0
- metadata +21 -18
- data/pre_commit/lib/pre_commit.rb +0 -4
- data/pre_commit/lib/pre_commit/core.rb +0 -50
- data/pre_commit/lib/pre_commit/pre_commit.rb +0 -54
- data/pre_commit/lib/pre_commit/rspec.rb +0 -111
- data/pre_commit/lib/pre_commit/rspec_on_rails.rb +0 -313
- data/pre_commit/spec/pre_commit/pre_commit_spec.rb +0 -15
- data/pre_commit/spec/pre_commit/rspec_on_rails_spec.rb +0 -36
- data/pre_commit/spec/spec_helper.rb +0 -3
- data/pre_commit/spec/spec_suite.rb +0 -11
@@ -1,6 +1,7 @@
|
|
1
1
|
module Spec
|
2
2
|
module Example
|
3
|
-
#
|
3
|
+
# Base class for customized example groups. Use this if you
|
4
|
+
# want to make a custom example group.
|
4
5
|
class ExampleGroup
|
5
6
|
extend Spec::Example::ExampleGroupMethods
|
6
7
|
include Spec::Example::ExampleMethods
|
@@ -7,52 +7,54 @@ module Spec
|
|
7
7
|
default(ExampleGroup)
|
8
8
|
end
|
9
9
|
|
10
|
-
# Registers an example group class +klass+ with the symbol
|
11
|
-
#
|
10
|
+
# Registers an example group class +klass+ with the symbol +type+. For
|
11
|
+
# example:
|
12
12
|
#
|
13
|
-
# Spec::Example::ExampleGroupFactory.register(:farm,
|
13
|
+
# Spec::Example::ExampleGroupFactory.register(:farm, FarmExampleGroup)
|
14
14
|
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
|
19
|
-
|
15
|
+
# With that you can append a hash with :type => :farm to the describe
|
16
|
+
# method and it will load an instance of FarmExampleGroup.
|
17
|
+
#
|
18
|
+
# describe Pig, :type => :farm do
|
19
|
+
# ...
|
20
|
+
#
|
21
|
+
# If you don't use the hash explicitly, <tt>describe</tt> will
|
22
|
+
# implicitly use an instance of FarmExampleGroup for any file loaded
|
23
|
+
# from the <tt>./spec/farm</tt> directory.
|
24
|
+
def register(key, example_group_class)
|
25
|
+
@example_group_types[key] = example_group_class
|
20
26
|
end
|
21
27
|
|
22
28
|
# Sets the default ExampleGroup class
|
23
29
|
def default(example_group_class)
|
24
30
|
old = @example_group_types
|
25
31
|
@example_group_types = Hash.new(example_group_class)
|
26
|
-
@example_group_types.merge(old) if old
|
32
|
+
@example_group_types.merge!(old) if old
|
27
33
|
end
|
28
34
|
|
29
|
-
def get(
|
30
|
-
if @example_group_types.values.include?(
|
31
|
-
|
35
|
+
def get(key=nil)
|
36
|
+
if @example_group_types.values.include?(key)
|
37
|
+
key
|
32
38
|
else
|
33
|
-
@example_group_types[
|
39
|
+
@example_group_types[key]
|
34
40
|
end
|
35
41
|
end
|
36
42
|
|
37
43
|
def create_example_group(*args, &block)
|
38
44
|
opts = Hash === args.last ? args.last : {}
|
39
|
-
|
40
|
-
|
41
|
-
else
|
42
|
-
superclass = determine_superclass(opts)
|
43
|
-
superclass.describe(*args, &block)
|
44
|
-
end
|
45
|
+
superclass = determine_superclass(opts)
|
46
|
+
superclass.describe(*args, &block)
|
45
47
|
end
|
46
48
|
|
47
49
|
protected
|
48
50
|
|
49
51
|
def determine_superclass(opts)
|
50
|
-
|
52
|
+
key = if opts[:type]
|
51
53
|
opts[:type]
|
52
54
|
elsif opts[:spec_path] =~ /spec(\\|\/)(#{@example_group_types.keys.join('|')})/
|
53
55
|
$2 == '' ? nil : $2.to_sym
|
54
56
|
end
|
55
|
-
get(
|
57
|
+
get(key)
|
56
58
|
end
|
57
59
|
|
58
60
|
end
|
@@ -34,10 +34,17 @@ module Spec
|
|
34
34
|
# end
|
35
35
|
#
|
36
36
|
def describe(*args, &example_group_block)
|
37
|
+
args << {} unless Hash === args.last
|
37
38
|
if example_group_block
|
38
|
-
|
39
|
-
|
40
|
-
|
39
|
+
params = args.last
|
40
|
+
params[:spec_path] = eval("caller(0)[1]", example_group_block) unless params[:spec_path]
|
41
|
+
if params[:shared]
|
42
|
+
SharedExampleGroup.new(*args, &example_group_block)
|
43
|
+
else
|
44
|
+
self.subclass("Subclass") do
|
45
|
+
describe(*args)
|
46
|
+
module_eval(&example_group_block)
|
47
|
+
end
|
41
48
|
end
|
42
49
|
else
|
43
50
|
set_description(*args)
|
@@ -45,6 +52,7 @@ module Spec
|
|
45
52
|
self
|
46
53
|
end
|
47
54
|
end
|
55
|
+
alias :context :describe
|
48
56
|
|
49
57
|
# Use this to pull in examples from shared example groups.
|
50
58
|
# See Spec::Runner for information about shared example groups.
|
@@ -107,11 +115,12 @@ module Spec
|
|
107
115
|
def xit(description=nil, opts={}, &block)
|
108
116
|
Kernel.warn("Example disabled: #{description}")
|
109
117
|
end
|
118
|
+
alias_method :xspecify, :xit
|
110
119
|
|
111
120
|
def run
|
112
121
|
examples = examples_to_run
|
113
|
-
return true if examples.empty?
|
114
122
|
reporter.add_example_group(self)
|
123
|
+
return true if examples.empty?
|
115
124
|
return dry_run(examples) if dry_run?
|
116
125
|
|
117
126
|
plugin_mock_framework
|
@@ -150,10 +159,12 @@ module Spec
|
|
150
159
|
@description_text = ExampleGroupMethods.description_text(*args)
|
151
160
|
@spec_path = File.expand_path(options[:spec_path]) if options[:spec_path]
|
152
161
|
if described_type.class == Module
|
153
|
-
|
162
|
+
@described_module = described_type
|
154
163
|
end
|
155
164
|
self
|
156
165
|
end
|
166
|
+
|
167
|
+
attr_reader :described_module
|
157
168
|
|
158
169
|
def examples #:nodoc:
|
159
170
|
examples = example_objects.dup
|
@@ -384,6 +395,7 @@ module Spec
|
|
384
395
|
case scope
|
385
396
|
when :each; before_each_parts
|
386
397
|
when :all; before_all_parts
|
398
|
+
when :suite; rspec_options.before_suite_parts
|
387
399
|
end
|
388
400
|
end
|
389
401
|
|
@@ -391,6 +403,7 @@ module Spec
|
|
391
403
|
case scope
|
392
404
|
when :each; after_each_parts
|
393
405
|
when :all; after_all_parts
|
406
|
+
when :suite; rspec_options.after_suite_parts
|
394
407
|
end
|
395
408
|
end
|
396
409
|
|
File without changes
|
@@ -3,6 +3,8 @@ module Spec
|
|
3
3
|
module ExampleMethods
|
4
4
|
extend ExampleGroupMethods
|
5
5
|
extend ModuleReopeningFix
|
6
|
+
include ModuleInclusionWarnings
|
7
|
+
|
6
8
|
|
7
9
|
PENDING_EXAMPLE_BLOCK = lambda {
|
8
10
|
raise Spec::Example::ExamplePendingError.new("Not Yet Implemented")
|
@@ -63,6 +65,10 @@ module Spec
|
|
63
65
|
def description
|
64
66
|
@_defined_description || @_matcher_description || "NO NAME"
|
65
67
|
end
|
68
|
+
|
69
|
+
def __full_description
|
70
|
+
"#{self.class.description} #{self.description}"
|
71
|
+
end
|
66
72
|
|
67
73
|
def set_instance_variables_from_hash(ivars)
|
68
74
|
ivars.each do |variable_name, value|
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Spec
|
2
|
+
module Example
|
3
|
+
# In the future, modules will no longer be automatically included
|
4
|
+
# in the Example Group (based on the description name); when that
|
5
|
+
# time comes, this code should be removed.
|
6
|
+
module ModuleInclusionWarnings
|
7
|
+
# Thanks, Francis Hwang.
|
8
|
+
class MethodDispatcher
|
9
|
+
def initialize(mod, target=nil)
|
10
|
+
@mod = mod
|
11
|
+
@target = target
|
12
|
+
end
|
13
|
+
|
14
|
+
def respond_to?(sym)
|
15
|
+
@mod && @mod.instance_methods.include?(sym.to_s)
|
16
|
+
end
|
17
|
+
|
18
|
+
def call(sym, *args, &blk)
|
19
|
+
Kernel.warn("Modules will no longer be automatically included in RSpec version 1.1.4. Called from #{caller[2]}")
|
20
|
+
@target.extend @mod
|
21
|
+
@target.send(sym, *args, &blk)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def respond_to?(sym)
|
26
|
+
MethodDispatcher.new(self.class.described_module).respond_to?(sym) ? true : super
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def method_missing(sym, *args, &blk)
|
32
|
+
md = MethodDispatcher.new(self.class.described_module, self)
|
33
|
+
self.respond_to?(sym) ? md.call(sym, *args, &blk) : super
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -17,7 +17,7 @@ module Spec
|
|
17
17
|
end
|
18
18
|
|
19
19
|
# This is snagged from diff/lcs/ldiff.rb (which is a commandline tool)
|
20
|
-
def diff_as_string(
|
20
|
+
def diff_as_string(data_new, data_old)
|
21
21
|
data_old = data_old.split(/\n/).map! { |e| e.chomp }
|
22
22
|
data_new = data_new.split(/\n/).map! { |e| e.chomp }
|
23
23
|
output = ""
|
@@ -27,12 +27,8 @@ module Spec
|
|
27
27
|
#
|
28
28
|
# NOTE that this does NOT support receiver.should != expected.
|
29
29
|
# Instead, use receiver.should_not == expected
|
30
|
-
def should(matcher
|
31
|
-
|
32
|
-
Spec::Matchers::PositiveOperatorMatcher.new(self)
|
33
|
-
else
|
34
|
-
ExpectationMatcherHandler.handle_matcher(self, matcher, &block)
|
35
|
-
end
|
30
|
+
def should(matcher=:use_operator_matcher, &block)
|
31
|
+
ExpectationMatcherHandler.handle_matcher(self, matcher, &block)
|
36
32
|
end
|
37
33
|
|
38
34
|
# :call-seq:
|
@@ -54,12 +50,8 @@ module Spec
|
|
54
50
|
# => Passes unless (receiver =~ regexp)
|
55
51
|
#
|
56
52
|
# See Spec::Matchers for more information about matchers
|
57
|
-
def should_not(matcher
|
58
|
-
|
59
|
-
Spec::Matchers::NegativeOperatorMatcher.new(self)
|
60
|
-
else
|
61
|
-
NegativeExpectationMatcherHandler.handle_matcher(self, matcher, &block)
|
62
|
-
end
|
53
|
+
def should_not(matcher=:use_operator_matcher, &block)
|
54
|
+
NegativeExpectationMatcherHandler.handle_matcher(self, matcher, &block)
|
63
55
|
end
|
64
56
|
|
65
57
|
end
|
@@ -12,6 +12,10 @@ module Spec
|
|
12
12
|
class << self
|
13
13
|
include MatcherHandlerHelper
|
14
14
|
def handle_matcher(actual, matcher, &block)
|
15
|
+
if :use_operator_matcher == matcher
|
16
|
+
return Spec::Matchers::PositiveOperatorMatcher.new(actual)
|
17
|
+
end
|
18
|
+
|
15
19
|
unless matcher.respond_to?(:matches?)
|
16
20
|
raise InvalidMatcherError, "Expected a matcher, got #{matcher.inspect}."
|
17
21
|
end
|
@@ -27,6 +31,10 @@ module Spec
|
|
27
31
|
class << self
|
28
32
|
include MatcherHandlerHelper
|
29
33
|
def handle_matcher(actual, matcher, &block)
|
34
|
+
if :use_operator_matcher == matcher
|
35
|
+
return Spec::Matchers::NegativeOperatorMatcher.new(actual)
|
36
|
+
end
|
37
|
+
|
30
38
|
unless matcher.respond_to?(:matches?)
|
31
39
|
raise InvalidMatcherError, "Expected a matcher, got #{matcher.inspect}."
|
32
40
|
end
|
data/lib/spec/extensions.rb
CHANGED
data/lib/spec/matchers/change.rb
CHANGED
data/lib/spec/matchers/has.rb
CHANGED
@@ -8,24 +8,14 @@ module Spec
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def matches?(target)
|
11
|
-
|
12
|
-
begin
|
13
|
-
return target.send(predicate, *@args)
|
14
|
-
rescue => @error
|
15
|
-
# This clause should be empty, but rcov will not report it as covered
|
16
|
-
# unless something (anything) is executed within the clause
|
17
|
-
rcov_error_report = "http://eigenclass.org/hiki.rb?rcov-0.8.0"
|
18
|
-
end
|
19
|
-
return false
|
11
|
+
target.send(predicate, *@args)
|
20
12
|
end
|
21
13
|
|
22
14
|
def failure_message
|
23
|
-
raise @error if @error
|
24
15
|
"expected ##{predicate}(#{@args[0].inspect}) to return true, got false"
|
25
16
|
end
|
26
17
|
|
27
18
|
def negative_failure_message
|
28
|
-
raise @error if @error
|
29
19
|
"expected ##{predicate}(#{@args[0].inspect}) to return false, got true"
|
30
20
|
end
|
31
21
|
|
File without changes
|
@@ -1,54 +1,66 @@
|
|
1
1
|
module Spec
|
2
2
|
module Matchers
|
3
|
-
|
4
3
|
class RaiseError #:nodoc:
|
5
|
-
def initialize(error_or_message=Exception, message=nil)
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
def initialize(error_or_message=Exception, message=nil, &block)
|
5
|
+
@block = block
|
6
|
+
case error_or_message
|
7
|
+
when String, Regexp
|
8
|
+
@expected_error, @expected_message = Exception, error_or_message
|
9
9
|
else
|
10
|
-
@expected_error = error_or_message
|
11
|
-
@expected_message = message
|
10
|
+
@expected_error, @expected_message = error_or_message, message
|
12
11
|
end
|
13
12
|
end
|
14
|
-
|
13
|
+
|
15
14
|
def matches?(proc)
|
16
15
|
@raised_expected_error = false
|
17
|
-
@
|
16
|
+
@with_expected_message = false
|
17
|
+
@eval_block = false
|
18
|
+
@eval_block_passed = false
|
18
19
|
begin
|
19
20
|
proc.call
|
20
21
|
rescue @expected_error => @actual_error
|
21
|
-
|
22
|
-
|
23
|
-
else
|
24
|
-
verify_message
|
25
|
-
end
|
22
|
+
@raised_expected_error = true
|
23
|
+
@with_expected_message = verify_message
|
26
24
|
rescue Exception => @actual_error
|
27
|
-
|
28
|
-
|
29
|
-
|
25
|
+
# This clause should be empty, but rcov will not report it as covered
|
26
|
+
# unless something (anything) is executed within the clause
|
27
|
+
rcov_error_report = "http://eigenclass.org/hiki.rb?rcov-0.8.0"
|
28
|
+
end
|
29
|
+
|
30
|
+
unless negative_expectation?
|
31
|
+
eval_block if @raised_expected_error && @with_expected_message && @block
|
32
|
+
end
|
33
|
+
ensure
|
34
|
+
return (@raised_expected_error && @with_expected_message) ? (@eval_block ? @eval_block_passed : true) : false
|
35
|
+
end
|
36
|
+
|
37
|
+
def eval_block
|
38
|
+
@eval_block = true
|
39
|
+
begin
|
40
|
+
@block[@actual_error]
|
41
|
+
@eval_block_passed = true
|
42
|
+
rescue Exception => err
|
43
|
+
@actual_error = err
|
30
44
|
end
|
31
45
|
end
|
32
46
|
|
33
47
|
def verify_message
|
34
48
|
case @expected_message
|
49
|
+
when nil
|
50
|
+
return true
|
35
51
|
when Regexp
|
36
|
-
|
37
|
-
@raised_expected_error = true
|
38
|
-
else
|
39
|
-
@raised_other = true
|
40
|
-
end
|
52
|
+
return @expected_message =~ @actual_error.message
|
41
53
|
else
|
42
|
-
|
43
|
-
@raised_expected_error = true
|
44
|
-
else
|
45
|
-
@raised_other = true
|
46
|
-
end
|
54
|
+
return @expected_message == @actual_error.message
|
47
55
|
end
|
48
56
|
end
|
49
57
|
|
50
58
|
def failure_message
|
51
|
-
|
59
|
+
if @eval_block
|
60
|
+
return @actual_error.message
|
61
|
+
else
|
62
|
+
return "expected #{expected_error}#{actual_error}"
|
63
|
+
end
|
52
64
|
end
|
53
65
|
|
54
66
|
def negative_failure_message
|
@@ -74,6 +86,11 @@ module Spec
|
|
74
86
|
def actual_error
|
75
87
|
@actual_error.nil? ? " but nothing was raised" : ", got #{@actual_error.inspect}"
|
76
88
|
end
|
89
|
+
|
90
|
+
def negative_expectation?
|
91
|
+
# YES - I'm a bad person... help me find a better way - ryand
|
92
|
+
caller.first(3).find { |s| s =~ /should_not/ }
|
93
|
+
end
|
77
94
|
end
|
78
95
|
|
79
96
|
# :call-seq:
|
@@ -81,6 +98,10 @@ module Spec
|
|
81
98
|
# should raise_error(NamedError)
|
82
99
|
# should raise_error(NamedError, String)
|
83
100
|
# should raise_error(NamedError, Regexp)
|
101
|
+
# should raise_error() { |error| ... }
|
102
|
+
# should raise_error(NamedError) { |error| ... }
|
103
|
+
# should raise_error(NamedError, String) { |error| ... }
|
104
|
+
# should raise_error(NamedError, Regexp) { |error| ... }
|
84
105
|
# should_not raise_error()
|
85
106
|
# should_not raise_error(NamedError)
|
86
107
|
# should_not raise_error(NamedError, String)
|
@@ -90,11 +111,13 @@ module Spec
|
|
90
111
|
# With a named error, matches only if that specific error is raised.
|
91
112
|
# With a named error and messsage specified as a String, matches only if both match.
|
92
113
|
# With a named error and messsage specified as a Regexp, matches only if both match.
|
114
|
+
# Pass an optional block to perform extra verifications on the exception matched
|
93
115
|
#
|
94
116
|
# == Examples
|
95
117
|
#
|
96
118
|
# lambda { do_something_risky }.should raise_error
|
97
119
|
# lambda { do_something_risky }.should raise_error(PoorRiskDecisionError)
|
120
|
+
# lambda { do_something_risky }.should raise_error(PoorRiskDecisionError) { |error| error.data.should == 42 }
|
98
121
|
# lambda { do_something_risky }.should raise_error(PoorRiskDecisionError, "that was too risky")
|
99
122
|
# lambda { do_something_risky }.should raise_error(PoorRiskDecisionError, /oo ri/)
|
100
123
|
#
|
@@ -102,8 +125,8 @@ module Spec
|
|
102
125
|
# lambda { do_something_risky }.should_not raise_error(PoorRiskDecisionError)
|
103
126
|
# lambda { do_something_risky }.should_not raise_error(PoorRiskDecisionError, "that was too risky")
|
104
127
|
# lambda { do_something_risky }.should_not raise_error(PoorRiskDecisionError, /oo ri/)
|
105
|
-
def raise_error(error=Exception, message=nil)
|
106
|
-
Matchers::RaiseError.new(error, message)
|
128
|
+
def raise_error(error=Exception, message=nil, &block)
|
129
|
+
Matchers::RaiseError.new(error, message, &block)
|
107
130
|
end
|
108
131
|
end
|
109
132
|
end
|