rspec 0.8.2 → 0.9.0
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/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
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
module Spec
|
|
2
|
-
module Runner
|
|
3
|
-
module ContextEval
|
|
4
|
-
module ModuleMethods
|
|
5
|
-
def inherit(klass)
|
|
6
|
-
@context_superclass = klass
|
|
7
|
-
derive_execution_context_class_from_context_superclass
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def include(mod)
|
|
11
|
-
context_modules << mod
|
|
12
|
-
mod.send :included, self
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def context_setup(&block)
|
|
16
|
-
context_setup_parts << block
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def context_teardown(&block)
|
|
20
|
-
context_teardown_parts << block
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def setup(&block)
|
|
24
|
-
setup_parts << block
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def teardown(&block)
|
|
28
|
-
teardown_parts << block
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def specify(spec_name=:__generate_description, opts={}, &block)
|
|
32
|
-
specifications << Specification.new(spec_name, opts, &block)
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def methods
|
|
36
|
-
my_methods = super
|
|
37
|
-
my_methods |= context_superclass.methods
|
|
38
|
-
my_methods
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
protected
|
|
42
|
-
|
|
43
|
-
def method_missing(method_name, *args)
|
|
44
|
-
if context_superclass.respond_to?(method_name)
|
|
45
|
-
return execution_context_class.send(method_name, *args)
|
|
46
|
-
end
|
|
47
|
-
super
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
private
|
|
51
|
-
|
|
52
|
-
def context_setup_block
|
|
53
|
-
parts = context_setup_parts.dup
|
|
54
|
-
add_context_superclass_method(:context_setup, parts)
|
|
55
|
-
create_block_from_parts(parts)
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def context_teardown_block
|
|
59
|
-
parts = context_teardown_parts.dup
|
|
60
|
-
add_context_superclass_method(:context_teardown, parts)
|
|
61
|
-
create_block_from_parts(parts)
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def setup_block
|
|
65
|
-
parts = setup_parts.dup
|
|
66
|
-
add_context_superclass_method(:setup, parts)
|
|
67
|
-
create_block_from_parts(parts)
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
def teardown_block
|
|
71
|
-
parts = teardown_parts.dup
|
|
72
|
-
add_context_superclass_method(:teardown, parts)
|
|
73
|
-
create_block_from_parts(parts)
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
def execution_context_class
|
|
77
|
-
@execution_context_class ||= derive_execution_context_class_from_context_superclass
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
def derive_execution_context_class_from_context_superclass
|
|
81
|
-
@execution_context_class = Class.new(context_superclass)
|
|
82
|
-
@execution_context_class.class_eval do
|
|
83
|
-
include ::Spec::Runner::ExecutionContext::InstanceMethods
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
def context_superclass
|
|
88
|
-
@context_superclass ||= Object
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
def context_modules
|
|
92
|
-
@context_modules ||= [Spec::Matchers, Spec::Mocks]
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
def specifications
|
|
96
|
-
@specifications ||= []
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
def context_setup_parts
|
|
100
|
-
@context_setup_parts ||= []
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
def context_teardown_parts
|
|
104
|
-
@context_teardown_parts ||= []
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
def setup_parts
|
|
108
|
-
@setup_parts ||= []
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
def teardown_parts
|
|
112
|
-
@teardown_parts ||= []
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
def add_context_superclass_method sym, parts
|
|
116
|
-
superclass_method = begin
|
|
117
|
-
context_superclass.instance_method(sym)
|
|
118
|
-
rescue
|
|
119
|
-
nil
|
|
120
|
-
end
|
|
121
|
-
parts.unshift superclass_method if superclass_method
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
def create_block_from_parts(parts)
|
|
125
|
-
proc do
|
|
126
|
-
parts.each do |part|
|
|
127
|
-
if part.is_a?(UnboundMethod)
|
|
128
|
-
part.bind(self).call
|
|
129
|
-
else
|
|
130
|
-
instance_eval(&part)
|
|
131
|
-
end
|
|
132
|
-
end
|
|
133
|
-
end
|
|
134
|
-
end
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
module InstanceMethods
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
end
|
|
141
|
-
end
|
|
142
|
-
end
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
module Spec
|
|
2
|
-
module Runner
|
|
3
|
-
class ContextRunner
|
|
4
|
-
|
|
5
|
-
def initialize(options)
|
|
6
|
-
@contexts = []
|
|
7
|
-
@options = options
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def add_context(context)
|
|
11
|
-
return unless spec_description.nil? || context.matches?(spec_description)
|
|
12
|
-
context.run_single_spec(spec_description) if context.matches?(spec_description)
|
|
13
|
-
@contexts << context
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
# Runs all contexts and returns the number of failures.
|
|
17
|
-
def run(exit_when_done)
|
|
18
|
-
@options.reporter.start(number_of_specs)
|
|
19
|
-
begin
|
|
20
|
-
@contexts.each do |context|
|
|
21
|
-
context.run(@options.reporter, @options.dry_run)
|
|
22
|
-
end
|
|
23
|
-
rescue Interrupt
|
|
24
|
-
ensure
|
|
25
|
-
@options.reporter.end
|
|
26
|
-
end
|
|
27
|
-
failure_count = @options.reporter.dump
|
|
28
|
-
|
|
29
|
-
if(failure_count == 0 && !@options.heckle_runner.nil?)
|
|
30
|
-
heckle_runner = @options.heckle_runner
|
|
31
|
-
@options.heckle_runner = nil
|
|
32
|
-
context_runner = self.class.new(@options)
|
|
33
|
-
context_runner.instance_variable_set(:@contexts, @contexts)
|
|
34
|
-
heckle_runner.heckle_with(context_runner)
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
if(exit_when_done)
|
|
38
|
-
exit_code = (failure_count == 0) ? 0 : 1
|
|
39
|
-
exit(exit_code)
|
|
40
|
-
end
|
|
41
|
-
failure_count
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def number_of_specs
|
|
45
|
-
@contexts.inject(0) {|sum, context| sum + context.number_of_specs}
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
private
|
|
49
|
-
def spec_description
|
|
50
|
-
@options.spec_name
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
end
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
module Spec
|
|
2
|
-
module Runner
|
|
3
|
-
class ExecutionContext
|
|
4
|
-
module InstanceMethods
|
|
5
|
-
def initialize(*args) #:nodoc:
|
|
6
|
-
#necessary for RSpec's own specs
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def violated(message="")
|
|
10
|
-
raise Spec::Expectations::ExpectationNotMetError.new(message)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
end
|
|
14
|
-
include InstanceMethods
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
module Spec
|
|
2
|
-
module Runner
|
|
3
|
-
class SpecMatcher
|
|
4
|
-
|
|
5
|
-
attr_writer :spec_desc
|
|
6
|
-
def initialize(context_desc, spec_desc=nil)
|
|
7
|
-
@context_desc = context_desc
|
|
8
|
-
@spec_desc = spec_desc
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def matches?(desc)
|
|
12
|
-
desc =~ /(^#{context_regexp} #{spec_regexp}$|^#{context_regexp}$|^#{spec_regexp}$)/
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
private
|
|
16
|
-
def context_regexp
|
|
17
|
-
Regexp.escape(@context_desc)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def spec_regexp
|
|
21
|
-
Regexp.escape(@spec_desc)
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
module Spec
|
|
2
|
-
module Runner
|
|
3
|
-
class Specification
|
|
4
|
-
|
|
5
|
-
class << self
|
|
6
|
-
attr_accessor :current, :generated_description
|
|
7
|
-
protected :current=
|
|
8
|
-
|
|
9
|
-
callback_events :before_setup, :after_teardown
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
attr_reader :spec_block
|
|
13
|
-
callback_events :before_setup, :after_teardown
|
|
14
|
-
|
|
15
|
-
def initialize(name, opts={}, &spec_block)
|
|
16
|
-
@from = caller(0)[3]
|
|
17
|
-
@description = name
|
|
18
|
-
@options = opts
|
|
19
|
-
@spec_block = spec_block
|
|
20
|
-
@description_generated_callback = lambda { |desc| @generated_description = desc }
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def run(reporter, setup_block, teardown_block, dry_run, execution_context)
|
|
24
|
-
reporter.spec_started(name) if reporter
|
|
25
|
-
return reporter.spec_finished(name) if dry_run
|
|
26
|
-
|
|
27
|
-
errors = []
|
|
28
|
-
begin
|
|
29
|
-
set_current
|
|
30
|
-
setup_ok = setup_spec(execution_context, errors, &setup_block)
|
|
31
|
-
spec_ok = execute_spec(execution_context, errors) if setup_ok
|
|
32
|
-
teardown_ok = teardown_spec(execution_context, errors, &teardown_block)
|
|
33
|
-
ensure
|
|
34
|
-
clear_current
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
SpecShouldRaiseHandler.new(@from, @options).handle(errors)
|
|
38
|
-
reporter.spec_finished(name, errors.first, failure_location(setup_ok, spec_ok, teardown_ok)) if reporter
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def matches?(matcher, description)
|
|
42
|
-
matcher.spec_desc = name
|
|
43
|
-
matcher.matches?(description)
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
private
|
|
47
|
-
def name
|
|
48
|
-
@description == :__generate_description ? generated_description : @description
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def generated_description
|
|
52
|
-
@generated_description || "NAME NOT GENERATED"
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
def setup_spec(execution_context, errors, &setup_block)
|
|
56
|
-
notify_before_setup(errors)
|
|
57
|
-
execution_context.instance_eval(&setup_block) if setup_block
|
|
58
|
-
return errors.empty?
|
|
59
|
-
rescue => e
|
|
60
|
-
errors << e
|
|
61
|
-
return false
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def execute_spec(execution_context, errors)
|
|
65
|
-
begin
|
|
66
|
-
execution_context.instance_eval(&spec_block)
|
|
67
|
-
return true
|
|
68
|
-
rescue Exception => e
|
|
69
|
-
errors << e
|
|
70
|
-
return false
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
def teardown_spec(execution_context, errors, &teardown_block)
|
|
75
|
-
execution_context.instance_eval(&teardown_block) if teardown_block
|
|
76
|
-
notify_after_teardown(errors)
|
|
77
|
-
return errors.empty?
|
|
78
|
-
rescue => e
|
|
79
|
-
errors << e
|
|
80
|
-
return false
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
def notify_before_setup(errors)
|
|
84
|
-
notify_class_callbacks(:before_setup, self, &append_errors(errors))
|
|
85
|
-
notify_callbacks(:before_setup, self, &append_errors(errors))
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
def notify_after_teardown(errors)
|
|
89
|
-
notify_callbacks(:after_teardown, self, &append_errors(errors))
|
|
90
|
-
notify_class_callbacks(:after_teardown, self, &append_errors(errors))
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
def append_errors(errors)
|
|
94
|
-
proc {|error| errors << error}
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
def set_current
|
|
98
|
-
Spec::Matchers.description_generated(&@description_generated_callback)
|
|
99
|
-
self.class.send(:current=, self)
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
def clear_current
|
|
103
|
-
Spec::Matchers.unregister_callback(:description_generated, @description_generated_callback)
|
|
104
|
-
self.class.send(:current=, nil)
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
def failure_location(setup_ok, spec_ok, teardown_ok)
|
|
108
|
-
return 'setup' unless setup_ok
|
|
109
|
-
return name unless spec_ok
|
|
110
|
-
return 'teardown' unless teardown_ok
|
|
111
|
-
end
|
|
112
|
-
end
|
|
113
|
-
end
|
|
114
|
-
end
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
require File.dirname(__FILE__) + '/../../spec_helper.rb'
|
|
2
|
-
|
|
3
|
-
context "A CallbackContainer instance" do
|
|
4
|
-
setup do
|
|
5
|
-
@container = Callback::CallbackContainer.new
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
specify "should define and call callbacks" do
|
|
9
|
-
@container.define(:foo) {:bar}
|
|
10
|
-
@container.define(:foo) {:baz}
|
|
11
|
-
@container.notify(:foo).should == [:bar, :baz]
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
specify "should undefine callbacks" do
|
|
15
|
-
callback_to_undefine = @container.define(:foo) {:bar}
|
|
16
|
-
@container.define(:foo) {:baz}
|
|
17
|
-
@container.undefine(:foo, callback_to_undefine)
|
|
18
|
-
@container.notify(:foo).should == [:baz]
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
specify "should clear all callbacks" do
|
|
22
|
-
@container.define(:foo) {:bar}
|
|
23
|
-
@container.define(:baz) {1}
|
|
24
|
-
@container.clear
|
|
25
|
-
@container.notify(:foo).should == []
|
|
26
|
-
end
|
|
27
|
-
end
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
require File.dirname(__FILE__) + '/../../spec_helper.rb'
|
|
2
|
-
|
|
3
|
-
context "A Module" do
|
|
4
|
-
specify "should provide callback_events and notify_callbacks methods" do
|
|
5
|
-
the_class = Class.new do
|
|
6
|
-
callback_events :foo
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
the_obj = the_class.new
|
|
10
|
-
the_obj.foo { :bar }
|
|
11
|
-
the_obj.notify_callbacks(:foo).should == [:bar]
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
specify "should support defining multiple callback_events with one call to callback_events" do
|
|
15
|
-
the_class = Class.new do
|
|
16
|
-
callback_events :foo, :bar
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
the_obj = the_class.new
|
|
20
|
-
the_obj.foo { 1 }
|
|
21
|
-
the_obj.bar { 2 }
|
|
22
|
-
the_obj.notify_callbacks(:foo).should == [1]
|
|
23
|
-
the_obj.notify_callbacks(:bar).should == [2]
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
specify "should provide unregister_callback method" do
|
|
27
|
-
the_class = Class.new do
|
|
28
|
-
callback_events :foo
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
the_obj = the_class.new
|
|
32
|
-
bar_proc = proc {:bar}
|
|
33
|
-
the_obj.foo &bar_proc
|
|
34
|
-
the_obj.unregister_callback(:foo, bar_proc)
|
|
35
|
-
the_obj.notify_callbacks(:foo).should == []
|
|
36
|
-
end
|
|
37
|
-
end
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
require File.dirname(__FILE__) + '/../../spec_helper.rb'
|
|
2
|
-
|
|
3
|
-
context "An Object" do
|
|
4
|
-
setup do
|
|
5
|
-
@callback_object = Object.new
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
specify "should be defined as a block and notified" do
|
|
9
|
-
specify_registration_and_notification do |callback_key, expected_callback|
|
|
10
|
-
@callback_object.register_callback(callback_key, &expected_callback)
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
specify "should be defined as a proc and notified" do
|
|
15
|
-
specify_registration_and_notification do |callback_key, expected_callback|
|
|
16
|
-
@callback_object.register_callback(callback_key, expected_callback)
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
specify "define should require callback with the call method" do
|
|
21
|
-
proc do
|
|
22
|
-
specify_registration_and_notification do |callback_key, expected_callback|
|
|
23
|
-
@callback_object.register_callback(callback_key)
|
|
24
|
-
end
|
|
25
|
-
end.should_raise(RuntimeError, "You must define the callback that accepts the call method.")
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
specify "should undefine a proc" do
|
|
29
|
-
specify_unregistration do |callback_key, callback|
|
|
30
|
-
@callback_object.unregister_callback callback_key, callback
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
specify "undefine should require callback with the call method" do
|
|
35
|
-
proc do
|
|
36
|
-
specify_unregistration do |callback_key, expected_callback|
|
|
37
|
-
@callback_object.unregister_callback(callback_key, nil)
|
|
38
|
-
end
|
|
39
|
-
end.should_raise(RuntimeError, "You may only undefine callbacks that use the call method.")
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
specify "should handle errors" do
|
|
43
|
-
@callback_object.register_callback(:error_callback) do
|
|
44
|
-
raise "First Error"
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
@callback_object.register_callback(:error_callback) do
|
|
48
|
-
raise "Second Error"
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
error_messages = []
|
|
52
|
-
@callback_object.notify_callbacks(:error_callback) do |e|
|
|
53
|
-
error_messages << e.message
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
error_messages.should_eql ["First Error", "Second Error"]
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
specify "should not fail with nothing to notify" do
|
|
60
|
-
@callback_object.notify_callbacks(:foobar, :argument)
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
protected
|
|
64
|
-
def specify_registration_and_notification
|
|
65
|
-
callback_key = :create
|
|
66
|
-
passed_callback_argument = nil
|
|
67
|
-
expected_callback = proc do |callback_argument|
|
|
68
|
-
passed_callback_argument = callback_argument
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
returned_callback = yield(callback_key, expected_callback)
|
|
72
|
-
returned_callback.should_equal expected_callback
|
|
73
|
-
|
|
74
|
-
expected_argument = Object.new
|
|
75
|
-
@callback_object.notify_callbacks(callback_key, expected_argument)
|
|
76
|
-
passed_callback_argument.should_equal expected_argument
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
def specify_unregistration
|
|
80
|
-
callback_key = :create
|
|
81
|
-
callback_called = false
|
|
82
|
-
callback = @callback_object.register_callback(callback_key) do
|
|
83
|
-
callback_called = true
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
yield(callback_key, callback)
|
|
87
|
-
@callback_object.notify_callbacks(callback_key)
|
|
88
|
-
callback_called.should_equal false
|
|
89
|
-
end
|
|
90
|
-
end
|