rspec 0.8.2 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +125 -9
- data/EXAMPLES.rd +50 -27
- data/README +14 -1
- data/Rakefile +95 -42
- data/UPGRADE +31 -0
- data/bin/spec +0 -1
- data/bin/spec_translator +6 -0
- data/examples/auto_spec_description_example.rb +19 -0
- data/examples/{setup_teardown_example.rb → before_and_after_example.rb} +6 -6
- data/examples/behave_as_example.rb +45 -0
- data/examples/custom_expectation_matchers.rb +13 -12
- data/examples/dynamic_spec.rb +2 -2
- data/examples/file_accessor_spec.rb +2 -2
- data/examples/greeter_spec.rb +3 -3
- data/examples/helper_method_example.rb +2 -2
- data/examples/io_processor_spec.rb +4 -4
- data/examples/legacy_spec.rb +10 -0
- data/examples/mocking_example.rb +5 -5
- data/examples/multi_threaded_behaviour_runner.rb +25 -0
- data/examples/partial_mock_example.rb +4 -4
- data/examples/predicate_example.rb +4 -4
- data/examples/priority.txt +1 -0
- data/examples/shared_behaviours_example.rb +31 -0
- data/examples/stack_spec.rb +52 -69
- data/examples/stubbing_example.rb +10 -10
- data/examples/test_case_adapter_example.rb +26 -0
- data/examples/test_case_spec.rb +6 -6
- data/lib/spec.rb +9 -4
- data/lib/spec/dsl.rb +10 -0
- data/lib/spec/dsl/behaviour.rb +189 -0
- data/lib/spec/dsl/behaviour_callbacks.rb +43 -0
- data/lib/spec/dsl/behaviour_eval.rb +170 -0
- data/lib/spec/dsl/behaviour_factory.rb +32 -0
- data/lib/spec/dsl/composite_proc_builder.rb +28 -0
- data/lib/spec/dsl/configuration.rb +38 -0
- data/lib/spec/dsl/description.rb +34 -0
- data/lib/spec/dsl/example.rb +114 -0
- data/lib/spec/dsl/example_matcher.rb +28 -0
- data/lib/spec/{runner/spec_should_raise_handler.rb → dsl/example_should_raise_handler.rb} +4 -4
- data/lib/spec/expectations.rb +0 -3
- data/lib/spec/expectations/differs/default.rb +0 -1
- data/lib/spec/expectations/extensions.rb +0 -1
- data/lib/spec/expectations/extensions/object.rb +10 -53
- data/lib/spec/expectations/handler.rb +14 -18
- data/lib/spec/extensions.rb +1 -0
- data/lib/spec/extensions/object.rb +6 -0
- data/lib/spec/matchers.rb +19 -21
- data/lib/spec/matchers/be.rb +40 -11
- data/lib/spec/matchers/be_close.rb +2 -2
- data/lib/spec/matchers/operator_matcher.rb +52 -0
- data/lib/spec/matchers/respond_to.rb +21 -11
- data/lib/spec/mocks.rb +5 -28
- data/lib/spec/mocks/argument_constraint_matchers.rb +12 -0
- data/lib/spec/mocks/argument_expectation.rb +7 -4
- data/lib/spec/mocks/methods.rb +11 -16
- data/lib/spec/mocks/mock.rb +6 -3
- data/lib/spec/mocks/{mock_handler.rb → proxy.rb} +4 -7
- data/lib/spec/mocks/space.rb +28 -0
- data/lib/spec/mocks/spec_methods.rb +30 -0
- data/lib/spec/rake/spectask.rb +23 -21
- data/lib/spec/rake/verify_rcov.rb +1 -0
- data/lib/spec/runner.rb +88 -35
- data/lib/spec/runner/backtrace_tweaker.rb +2 -1
- data/lib/spec/runner/behaviour_runner.rb +102 -0
- data/lib/spec/runner/command_line.rb +5 -17
- data/lib/spec/runner/drb_command_line.rb +2 -2
- data/lib/spec/runner/extensions/kernel.rb +22 -9
- data/lib/spec/runner/formatter.rb +4 -0
- data/lib/spec/runner/formatter/base_formatter.rb +63 -0
- data/lib/spec/runner/formatter/base_text_formatter.rb +22 -52
- data/lib/spec/runner/formatter/failing_behaviours_formatter.rb +25 -0
- data/lib/spec/runner/formatter/failing_examples_formatter.rb +22 -0
- data/lib/spec/runner/formatter/html_formatter.rb +74 -29
- data/lib/spec/runner/formatter/progress_bar_formatter.rb +6 -8
- data/lib/spec/runner/formatter/rdoc_formatter.rb +6 -6
- data/lib/spec/runner/formatter/snippet_extractor.rb +52 -0
- data/lib/spec/runner/formatter/specdoc_formatter.rb +6 -6
- data/lib/spec/runner/heckle_runner.rb +8 -7
- data/lib/spec/runner/option_parser.rb +136 -55
- data/lib/spec/runner/options.rb +26 -0
- data/lib/spec/runner/reporter.rb +38 -31
- data/lib/spec/runner/spec_parser.rb +22 -13
- data/lib/spec/test_case_adapter.rb +10 -0
- data/lib/spec/translator.rb +103 -86
- data/lib/spec/version.rb +7 -15
- data/plugins/mock_frameworks/flexmock.rb +27 -0
- data/plugins/mock_frameworks/mocha.rb +21 -0
- data/plugins/mock_frameworks/rspec.rb +18 -0
- data/spec/spec/dsl/behaviour_eval_spec.rb +49 -0
- data/spec/spec/dsl/behaviour_factory_spec.rb +30 -0
- data/spec/spec/dsl/behaviour_spec.rb +508 -0
- data/spec/spec/dsl/composite_proc_builder_spec.rb +57 -0
- data/spec/spec/dsl/configuration_spec.rb +43 -0
- data/spec/spec/dsl/description_spec.rb +51 -0
- data/spec/spec/dsl/example_class_spec.rb +24 -0
- data/spec/spec/dsl/example_instance_spec.rb +140 -0
- data/spec/spec/dsl/example_should_raise_spec.rb +137 -0
- data/spec/spec/dsl/predicate_matcher_spec.rb +21 -0
- data/spec/spec/dsl/shared_behaviour_spec.rb +186 -0
- data/spec/spec/expectations/differs/default_spec.rb +12 -12
- data/spec/spec/expectations/extensions/object_spec.rb +10 -10
- data/spec/spec/expectations/fail_with_spec.rb +20 -20
- data/spec/spec/matchers/be_close_spec.rb +37 -31
- data/spec/spec/matchers/be_spec.rb +50 -41
- data/spec/spec/matchers/change_spec.rb +54 -54
- data/spec/spec/matchers/description_generation_spec.rb +43 -31
- data/spec/spec/matchers/eql_spec.rb +24 -37
- data/spec/spec/matchers/equal_spec.rb +24 -37
- data/spec/spec/matchers/exist_spec.rb +48 -0
- data/spec/spec/matchers/handler_spec.rb +36 -23
- data/spec/spec/matchers/has_spec.rb +8 -8
- data/spec/spec/matchers/have_spec.rb +38 -38
- data/spec/spec/matchers/include_spec.rb +6 -6
- data/spec/spec/matchers/match_spec.rb +8 -8
- data/spec/spec/matchers/matcher_methods_spec.rb +24 -31
- data/spec/spec/matchers/raise_error_spec.rb +34 -34
- data/spec/spec/matchers/respond_to_spec.rb +32 -8
- data/spec/spec/matchers/satisfy_spec.rb +6 -6
- data/spec/spec/matchers/should_===_spec.rb +38 -0
- data/spec/spec/matchers/should_==_spec.rb +37 -0
- data/spec/spec/matchers/should_=~_spec.rb +36 -0
- data/spec/spec/matchers/throw_symbol_spec.rb +47 -55
- data/spec/spec/mocks/any_number_of_times_spec.rb +16 -21
- data/spec/spec/mocks/argument_expectation_spec.rb +3 -3
- data/spec/spec/mocks/at_least_spec.rb +30 -30
- data/spec/spec/mocks/at_most_spec.rb +53 -57
- data/spec/spec/mocks/bug_report_10260_spec.rb +8 -0
- data/spec/spec/mocks/bug_report_7611_spec.rb +3 -3
- data/spec/spec/mocks/bug_report_7805_spec.rb +3 -3
- data/spec/spec/mocks/bug_report_8165_spec.rb +5 -5
- data/spec/spec/mocks/bug_report_8302_spec.rb +5 -5
- data/spec/spec/mocks/failing_mock_argument_constraints_spec.rb +26 -27
- data/spec/spec/mocks/mock_ordering_spec.rb +19 -15
- data/spec/spec/mocks/mock_space_spec.rb +54 -0
- data/spec/spec/mocks/mock_spec.rb +111 -141
- data/spec/spec/mocks/multiple_return_value_spec.rb +48 -48
- data/spec/spec/mocks/null_object_mock_spec.rb +10 -10
- data/spec/spec/mocks/once_counts_spec.rb +32 -35
- data/spec/spec/mocks/options_hash_spec.rb +12 -10
- data/spec/spec/mocks/partial_mock_spec.rb +15 -15
- data/spec/spec/mocks/partial_mock_using_mocks_directly_spec.rb +24 -22
- data/spec/spec/mocks/passing_mock_argument_constraints_spec.rb +19 -19
- data/spec/spec/mocks/precise_counts_spec.rb +28 -32
- data/spec/spec/mocks/record_messages_spec.rb +10 -10
- data/spec/spec/mocks/stub_spec.rb +45 -45
- data/spec/spec/mocks/twice_counts_spec.rb +21 -21
- data/spec/spec/package/bin_spec_spec.rb +12 -0
- data/spec/spec/runner/behaviour_runner_spec.rb +114 -0
- data/spec/spec/runner/command_line_spec.rb +8 -8
- data/spec/spec/runner/context_matching_spec.rb +14 -15
- data/spec/spec/runner/drb_command_line_spec.rb +12 -12
- data/spec/spec/runner/execution_context_spec.rb +8 -29
- data/spec/spec/runner/extensions/kernel_spec.rb +36 -0
- data/spec/spec/runner/formatter/failing_behaviours_formatter_spec.rb +27 -0
- data/spec/spec/runner/formatter/failing_examples_formatter_spec.rb +28 -0
- data/spec/spec/runner/formatter/html_formatter_spec.rb +9 -8
- data/spec/spec/runner/formatter/progress_bar_formatter_dry_run_spec.rb +6 -6
- data/spec/spec/runner/formatter/progress_bar_formatter_failure_dump_spec.rb +10 -10
- data/spec/spec/runner/formatter/progress_bar_formatter_spec.rb +22 -27
- data/spec/spec/runner/formatter/rdoc_formatter_dry_run_spec.rb +6 -5
- data/spec/spec/runner/formatter/rdoc_formatter_spec.rb +17 -17
- data/spec/spec/runner/formatter/snippet_extractor_spec.rb +11 -0
- data/spec/spec/runner/formatter/specdoc_formatter_dry_run_spec.rb +6 -6
- data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +17 -17
- data/spec/spec/runner/heckle_runner_spec.rb +21 -21
- data/spec/spec/runner/heckler_spec.rb +5 -5
- data/spec/spec/runner/noisy_backtrace_tweaker_spec.rb +12 -12
- data/spec/spec/runner/object_ext_spec.rb +3 -3
- data/spec/spec/runner/option_parser_spec.rb +171 -102
- data/spec/spec/runner/quiet_backtrace_tweaker_spec.rb +21 -12
- data/spec/spec/runner/reporter_spec.rb +106 -97
- data/spec/spec/runner/spec_matcher_spec.rb +46 -51
- data/spec/spec/runner/spec_parser_spec.rb +72 -16
- data/spec/spec/spec_classes.rb +12 -3
- data/spec/spec/translator_spec.rb +165 -36
- metadata +66 -76
- data/RELEASE-PLAN +0 -117
- data/examples/auto_spec_name_generation_example.rb +0 -18
- data/lib/spec/callback.rb +0 -11
- data/lib/spec/callback/callback_container.rb +0 -60
- data/lib/spec/callback/extensions/module.rb +0 -24
- data/lib/spec/callback/extensions/object.rb +0 -37
- data/lib/spec/deprecated.rb +0 -3
- data/lib/spec/expectations/extensions/proc.rb +0 -57
- data/lib/spec/expectations/should.rb +0 -5
- data/lib/spec/expectations/should/base.rb +0 -64
- data/lib/spec/expectations/should/change.rb +0 -69
- data/lib/spec/expectations/should/have.rb +0 -128
- data/lib/spec/expectations/should/not.rb +0 -74
- data/lib/spec/expectations/should/should.rb +0 -81
- data/lib/spec/expectations/sugar.rb +0 -47
- data/lib/spec/runner/context.rb +0 -154
- data/lib/spec/runner/context_eval.rb +0 -142
- data/lib/spec/runner/context_runner.rb +0 -55
- data/lib/spec/runner/execution_context.rb +0 -17
- data/lib/spec/runner/spec_matcher.rb +0 -25
- data/lib/spec/runner/specification.rb +0 -114
- data/spec/spec/callback/callback_container_spec.rb +0 -27
- data/spec/spec/callback/module_spec.rb +0 -37
- data/spec/spec/callback/object_spec.rb +0 -90
- data/spec/spec/callback/object_with_class_callback_spec.rb +0 -19
- data/spec/spec/expectations/should/should_==_spec.rb +0 -19
- data/spec/spec/expectations/should/should_=~_spec.rb +0 -13
- data/spec/spec/expectations/should/should_be_a_kind_of_spec.rb +0 -21
- data/spec/spec/expectations/should/should_be_an_instance_of_spec.rb +0 -30
- data/spec/spec/expectations/should/should_be_arbitrary_predicate_spec.rb +0 -81
- data/spec/spec/expectations/should/should_be_close_spec.rb +0 -18
- data/spec/spec/expectations/should/should_be_comparison_operator_spec.rb +0 -44
- data/spec/spec/expectations/should/should_be_false_spec.rb +0 -39
- data/spec/spec/expectations/should/should_be_spec.rb +0 -11
- data/spec/spec/expectations/should/should_be_true_spec.rb +0 -27
- data/spec/spec/expectations/should/should_change_spec.rb +0 -184
- data/spec/spec/expectations/should/should_eql_spec.rb +0 -11
- data/spec/spec/expectations/should/should_equal_spec.rb +0 -11
- data/spec/spec/expectations/should/should_have_at_least_spec.rb +0 -53
- data/spec/spec/expectations/should/should_have_at_most_spec.rb +0 -45
- data/spec/spec/expectations/should/should_have_key_spec.rb +0 -21
- data/spec/spec/expectations/should/should_have_spec.rb +0 -64
- data/spec/spec/expectations/should/should_include_spec.rb +0 -59
- data/spec/spec/expectations/should/should_match_spec.rb +0 -25
- data/spec/spec/expectations/should/should_not_==_spec.rb +0 -15
- data/spec/spec/expectations/should/should_not_be_a_kind_of_spec.rb +0 -21
- data/spec/spec/expectations/should/should_not_be_an_instance_of_spec.rb +0 -11
- data/spec/spec/expectations/should/should_not_be_arbitrary_predicate_spec.rb +0 -68
- data/spec/spec/expectations/should/should_not_be_spec.rb +0 -11
- data/spec/spec/expectations/should/should_not_change_spec.rb +0 -24
- data/spec/spec/expectations/should/should_not_eql_spec.rb +0 -11
- data/spec/spec/expectations/should/should_not_equal_spec.rb +0 -11
- data/spec/spec/expectations/should/should_not_have_key_spec.rb +0 -15
- data/spec/spec/expectations/should/should_not_include_spec.rb +0 -58
- data/spec/spec/expectations/should/should_not_match_spec.rb +0 -11
- data/spec/spec/expectations/should/should_not_raise_spec.rb +0 -75
- data/spec/spec/expectations/should/should_not_respond_to_spec.rb +0 -15
- data/spec/spec/expectations/should/should_not_throw_spec.rb +0 -35
- data/spec/spec/expectations/should/should_raise_spec.rb +0 -66
- data/spec/spec/expectations/should/should_respond_to_spec.rb +0 -15
- data/spec/spec/expectations/should/should_satisfy_spec.rb +0 -35
- data/spec/spec/expectations/should/should_throw_spec.rb +0 -27
- data/spec/spec/runner/context_runner_spec.rb +0 -100
- data/spec/spec/runner/context_spec.rb +0 -405
- data/spec/spec/runner/kernel_ext_spec.rb +0 -16
- data/spec/spec/runner/spec_name_generation_spec.rb +0 -102
- data/spec/spec/runner/specification_class_spec.rb +0 -72
- data/spec/spec/runner/specification_instance_spec.rb +0 -160
- data/spec/spec/runner/specification_should_raise_spec.rb +0 -136
@@ -0,0 +1,32 @@
|
|
1
|
+
module Spec
|
2
|
+
module DSL
|
3
|
+
class BehaviourFactory
|
4
|
+
|
5
|
+
class << self
|
6
|
+
|
7
|
+
BEHAVIOUR_CLASSES = {:default => Spec::DSL::Behaviour}
|
8
|
+
|
9
|
+
def add_behaviour_class(key, value)
|
10
|
+
BEHAVIOUR_CLASSES[key] = value
|
11
|
+
end
|
12
|
+
|
13
|
+
def remove_behaviour_class(key)
|
14
|
+
BEHAVIOUR_CLASSES.delete(key)
|
15
|
+
end
|
16
|
+
|
17
|
+
def create(*args, &block)
|
18
|
+
return BEHAVIOUR_CLASSES[behaviour_type(*args)].new(*args, &block)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def behaviour_type(*args)
|
24
|
+
opts = Hash === args.last ? args.last : {}
|
25
|
+
opts[:behaviour_type] ? opts[:behaviour_type] : :default
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Spec
|
2
|
+
module DSL
|
3
|
+
class CompositeProcBuilder < Array
|
4
|
+
def initialize(callbacks=[])
|
5
|
+
push(*callbacks)
|
6
|
+
end
|
7
|
+
|
8
|
+
def proc(&error_handler)
|
9
|
+
parts = self
|
10
|
+
Proc.new do
|
11
|
+
parts.collect do |part|
|
12
|
+
begin
|
13
|
+
if part.is_a?(UnboundMethod)
|
14
|
+
part.bind(self).call
|
15
|
+
else
|
16
|
+
instance_eval(&part)
|
17
|
+
end
|
18
|
+
rescue Exception => e
|
19
|
+
raise e unless error_handler
|
20
|
+
error_handler.call(e)
|
21
|
+
e
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Spec
|
2
|
+
module DSL
|
3
|
+
class Configuration
|
4
|
+
|
5
|
+
def mock_with(mock_framework)
|
6
|
+
@mock_framework = case mock_framework
|
7
|
+
when Symbol
|
8
|
+
mock_framework_path(mock_framework.to_s)
|
9
|
+
else
|
10
|
+
mock_framework
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def mock_framework
|
15
|
+
@mock_framework ||= mock_framework_path("rspec")
|
16
|
+
end
|
17
|
+
|
18
|
+
def include(mod)
|
19
|
+
included_modules << mod
|
20
|
+
end
|
21
|
+
|
22
|
+
def included_modules
|
23
|
+
@included_modules ||= []
|
24
|
+
end
|
25
|
+
|
26
|
+
def predicate_matchers
|
27
|
+
@predicate_matchers ||= {}
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def mock_framework_path(framework_name)
|
33
|
+
File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "plugins", "mock_frameworks", framework_name))
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Spec
|
2
|
+
module DSL
|
3
|
+
class Description
|
4
|
+
attr_reader :description, :described_type
|
5
|
+
|
6
|
+
def initialize(*args)
|
7
|
+
args, @options = args_and_options(*args)
|
8
|
+
@described_type = args.first unless args.first.is_a?(String)
|
9
|
+
@description = args.shift.to_s
|
10
|
+
@description << args.shift.to_s unless args.empty?
|
11
|
+
end
|
12
|
+
|
13
|
+
def [](key)
|
14
|
+
@options[key]
|
15
|
+
end
|
16
|
+
|
17
|
+
def []=(key, value)
|
18
|
+
@options[key] = value
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_s; @description; end
|
22
|
+
|
23
|
+
def ==(value)
|
24
|
+
case value
|
25
|
+
when Description
|
26
|
+
@description == value.description
|
27
|
+
else
|
28
|
+
@description == value
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
require 'timeout'
|
2
|
+
|
3
|
+
module Spec
|
4
|
+
module DSL
|
5
|
+
class Example
|
6
|
+
def initialize(description, options={}, &example_block)
|
7
|
+
@from = caller(0)[3]
|
8
|
+
@options = options
|
9
|
+
@example_block = example_block
|
10
|
+
@description = description
|
11
|
+
@description_generated_proc = lambda { |desc| @generated_description = desc }
|
12
|
+
end
|
13
|
+
|
14
|
+
def run(reporter, before_each_block, after_each_block, dry_run, execution_context, timeout=nil)
|
15
|
+
reporter.example_started(description)
|
16
|
+
return reporter.example_finished(description) if dry_run
|
17
|
+
|
18
|
+
errors = []
|
19
|
+
location = nil
|
20
|
+
Timeout.timeout(timeout) do
|
21
|
+
before_each_ok = setup_example(execution_context, errors, &before_each_block)
|
22
|
+
example_ok = run_example(execution_context, errors) if before_each_ok
|
23
|
+
after_each_ok = teardown_example(execution_context, errors, &after_each_block)
|
24
|
+
location = failure_location(before_each_ok, example_ok, after_each_ok)
|
25
|
+
end
|
26
|
+
|
27
|
+
ExampleShouldRaiseHandler.new(@from, @options).handle(errors)
|
28
|
+
reporter.example_finished(description, errors.first, location) if reporter
|
29
|
+
end
|
30
|
+
|
31
|
+
def matches?(matcher, specified_examples)
|
32
|
+
matcher.example_desc = description
|
33
|
+
matcher.matches?(specified_examples)
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
def description
|
38
|
+
@description == :__generate_description ? generated_description : @description
|
39
|
+
end
|
40
|
+
|
41
|
+
def generated_description
|
42
|
+
@generated_description || "NAME NOT GENERATED"
|
43
|
+
end
|
44
|
+
|
45
|
+
def setup_example(execution_context, errors, &behaviour_before_block)
|
46
|
+
setup_mocks(execution_context)
|
47
|
+
Spec::Matchers.description_generated(&@description_generated_proc)
|
48
|
+
|
49
|
+
builder = CompositeProcBuilder.new
|
50
|
+
before_proc = builder.proc(&append_errors(errors))
|
51
|
+
execution_context.instance_eval(&before_proc)
|
52
|
+
|
53
|
+
execution_context.instance_eval(&behaviour_before_block) if behaviour_before_block
|
54
|
+
return errors.empty?
|
55
|
+
rescue => e
|
56
|
+
errors << e
|
57
|
+
return false
|
58
|
+
end
|
59
|
+
|
60
|
+
def run_example(execution_context, errors)
|
61
|
+
begin
|
62
|
+
execution_context.instance_eval(&@example_block)
|
63
|
+
return true
|
64
|
+
rescue Exception => e
|
65
|
+
errors << e
|
66
|
+
return false
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def teardown_example(execution_context, errors, &behaviour_after_each)
|
71
|
+
execution_context.instance_eval(&behaviour_after_each) if behaviour_after_each
|
72
|
+
|
73
|
+
begin
|
74
|
+
verify_mocks(execution_context)
|
75
|
+
ensure
|
76
|
+
teardown_mocks(execution_context)
|
77
|
+
end
|
78
|
+
|
79
|
+
Spec::Matchers.unregister_description_generated(@description_generated_proc)
|
80
|
+
|
81
|
+
builder = CompositeProcBuilder.new
|
82
|
+
after_proc = builder.proc(&append_errors(errors))
|
83
|
+
execution_context.instance_eval(&after_proc)
|
84
|
+
|
85
|
+
return errors.empty?
|
86
|
+
rescue => e
|
87
|
+
errors << e
|
88
|
+
return false
|
89
|
+
end
|
90
|
+
|
91
|
+
def setup_mocks(execution_context)
|
92
|
+
execution_context.setup_mocks_for_rspec if execution_context.respond_to?(:setup_mocks_for_rspec)
|
93
|
+
end
|
94
|
+
|
95
|
+
def verify_mocks(execution_context)
|
96
|
+
execution_context.verify_mocks_for_rspec if execution_context.respond_to?(:verify_mocks_for_rspec)
|
97
|
+
end
|
98
|
+
|
99
|
+
def teardown_mocks(execution_context)
|
100
|
+
execution_context.teardown_mocks_for_rspec if execution_context.respond_to?(:teardown_mocks_for_rspec)
|
101
|
+
end
|
102
|
+
|
103
|
+
def append_errors(errors)
|
104
|
+
proc {|error| errors << error}
|
105
|
+
end
|
106
|
+
|
107
|
+
def failure_location(before_each_ok, example_ok, after_each_ok)
|
108
|
+
return 'before(:each)' unless before_each_ok
|
109
|
+
return description unless example_ok
|
110
|
+
return 'after(:each)' unless after_each_ok
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Spec
|
2
|
+
module DSL
|
3
|
+
class ExampleMatcher
|
4
|
+
|
5
|
+
attr_writer :example_desc
|
6
|
+
def initialize(context_desc, example_desc=nil)
|
7
|
+
@context_desc = context_desc
|
8
|
+
@example_desc = example_desc
|
9
|
+
end
|
10
|
+
|
11
|
+
def matches?(specified_examples)
|
12
|
+
specified_examples.each do |specified_example|
|
13
|
+
return true if specified_example =~ /(^#{context_regexp} #{example_regexp}$|^#{context_regexp}$|^#{example_regexp}$)/
|
14
|
+
end
|
15
|
+
false
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
def context_regexp
|
20
|
+
Regexp.escape(@context_desc.split('::').last)
|
21
|
+
end
|
22
|
+
|
23
|
+
def example_regexp
|
24
|
+
Regexp.escape(@example_desc)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Spec
|
2
|
-
module
|
3
|
-
class
|
2
|
+
module DSL
|
3
|
+
class ExampleShouldRaiseHandler
|
4
4
|
def initialize(file_and_line_number, opts)
|
5
5
|
@file_and_line_number = file_and_line_number
|
6
6
|
@options = opts
|
@@ -31,9 +31,9 @@ module Spec
|
|
31
31
|
|
32
32
|
def build_message(exception=nil)
|
33
33
|
if @expected_error_message.nil?
|
34
|
-
message = "
|
34
|
+
message = "example block expected #{@expected_error_class.to_s}"
|
35
35
|
else
|
36
|
-
message = "
|
36
|
+
message = "example block expected #{@expected_error_class.new(@expected_error_message.to_s).inspect}"
|
37
37
|
end
|
38
38
|
message << " but raised #{exception.inspect}" if exception
|
39
39
|
message << " but nothing was raised" unless exception
|
data/lib/spec/expectations.rb
CHANGED
@@ -7,6 +7,7 @@ module Spec
|
|
7
7
|
# :call-seq:
|
8
8
|
# should(matcher)
|
9
9
|
# should == expected
|
10
|
+
# should === expected
|
10
11
|
# should =~ expected
|
11
12
|
#
|
12
13
|
# receiver.should(matcher)
|
@@ -15,6 +16,9 @@ module Spec
|
|
15
16
|
# receiver.should == expected #any value
|
16
17
|
# => Passes if (receiver == expected)
|
17
18
|
#
|
19
|
+
# receiver.should === expected #any value
|
20
|
+
# => Passes if (receiver === expected)
|
21
|
+
#
|
18
22
|
# receiver.should =~ regexp
|
19
23
|
# => Passes if (receiver =~ regexp)
|
20
24
|
#
|
@@ -26,12 +30,13 @@ module Spec
|
|
26
30
|
# Instead, use receiver.should_not == expected
|
27
31
|
def should(matcher=nil, &block)
|
28
32
|
return ExpectationMatcherHandler.handle_matcher(self, matcher, &block) if matcher
|
29
|
-
|
33
|
+
Spec::Matchers::PositiveOperatorMatcher.new(self)
|
30
34
|
end
|
31
35
|
|
32
36
|
# :call-seq:
|
33
37
|
# should_not(matcher)
|
34
38
|
# should_not == expected
|
39
|
+
# should_not === expected
|
35
40
|
# should_not =~ expected
|
36
41
|
#
|
37
42
|
# receiver.should_not(matcher)
|
@@ -40,70 +45,22 @@ module Spec
|
|
40
45
|
# receiver.should_not == expected
|
41
46
|
# => Passes unless (receiver == expected)
|
42
47
|
#
|
48
|
+
# receiver.should_not === expected
|
49
|
+
# => Passes unless (receiver === expected)
|
50
|
+
#
|
43
51
|
# receiver.should_not =~ regexp
|
44
52
|
# => Passes unless (receiver =~ regexp)
|
45
53
|
#
|
46
54
|
# See Spec::Matchers for more information about matchers
|
47
55
|
def should_not(matcher=nil, &block)
|
48
56
|
return NegativeExpectationMatcherHandler.handle_matcher(self, matcher, &block) if matcher
|
49
|
-
|
57
|
+
Spec::Matchers::NegativeOperatorMatcher.new(self)
|
50
58
|
end
|
51
59
|
|
52
|
-
deprecated do
|
53
|
-
# Deprecated: use should have(n).items (see Spec::Matchers)
|
54
|
-
# This will be removed in 0.9
|
55
|
-
def should_have(expected)
|
56
|
-
should.have(expected)
|
57
|
-
end
|
58
|
-
alias_method :should_have_exactly, :should_have
|
59
|
-
|
60
|
-
# Deprecated: use should have_at_least(n).items (see Spec::Matchers)
|
61
|
-
# This will be removed in 0.9
|
62
|
-
def should_have_at_least(expected)
|
63
|
-
should.have.at_least(expected)
|
64
|
-
end
|
65
|
-
|
66
|
-
# Deprecated: use should have_at_most(n).items (see Spec::Matchers)
|
67
|
-
# This will be removed in 0.9
|
68
|
-
def should_have_at_most(expected)
|
69
|
-
should.have.at_most(expected)
|
70
|
-
end
|
71
|
-
|
72
|
-
# Deprecated: use should include(expected) (see Spec::Matchers)
|
73
|
-
# This will be removed in 0.9
|
74
|
-
def should_include(expected)
|
75
|
-
should.include(expected)
|
76
|
-
end
|
77
|
-
|
78
|
-
# Deprecated: use should_not include(expected) (see Spec::Matchers)
|
79
|
-
# This will be removed in 0.9
|
80
|
-
def should_not_include(expected)
|
81
|
-
should.not.include(expected)
|
82
|
-
end
|
83
|
-
|
84
|
-
# Deprecated: use should be(expected) (see Spec::Matchers)
|
85
|
-
# This will be removed in 0.9
|
86
|
-
def should_be(expected = :___no_arg)
|
87
|
-
should.be(expected)
|
88
|
-
end
|
89
|
-
|
90
|
-
# Deprecated: use should_not be(expected) (see Spec::Matchers)
|
91
|
-
# This will be removed in 0.9
|
92
|
-
def should_not_be(expected = :___no_arg)
|
93
|
-
should_not.be(expected)
|
94
|
-
end
|
95
|
-
end
|
96
60
|
end
|
97
61
|
end
|
98
62
|
end
|
99
63
|
|
100
64
|
class Object
|
101
65
|
include Spec::Expectations::ObjectExpectations
|
102
|
-
deprecated do
|
103
|
-
include Spec::Expectations::UnderscoreSugar
|
104
|
-
end
|
105
66
|
end
|
106
|
-
|
107
|
-
deprecated do
|
108
|
-
Object.handle_underscores_for_rspec!
|
109
|
-
end
|
@@ -11,11 +11,9 @@ module Spec
|
|
11
11
|
class << self
|
12
12
|
include MatcherHandlerHelper
|
13
13
|
def handle_matcher(actual, matcher, &block)
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
Spec::Expectations.fail_with(matcher.failure_message) unless match
|
18
|
-
end
|
14
|
+
match = matcher.matches?(actual, &block)
|
15
|
+
::Spec::Matchers.generated_description = "should #{describe(matcher)}"
|
16
|
+
Spec::Expectations.fail_with(matcher.failure_message) unless match
|
19
17
|
end
|
20
18
|
end
|
21
19
|
end
|
@@ -24,20 +22,18 @@ module Spec
|
|
24
22
|
class << self
|
25
23
|
include MatcherHandlerHelper
|
26
24
|
def handle_matcher(actual, matcher, &block)
|
27
|
-
unless matcher.
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
)
|
36
|
-
end
|
37
|
-
match = matcher.matches?(actual, &block)
|
38
|
-
::Spec::Matchers.generated_description = "should not #{describe(matcher)}"
|
39
|
-
Spec::Expectations.fail_with(matcher.negative_failure_message) if match
|
25
|
+
unless matcher.respond_to?(:negative_failure_message)
|
26
|
+
Spec::Expectations.fail_with(
|
27
|
+
<<-EOF
|
28
|
+
Matcher does not support should_not.
|
29
|
+
See Spec::Matchers for more information
|
30
|
+
about matchers.
|
31
|
+
EOF
|
32
|
+
)
|
40
33
|
end
|
34
|
+
match = matcher.matches?(actual, &block)
|
35
|
+
::Spec::Matchers.generated_description = "should not #{describe(matcher)}"
|
36
|
+
Spec::Expectations.fail_with(matcher.negative_failure_message) if match
|
41
37
|
end
|
42
38
|
end
|
43
39
|
end
|