rspec 1.1.11 → 1.1.12
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/.autotest +4 -0
- data/History.txt +55 -0
- data/Manifest.txt +102 -122
- data/README.txt +30 -12
- data/Rakefile +10 -10
- data/TODO.txt +10 -2
- data/{failing_examples → examples/failing}/README.txt +0 -0
- data/{failing_examples → examples/failing}/diffing_spec.rb +0 -0
- data/{failing_examples → examples/failing}/failing_autogenerated_docstrings_example.rb +0 -0
- data/{failing_examples/failure_in_teardown.rb → examples/failing/failure_in_after.rb} +1 -1
- data/{failing_examples/failure_in_setup.rb → examples/failing/failure_in_before.rb} +1 -1
- data/{failing_examples → examples/failing}/mocking_example.rb +0 -0
- data/{failing_examples → examples/failing}/mocking_with_flexmock.rb +0 -0
- data/{failing_examples → examples/failing}/mocking_with_mocha.rb +0 -0
- data/{failing_examples → examples/failing}/mocking_with_rr.rb +0 -0
- data/{failing_examples → examples/failing}/partial_mock_example.rb +0 -0
- data/{failing_examples → examples/failing}/predicate_example.rb +5 -0
- data/{failing_examples → examples/failing}/raising_example.rb +0 -0
- data/{failing_examples → examples/failing}/spec_helper.rb +1 -1
- data/{failing_examples → examples/failing}/syntax_error_example.rb +0 -0
- data/{failing_examples → examples/failing}/team_spec.rb +0 -0
- data/{failing_examples → examples/failing}/timeout_behaviour.rb +0 -0
- data/examples/{pure → passing}/autogenerated_docstrings_example.rb +6 -0
- data/examples/{pure → passing}/before_and_after_example.rb +0 -0
- data/examples/{pure → passing}/behave_as_example.rb +0 -0
- data/examples/{pure → passing}/custom_expectation_matchers.rb +0 -0
- data/examples/{pure → passing}/custom_formatter.rb +1 -1
- data/examples/{pure → passing}/dynamic_spec.rb +2 -2
- data/examples/{pure → passing}/file_accessor.rb +0 -0
- data/examples/{pure → passing}/file_accessor_spec.rb +0 -0
- data/examples/{pure → passing}/greeter_spec.rb +0 -0
- data/examples/{pure → passing}/helper_method_example.rb +0 -0
- data/examples/{pure → passing}/io_processor.rb +0 -0
- data/examples/{pure → passing}/io_processor_spec.rb +0 -0
- data/examples/{pure → passing}/legacy_spec.rb +0 -0
- data/examples/{pure → passing}/mocking_example.rb +0 -0
- data/examples/{pure/multi_threaded_behaviour_runner.rb → passing/multi_threaded_example_group_runner.rb} +1 -3
- data/examples/{pure → passing}/nested_classes_example.rb +0 -0
- data/examples/{pure → passing}/partial_mock_example.rb +0 -0
- data/examples/{pure → passing}/pending_example.rb +0 -0
- data/examples/{pure → passing}/predicate_example.rb +0 -0
- data/examples/{pure → passing}/priority.txt +0 -0
- data/examples/{pure → passing}/shared_example_group_example.rb +0 -0
- data/examples/{pure → passing}/shared_stack_examples.rb +1 -3
- data/examples/passing/simple_matcher_example.rb +31 -0
- data/examples/{pure → passing}/spec_helper.rb +0 -0
- data/examples/{pure → passing}/stack.rb +0 -0
- data/examples/{pure → passing}/stack_spec.rb +3 -2
- data/examples/{pure → passing}/stack_spec_with_nested_example_groups.rb +0 -0
- data/examples/{pure → passing}/stubbing_example.rb +0 -0
- data/examples/{pure → passing}/yielding_example.rb +0 -0
- data/examples/ruby1.9.compatibility/access_to_constants_spec.rb +86 -0
- data/features/before_and_after_blocks/before_and_after_blocks.feature +168 -0
- data/{stories/example_groups/autogenerated_docstrings → features/example_groups/autogenerated_docstrings.feature} +5 -5
- data/{stories/example_groups/example_group_with_should_methods → features/example_groups/example_group_with_should_methods.feature} +3 -3
- data/{stories/example_groups/nested_groups → features/example_groups/nested_groups.feature} +4 -4
- data/{stories/example_groups/output → features/example_groups/output.feature} +3 -8
- data/{stories/interop/examples_and_tests_together → features/interop/examples_and_tests_together.feature} +5 -4
- data/features/interop/test_but_not_test_unit.feature +14 -0
- data/{stories/interop/test_case_with_should_methods → features/interop/test_case_with_should_methods.feature} +2 -2
- data/{stories/mock_framework_integration/use_flexmock.story → features/mock_framework_integration/use_flexmock.feature} +1 -1
- data/features/step_definitions/running_rspec.rb +54 -0
- data/features/support/env.rb +26 -0
- data/{stories/resources → features/support}/helpers/cmdline.rb +0 -0
- data/{stories/resources → features/support}/helpers/story_helper.rb +1 -1
- data/{stories/resources → features/support}/matchers/smart_match.rb +0 -0
- data/{plugins → lib/adapters}/mock_frameworks/flexmock.rb +1 -1
- data/{plugins → lib/adapters}/mock_frameworks/mocha.rb +1 -1
- data/{plugins → lib/adapters}/mock_frameworks/rr.rb +1 -1
- data/{plugins → lib/adapters}/mock_frameworks/rspec.rb +2 -2
- data/lib/autotest/rspec.rb +4 -3
- data/lib/spec.rb +2 -27
- data/lib/spec/dsl.rb +1 -0
- data/lib/spec/{extensions → dsl}/main.rb +10 -10
- data/lib/spec/example.rb +175 -1
- data/lib/spec/example/before_and_after_hooks.rb +30 -24
- data/lib/spec/example/example_group.rb +1 -0
- data/lib/spec/example/example_group_factory.rb +26 -9
- data/lib/spec/example/example_group_methods.rb +138 -113
- data/lib/spec/example/example_methods.rb +88 -25
- data/lib/spec/example/shared_example_group.rb +28 -21
- data/lib/spec/expectations.rb +22 -18
- data/lib/spec/expectations/handler.rb +16 -36
- data/lib/spec/interop/test/unit/testcase.rb +19 -17
- data/lib/spec/interop/test/unit/testresult.rb +1 -1
- data/lib/spec/interop/test/unit/testsuite_adapter.rb +1 -1
- data/lib/spec/matchers.rb +7 -28
- data/lib/spec/matchers/be.rb +103 -116
- data/lib/spec/matchers/be_close.rb +6 -22
- data/lib/spec/matchers/eql.rb +7 -25
- data/lib/spec/matchers/equal.rb +7 -25
- data/lib/spec/matchers/errors.rb +5 -0
- data/lib/spec/matchers/exist.rb +8 -14
- data/lib/spec/matchers/generated_descriptions.rb +48 -0
- data/lib/spec/matchers/has.rb +12 -28
- data/lib/spec/matchers/include.rb +12 -9
- data/lib/spec/matchers/match.rb +8 -27
- data/lib/spec/matchers/match_array.rb +79 -0
- data/lib/spec/matchers/method_missing.rb +9 -0
- data/lib/spec/matchers/operator_matcher.rb +39 -48
- data/lib/spec/matchers/raise_error.rb +4 -8
- data/lib/spec/matchers/respond_to.rb +33 -8
- data/lib/spec/matchers/throw_symbol.rb +49 -17
- data/lib/spec/matchers/wrap_expectation.rb +55 -0
- data/lib/spec/mocks/argument_constraints.rb +77 -5
- data/lib/spec/mocks/message_expectation.rb +7 -7
- data/lib/spec/mocks/proxy.rb +14 -12
- data/lib/spec/rake/spectask.rb +4 -6
- data/lib/spec/ruby.rb +9 -0
- data/lib/spec/runner.rb +37 -162
- data/lib/spec/runner/backtrace_tweaker.rb +5 -3
- data/lib/spec/runner/class_and_arguments_parser.rb +7 -9
- data/lib/spec/runner/command_line.rb +6 -8
- data/lib/spec/{example → runner}/configuration.rb +46 -47
- data/lib/spec/runner/example_group_runner.rb +15 -4
- data/lib/spec/runner/formatter/base_text_formatter.rb +4 -3
- data/lib/spec/runner/formatter/html_formatter.rb +14 -11
- data/lib/spec/runner/formatter/nested_text_formatter.rb +2 -2
- data/lib/spec/runner/heckle_runner.rb +58 -56
- data/lib/spec/runner/option_parser.rb +8 -4
- data/lib/spec/runner/options.rb +29 -14
- data/lib/spec/runner/reporter.rb +1 -1
- data/lib/spec/runner/spec_parser.rb +11 -9
- data/lib/spec/story/runner.rb +40 -42
- data/lib/spec/story/runner/story_runner.rb +10 -6
- data/lib/spec/story/world.rb +66 -70
- data/lib/spec/version.rb +4 -2
- data/{rake_tasks → resources/rake}/examples.rake +0 -0
- data/{rake_tasks → resources/rake}/examples_with_rcov.rake +0 -0
- data/{rake_tasks → resources/rake}/failing_examples_with_html.rake +0 -0
- data/{rake_tasks → resources/rake}/verify_rcov.rake +0 -0
- data/{stories/resources → resources}/spec/example_group_with_should_methods.rb +1 -1
- data/{stories/resources → resources}/spec/simple_spec.rb +1 -1
- data/resources/spec/spec_with_flexmock.rb +19 -0
- data/{stories/resources → resources}/test/spec_and_test_together.rb +1 -1
- data/resources/test/spec_including_test_but_not_unit.rb +11 -0
- data/{stories/resources → resources}/test/test_case_with_should_methods.rb +2 -2
- data/rspec.gemspec +16 -6
- data/spec/autotest/autotest_helper.rb +2 -2
- data/spec/autotest/discover_spec.rb +4 -15
- data/spec/autotest/failed_results_re_spec.rb +24 -0
- data/spec/autotest/rspec_spec.rb +2 -38
- data/spec/spec/dsl/main_spec.rb +88 -0
- data/spec/spec/example/example_group_class_definition_spec.rb +6 -2
- data/spec/spec/example/example_group_factory_spec.rb +50 -10
- data/spec/spec/example/example_group_methods_spec.rb +210 -160
- data/spec/spec/example/example_group_spec.rb +44 -52
- data/spec/spec/example/example_matcher_spec.rb +6 -23
- data/spec/spec/example/example_methods_spec.rb +176 -54
- data/spec/spec/example/helper_method_spec.rb +24 -0
- data/spec/spec/example/pending_module_spec.rb +2 -8
- data/spec/spec/example/shared_example_group_spec.rb +56 -80
- data/spec/spec/expectations/extensions/object_spec.rb +0 -50
- data/spec/spec/expectations/wrap_expectation_spec.rb +30 -0
- data/spec/spec/interop/test/unit/spec_spec.rb +1 -5
- data/spec/spec/interop/test/unit/test_unit_spec_helper.rb +4 -0
- data/spec/spec/matchers/be_close_spec.rb +12 -10
- data/spec/spec/matchers/be_spec.rb +62 -7
- data/spec/spec/matchers/description_generation_spec.rb +19 -0
- data/spec/spec/matchers/eql_spec.rb +7 -6
- data/spec/spec/matchers/equal_spec.rb +7 -6
- data/spec/spec/matchers/handler_spec.rb +4 -43
- data/spec/spec/matchers/has_spec.rb +1 -1
- data/spec/spec/matchers/have_spec.rb +23 -18
- data/spec/spec/matchers/include_spec.rb +24 -0
- data/spec/spec/matchers/match_array_spec.rb +83 -0
- data/spec/spec/matchers/matcher_methods_spec.rb +1 -13
- data/spec/spec/matchers/raise_error_spec.rb +18 -0
- data/spec/spec/matchers/respond_to_spec.rb +71 -9
- data/spec/spec/matchers/throw_symbol_spec.rb +85 -43
- data/spec/spec/mocks/bug_report_11545_spec.rb +4 -5
- data/spec/spec/mocks/bug_report_496.rb +11 -9
- data/spec/spec/mocks/bug_report_600_spec.rb +22 -0
- data/spec/spec/mocks/hash_including_matcher_spec.rb +39 -2
- data/spec/spec/mocks/hash_not_including_matcher_spec.rb +67 -0
- data/spec/spec/mocks/mock_spec.rb +5 -6
- data/spec/spec/mocks/nil_expectation_warning_spec.rb +2 -2
- data/spec/spec/mocks/passing_mock_argument_constraints_spec.rb +18 -3
- data/spec/spec/mocks/stub_spec.rb +6 -0
- data/spec/spec/mocks/stubbed_message_expectations_spec.rb +14 -0
- data/spec/spec/runner/command_line_spec.rb +4 -4
- data/spec/spec/runner/configuration_spec.rb +301 -0
- data/spec/spec/runner/drb_command_line_spec.rb +4 -4
- data/spec/spec/runner/example_group_runner_spec.rb +33 -0
- data/spec/spec/runner/formatter/base_formatter_spec.rb +13 -102
- data/spec/spec/runner/formatter/base_text_formatter_spec.rb +23 -0
- data/spec/spec/runner/formatter/failing_example_groups_formatter_spec.rb +5 -5
- data/spec/spec/runner/formatter/failing_examples_formatter_spec.rb +3 -3
- data/spec/spec/runner/formatter/html_formatted-1.8.4.html +6 -6
- data/spec/spec/runner/formatter/html_formatted-1.8.5-jruby.html +9 -9
- data/spec/spec/runner/formatter/html_formatted-1.8.5.html +6 -6
- data/spec/spec/runner/formatter/html_formatted-1.8.6-jruby.html +10 -10
- data/spec/spec/runner/formatter/html_formatted-1.8.6.html +39 -30
- data/spec/spec/runner/formatter/html_formatted-1.8.7.html +379 -0
- data/spec/spec/runner/formatter/html_formatted-1.9.1.html +379 -0
- data/spec/spec/runner/formatter/html_formatter_spec.rb +14 -13
- data/spec/spec/runner/formatter/nested_text_formatter_spec.rb +5 -5
- data/spec/spec/runner/formatter/progress_bar_formatter_spec.rb +7 -17
- data/spec/spec/runner/formatter/spec_mate_formatter_spec.rb +18 -17
- data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +5 -5
- data/spec/spec/runner/formatter/text_mate_formatted-1.8.4.html +6 -6
- data/spec/spec/runner/formatter/text_mate_formatted-1.8.6.html +33 -30
- data/spec/spec/runner/formatter/text_mate_formatted-1.8.7.html +373 -0
- data/spec/spec/runner/formatter/text_mate_formatted-1.9.1.html +373 -0
- data/spec/spec/runner/heckler_spec.rb +16 -9
- data/spec/spec/runner/option_parser_spec.rb +3 -18
- data/spec/spec/runner/options_spec.rb +27 -8
- data/spec/spec/runner/reporter_spec.rb +5 -5
- data/spec/spec/runner/resources/custom_example_group_runner.rb +14 -0
- data/spec/spec/runner/resources/utf8_encoded.rb +7 -0
- data/spec/spec/runner/spec_parser_spec.rb +85 -79
- data/spec/spec/spec_spec.rb +21 -0
- data/spec/spec_helper.rb +9 -1
- data/story_server/prototype/javascripts/prototype.js +1 -1
- metadata +119 -131
- data/examples/stories/adder.rb +0 -13
- data/examples/stories/addition +0 -34
- data/examples/stories/addition.rb +0 -9
- data/examples/stories/calculator.rb +0 -65
- data/examples/stories/game-of-life/.loadpath +0 -5
- data/examples/stories/game-of-life/README.txt +0 -21
- data/examples/stories/game-of-life/behaviour/everything.rb +0 -6
- data/examples/stories/game-of-life/behaviour/examples/examples.rb +0 -3
- data/examples/stories/game-of-life/behaviour/examples/game_behaviour.rb +0 -35
- data/examples/stories/game-of-life/behaviour/examples/grid_behaviour.rb +0 -66
- data/examples/stories/game-of-life/behaviour/stories/CellsWithLessThanTwoNeighboursDie.story +0 -21
- data/examples/stories/game-of-life/behaviour/stories/CellsWithMoreThanThreeNeighboursDie.story +0 -21
- data/examples/stories/game-of-life/behaviour/stories/EmptySpacesWithThreeNeighboursCreateACell.story +0 -42
- data/examples/stories/game-of-life/behaviour/stories/ICanCreateACell.story +0 -42
- data/examples/stories/game-of-life/behaviour/stories/ICanKillACell.story +0 -17
- data/examples/stories/game-of-life/behaviour/stories/TheGridWraps.story +0 -53
- data/examples/stories/game-of-life/behaviour/stories/create_a_cell.rb +0 -52
- data/examples/stories/game-of-life/behaviour/stories/helper.rb +0 -6
- data/examples/stories/game-of-life/behaviour/stories/kill_a_cell.rb +0 -26
- data/examples/stories/game-of-life/behaviour/stories/steps.rb +0 -5
- data/examples/stories/game-of-life/behaviour/stories/stories.rb +0 -3
- data/examples/stories/game-of-life/behaviour/stories/stories.txt +0 -22
- data/examples/stories/game-of-life/life.rb +0 -3
- data/examples/stories/game-of-life/life/game.rb +0 -23
- data/examples/stories/game-of-life/life/grid.rb +0 -43
- data/examples/stories/helper.rb +0 -9
- data/examples/stories/steps/addition_steps.rb +0 -18
- data/lib/spec/adapters.rb +0 -1
- data/lib/spec/adapters/ruby_engine.rb +0 -26
- data/lib/spec/adapters/ruby_engine/mri.rb +0 -8
- data/lib/spec/adapters/ruby_engine/rubinius.rb +0 -8
- data/lib/spec/extensions.rb +0 -4
- data/lib/spec/extensions/class.rb +0 -24
- data/lib/spec/extensions/metaclass.rb +0 -7
- data/lib/spec/extensions/object.rb +0 -6
- data/spec/spec/adapters/ruby_engine_spec.rb +0 -16
- data/spec/spec/example/configuration_spec.rb +0 -296
- data/spec/spec/example/example_runner_spec.rb +0 -194
- data/spec/spec/extensions/main_spec.rb +0 -71
- data/stories/all.rb +0 -5
- data/stories/configuration/before_blocks.story +0 -21
- data/stories/configuration/stories.rb +0 -7
- data/stories/example_groups/stories.rb +0 -7
- data/stories/helper.rb +0 -6
- data/stories/interop/stories.rb +0 -7
- data/stories/mock_framework_integration/stories.rb +0 -7
- data/stories/pending_stories/README +0 -3
- data/stories/resources/spec/before_blocks_example.rb +0 -32
- data/stories/resources/spec/spec_with_flexmock.rb +0 -18
- data/stories/resources/steps/running_rspec.rb +0 -50
- data/stories/resources/stories/failing_story.rb +0 -15
- data/stories/stories/multiline_steps.story +0 -23
- data/stories/stories/steps/multiline_steps.rb +0 -13
- data/stories/stories/stories.rb +0 -6
@@ -1,41 +1,44 @@
|
|
1
1
|
module Spec
|
2
2
|
module Example
|
3
3
|
module BeforeAndAfterHooks
|
4
|
+
class << self
|
5
|
+
def before_suite_parts
|
6
|
+
@before_suite_parts ||= []
|
7
|
+
end
|
8
|
+
|
9
|
+
def after_suite_parts
|
10
|
+
@after_suite_parts ||= []
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
4
14
|
# Registers a block to be executed before each example.
|
5
15
|
# This method prepends +block+ to existing before blocks.
|
6
16
|
def prepend_before(*args, &block)
|
7
|
-
|
8
|
-
parts = before_parts_from_scope(scope)
|
9
|
-
parts.unshift(block)
|
17
|
+
before_parts(*args).unshift(block)
|
10
18
|
end
|
11
19
|
|
12
20
|
# Registers a block to be executed before each example.
|
13
21
|
# This method appends +block+ to existing before blocks.
|
14
22
|
def append_before(*args, &block)
|
15
|
-
|
16
|
-
parts = before_parts_from_scope(scope)
|
17
|
-
parts << block
|
23
|
+
before_parts(*args) << block
|
18
24
|
end
|
19
25
|
alias_method :before, :append_before
|
20
26
|
|
21
27
|
# Registers a block to be executed after each example.
|
22
28
|
# This method prepends +block+ to existing after blocks.
|
23
29
|
def prepend_after(*args, &block)
|
24
|
-
|
25
|
-
parts = after_parts_from_scope(scope)
|
26
|
-
parts.unshift(block)
|
30
|
+
after_parts(*args).unshift(block)
|
27
31
|
end
|
28
32
|
alias_method :after, :prepend_after
|
29
33
|
|
30
34
|
# Registers a block to be executed after each example.
|
31
35
|
# This method appends +block+ to existing after blocks.
|
32
36
|
def append_after(*args, &block)
|
33
|
-
|
34
|
-
parts = after_parts_from_scope(scope)
|
35
|
-
parts << block
|
37
|
+
after_parts(*args) << block
|
36
38
|
end
|
37
39
|
|
38
|
-
|
40
|
+
# TODO - deprecate this unless there is a reason why it exists
|
41
|
+
def remove_after(scope, &block) # :nodoc:
|
39
42
|
after_each_parts.delete(block)
|
40
43
|
end
|
41
44
|
|
@@ -65,26 +68,29 @@ module Spec
|
|
65
68
|
@after_each_parts ||= []
|
66
69
|
end
|
67
70
|
|
68
|
-
|
71
|
+
def before_suite_parts
|
72
|
+
BeforeAndAfterHooks.before_suite_parts
|
73
|
+
end
|
69
74
|
|
70
|
-
def
|
71
|
-
|
72
|
-
scope = (args[0] || :each), options
|
75
|
+
def after_suite_parts
|
76
|
+
BeforeAndAfterHooks.after_suite_parts
|
73
77
|
end
|
74
|
-
|
75
|
-
|
76
|
-
|
78
|
+
|
79
|
+
private
|
80
|
+
|
81
|
+
def before_parts(*args)
|
82
|
+
case Spec::Example.scope_from(*args)
|
77
83
|
when :each; before_each_parts
|
78
84
|
when :all; before_all_parts
|
79
|
-
when :suite;
|
85
|
+
when :suite; before_suite_parts
|
80
86
|
end
|
81
87
|
end
|
82
88
|
|
83
|
-
def
|
84
|
-
case
|
89
|
+
def after_parts(*args)
|
90
|
+
case Spec::Example.scope_from(*args)
|
85
91
|
when :each; after_each_parts
|
86
92
|
when :all; after_all_parts
|
87
|
-
when :suite;
|
93
|
+
when :suite; after_suite_parts
|
88
94
|
end
|
89
95
|
end
|
90
96
|
|
@@ -1,15 +1,17 @@
|
|
1
1
|
module Spec
|
2
2
|
module Example
|
3
3
|
class ExampleGroupFactory
|
4
|
-
|
4
|
+
module ClassMethods
|
5
5
|
def reset
|
6
6
|
@example_group_types = nil
|
7
7
|
default(ExampleGroup)
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
10
|
+
def registered_or_ancestor_of_registered?(example_group_classes) # :nodoc:
|
11
11
|
example_group_classes.each do |example_group_class|
|
12
|
-
return false unless
|
12
|
+
return false unless registered_types.any? do |registered_type|
|
13
|
+
registered_type.ancestors.include? example_group_class
|
14
|
+
end
|
13
15
|
end
|
14
16
|
return true
|
15
17
|
end
|
@@ -48,10 +50,28 @@ module Spec
|
|
48
50
|
end
|
49
51
|
|
50
52
|
def create_example_group(*args, &block)
|
51
|
-
|
52
|
-
|
53
|
+
raise ArgumentError if args.empty?
|
54
|
+
raise ArgumentError unless block
|
55
|
+
Spec::Example::add_spec_path_to(args)
|
56
|
+
superclass = determine_superclass(args.last)
|
53
57
|
superclass.describe(*args, &block)
|
54
58
|
end
|
59
|
+
|
60
|
+
def create_shared_example_group(*args, &block)
|
61
|
+
Spec::Example::add_spec_path_to(args)
|
62
|
+
SharedExampleGroup.register(*args, &block)
|
63
|
+
end
|
64
|
+
|
65
|
+
def include_constants_in(context, &block)
|
66
|
+
if (Spec::Ruby.version.to_f >= 1.9 && Module === context && !(Class === context))
|
67
|
+
return lambda {include context;instance_eval(&block)}
|
68
|
+
end
|
69
|
+
block
|
70
|
+
end
|
71
|
+
|
72
|
+
def assign_scope(scope, args)
|
73
|
+
args.last[:scope] = scope
|
74
|
+
end
|
55
75
|
|
56
76
|
protected
|
57
77
|
|
@@ -66,15 +86,12 @@ module Spec
|
|
66
86
|
|
67
87
|
private
|
68
88
|
|
69
|
-
def registered_or_ancestor_of_registered? example_group_class
|
70
|
-
registered_types.any? {|registered_type| registered_type.ancestors.include? example_group_class}
|
71
|
-
end
|
72
|
-
|
73
89
|
def registered_types
|
74
90
|
@example_group_types.values
|
75
91
|
end
|
76
92
|
|
77
93
|
end
|
94
|
+
extend ClassMethods
|
78
95
|
self.reset
|
79
96
|
end
|
80
97
|
end
|
@@ -2,30 +2,53 @@ module Spec
|
|
2
2
|
module Example
|
3
3
|
|
4
4
|
module ExampleGroupMethods
|
5
|
-
include Spec::Example::BeforeAndAfterHooks
|
6
|
-
|
7
5
|
class << self
|
8
6
|
attr_accessor :matcher_class
|
9
7
|
|
10
8
|
def description_text(*args)
|
11
|
-
args.inject("") do |
|
12
|
-
|
13
|
-
|
9
|
+
args.inject("") do |description, arg|
|
10
|
+
description << " " unless (description == "" || arg.to_s =~ /^(\s|\.|#)/)
|
11
|
+
description << arg.to_s
|
14
12
|
end
|
15
13
|
end
|
14
|
+
|
15
|
+
def example_group_creation_listeners
|
16
|
+
@example_group_creation_listeners ||= []
|
17
|
+
end
|
16
18
|
end
|
17
19
|
|
18
|
-
|
20
|
+
include Spec::Example::BeforeAndAfterHooks
|
21
|
+
|
22
|
+
attr_reader :description_options, :spec_path
|
19
23
|
alias :options :description_options
|
20
24
|
|
25
|
+
# Provides the backtrace up to where this example_group was declared.
|
26
|
+
def backtrace
|
27
|
+
@backtrace
|
28
|
+
end
|
29
|
+
|
30
|
+
# Deprecated - use +backtrace()+
|
31
|
+
def example_group_backtrace
|
32
|
+
Kernel.warn <<-WARNING
|
33
|
+
ExampleGroupMethods#example_group_backtrace is deprecated and will be removed
|
34
|
+
from a future version. Please use ExampleGroupMethods#backtrace instead.
|
35
|
+
WARNING
|
36
|
+
backtrace
|
37
|
+
end
|
38
|
+
|
21
39
|
def description_args
|
22
40
|
@description_args ||= []
|
23
41
|
end
|
24
42
|
|
25
43
|
def inherited(klass)
|
26
44
|
super
|
27
|
-
klass
|
28
|
-
|
45
|
+
register_example_group(klass)
|
46
|
+
end
|
47
|
+
|
48
|
+
def register_example_group(klass)
|
49
|
+
ExampleGroupMethods.example_group_creation_listeners.each do |l|
|
50
|
+
l.register_example_group(klass)
|
51
|
+
end
|
29
52
|
end
|
30
53
|
|
31
54
|
# Makes the describe/it syntax available from a class. For example:
|
@@ -43,14 +66,13 @@ module Spec
|
|
43
66
|
# end
|
44
67
|
#
|
45
68
|
def describe(*args, &example_group_block)
|
46
|
-
args << {} unless Hash === args.last
|
47
69
|
if example_group_block
|
70
|
+
Spec::Example::add_spec_path_to(args)
|
48
71
|
options = args.last
|
49
|
-
options[:spec_path] = eval("caller(0)[1]", example_group_block) unless options[:spec_path]
|
50
72
|
if options[:shared]
|
51
|
-
create_shared_example_group(args, example_group_block)
|
73
|
+
create_shared_example_group(*args, &example_group_block)
|
52
74
|
else
|
53
|
-
|
75
|
+
create_example_group_subclass(*args, &example_group_block)
|
54
76
|
end
|
55
77
|
else
|
56
78
|
set_description(*args)
|
@@ -58,19 +80,27 @@ module Spec
|
|
58
80
|
end
|
59
81
|
alias :context :describe
|
60
82
|
|
61
|
-
def create_shared_example_group(args, example_group_block)
|
62
|
-
SharedExampleGroup.
|
83
|
+
def create_shared_example_group(*args, &example_group_block) # :nodoc:
|
84
|
+
SharedExampleGroup.register(*args, &example_group_block)
|
63
85
|
end
|
64
86
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
87
|
+
# Creates a new subclass of self, with a name "under" our own name.
|
88
|
+
# Example:
|
89
|
+
#
|
90
|
+
# x = Foo::Bar.subclass('Zap'){}
|
91
|
+
# x.name # => Foo::Bar::Zap_1
|
92
|
+
# x.superclass.name # => Foo::Bar
|
93
|
+
def create_example_group_subclass(*args, &example_group_block) # :nodoc:
|
94
|
+
@class_count ||= 0
|
95
|
+
@class_count += 1
|
96
|
+
klass = const_set("Subclass_#{@class_count}", Class.new(self))
|
97
|
+
klass.set_description(*args)
|
98
|
+
example_group_block = ExampleGroupFactory.include_constants_in(args.last[:scope], &example_group_block)
|
99
|
+
klass.module_eval(&example_group_block)
|
100
|
+
klass
|
70
101
|
end
|
71
102
|
|
72
103
|
# Use this to pull in examples from shared example groups.
|
73
|
-
# See Spec::Runner for information about shared example groups.
|
74
104
|
def it_should_behave_like(*shared_example_groups)
|
75
105
|
shared_example_groups.each do |group|
|
76
106
|
include_shared_example_group(group)
|
@@ -85,7 +115,7 @@ module Spec
|
|
85
115
|
# a predicate on your class. RSpec provides a couple of these
|
86
116
|
# out of the box:
|
87
117
|
#
|
88
|
-
# exist (
|
118
|
+
# exist (for state expectations)
|
89
119
|
# File.should exist("path/to/file")
|
90
120
|
#
|
91
121
|
# an_instance_of (for mock argument constraints)
|
@@ -106,7 +136,7 @@ module Spec
|
|
106
136
|
# end
|
107
137
|
# end
|
108
138
|
def predicate_matchers
|
109
|
-
@predicate_matchers ||= {
|
139
|
+
@predicate_matchers ||= {}
|
110
140
|
end
|
111
141
|
|
112
142
|
# Creates an instance of the current example group class and adds it to
|
@@ -128,54 +158,69 @@ module Spec
|
|
128
158
|
alias_method :xit, :xexample
|
129
159
|
alias_method :xspecify, :xexample
|
130
160
|
|
131
|
-
def run
|
132
|
-
examples = examples_to_run
|
133
|
-
reporter.add_example_group(self) unless
|
161
|
+
def run(run_options)
|
162
|
+
examples = examples_to_run(run_options)
|
163
|
+
run_options.reporter.add_example_group(self) unless examples.empty?
|
134
164
|
return true if examples.empty?
|
135
|
-
return dry_run(examples) if dry_run?
|
165
|
+
return dry_run(examples, run_options) if run_options.dry_run?
|
136
166
|
|
137
|
-
plugin_mock_framework
|
138
|
-
define_methods_from_predicate_matchers
|
167
|
+
plugin_mock_framework(run_options)
|
168
|
+
define_methods_from_predicate_matchers(run_options)
|
139
169
|
|
140
|
-
success, before_all_instance_variables = run_before_all
|
141
|
-
success, after_all_instance_variables = execute_examples(success, before_all_instance_variables, examples)
|
142
|
-
success = run_after_all(success, after_all_instance_variables)
|
170
|
+
success, before_all_instance_variables = run_before_all(run_options)
|
171
|
+
success, after_all_instance_variables = execute_examples(success, before_all_instance_variables, examples, run_options)
|
172
|
+
success = run_after_all(success, after_all_instance_variables, run_options)
|
143
173
|
end
|
144
174
|
|
145
175
|
def description
|
146
176
|
result = ExampleGroupMethods.description_text(*description_parts)
|
147
|
-
|
148
|
-
return to_s
|
149
|
-
else
|
150
|
-
result
|
151
|
-
end
|
177
|
+
(result.nil? || result == "") ? to_s : result
|
152
178
|
end
|
153
|
-
|
179
|
+
|
154
180
|
def described_type
|
155
|
-
description_parts.find {|part| part.is_a?(Module)}
|
181
|
+
description_parts.reverse.find {|part| part.is_a?(Module)}
|
156
182
|
end
|
157
|
-
|
183
|
+
|
184
|
+
# Defines an explicit subject for an example group which can then be the
|
185
|
+
# implicit receiver (through delegation) of calls to +should+.
|
186
|
+
#
|
187
|
+
# == Examples
|
188
|
+
#
|
189
|
+
# describe CheckingAccount, "with $50" do
|
190
|
+
# subject { CheckingAccount.new(:amount => 50, :currency => :USD) }
|
191
|
+
# it { should have_a_balance_of(50, :USD)}
|
192
|
+
# it { should_not be_overdrawn}
|
193
|
+
# end
|
194
|
+
#
|
195
|
+
# See +ExampleMethods#should+ for more information about this approach.
|
196
|
+
def subject(&block)
|
197
|
+
@_subject_block = block
|
198
|
+
end
|
199
|
+
|
200
|
+
def subject_block
|
201
|
+
@_subject_block || lambda {nil}
|
202
|
+
end
|
203
|
+
|
158
204
|
def description_parts #:nodoc:
|
159
|
-
parts
|
160
|
-
|
161
|
-
parts << example_group_class.description_args
|
205
|
+
example_group_hierarchy.inject([]) do |parts, example_group_class|
|
206
|
+
[parts << example_group_class.description_args].flatten
|
162
207
|
end
|
163
|
-
parts.flatten.compact
|
164
208
|
end
|
165
209
|
|
166
210
|
def set_description(*args)
|
167
|
-
args, options = args_and_options(*args)
|
211
|
+
args, options = Spec::Example.args_and_options(*args)
|
168
212
|
@description_args = args
|
169
213
|
@description_options = options
|
170
214
|
@description_text = ExampleGroupMethods.description_text(*args)
|
215
|
+
@backtrace = caller(1)
|
171
216
|
@spec_path = File.expand_path(options[:spec_path]) if options[:spec_path]
|
172
217
|
self
|
173
218
|
end
|
174
219
|
|
175
|
-
def examples #:nodoc:
|
220
|
+
def examples(run_options=nil) #:nodoc:
|
176
221
|
examples = example_objects.dup
|
177
222
|
add_method_examples(examples)
|
178
|
-
|
223
|
+
(run_options && run_options.reverse) ? examples.reverse : examples
|
179
224
|
end
|
180
225
|
|
181
226
|
def number_of_examples #:nodoc:
|
@@ -190,136 +235,116 @@ module Spec
|
|
190
235
|
@after_each_parts = nil
|
191
236
|
end
|
192
237
|
|
193
|
-
def register(®istration_binding_block)
|
194
|
-
@registration_binding_block = registration_binding_block
|
195
|
-
Spec::Runner.options.add_example_group self
|
196
|
-
end
|
197
|
-
|
198
|
-
def unregister #:nodoc:
|
199
|
-
Spec::Runner.options.remove_example_group self
|
200
|
-
end
|
201
|
-
|
202
|
-
def registration_backtrace
|
203
|
-
eval("caller", @registration_binding_block)
|
204
|
-
end
|
205
|
-
|
206
238
|
def run_before_each(example)
|
207
|
-
|
208
|
-
|
239
|
+
example.eval_each_fail_fast(all_before_each_parts)
|
240
|
+
end
|
241
|
+
|
242
|
+
def all_before_each_parts
|
243
|
+
unless @all_before_each_parts
|
244
|
+
@all_before_each_parts = []
|
245
|
+
example_group_hierarchy.each do |example_group_class|
|
246
|
+
@all_before_each_parts += example_group_class.before_each_parts
|
247
|
+
end
|
209
248
|
end
|
249
|
+
@all_before_each_parts
|
210
250
|
end
|
211
251
|
|
212
252
|
def run_after_each(example)
|
213
|
-
|
253
|
+
example_group_hierarchy.reverse.each do |example_group_class|
|
214
254
|
example.eval_each_fail_slow(example_group_class.after_each_parts)
|
215
255
|
end
|
216
256
|
end
|
217
257
|
|
218
258
|
private
|
219
|
-
def dry_run(examples)
|
259
|
+
def dry_run(examples, run_options)
|
220
260
|
examples.each do |example|
|
221
|
-
|
222
|
-
|
261
|
+
run_options.reporter.example_started(example)
|
262
|
+
run_options.reporter.example_finished(example)
|
223
263
|
end
|
224
|
-
return true
|
225
264
|
end
|
226
265
|
|
227
|
-
def run_before_all
|
266
|
+
def run_before_all(run_options)
|
228
267
|
before_all = new("before(:all)")
|
229
268
|
begin
|
230
|
-
|
269
|
+
example_group_hierarchy.each do |example_group_class|
|
231
270
|
before_all.eval_each_fail_fast(example_group_class.before_all_parts)
|
232
271
|
end
|
233
272
|
return [true, before_all.instance_variable_hash]
|
234
273
|
rescue Exception => e
|
235
|
-
reporter.failure(before_all, e)
|
274
|
+
run_options.reporter.failure(before_all, e)
|
236
275
|
return [false, before_all.instance_variable_hash]
|
237
276
|
end
|
238
277
|
end
|
239
278
|
|
240
|
-
def execute_examples(success, instance_variables, examples)
|
279
|
+
def execute_examples(success, instance_variables, examples, run_options)
|
241
280
|
return [success, instance_variables] unless success
|
242
281
|
|
243
282
|
after_all_instance_variables = instance_variables
|
244
283
|
examples.each do |example_group_instance|
|
245
|
-
success &= example_group_instance.execute(
|
284
|
+
success &= example_group_instance.execute(run_options, instance_variables)
|
246
285
|
after_all_instance_variables = example_group_instance.instance_variable_hash
|
247
286
|
end
|
248
287
|
return [success, after_all_instance_variables]
|
249
288
|
end
|
250
289
|
|
251
|
-
def run_after_all(success, instance_variables)
|
290
|
+
def run_after_all(success, instance_variables, run_options)
|
252
291
|
after_all = new("after(:all)")
|
253
292
|
after_all.set_instance_variables_from_hash(instance_variables)
|
254
|
-
|
293
|
+
example_group_hierarchy.reverse.each do |example_group_class|
|
255
294
|
after_all.eval_each_fail_slow(example_group_class.after_all_parts)
|
256
295
|
end
|
257
296
|
return success
|
258
297
|
rescue Exception => e
|
259
|
-
reporter.failure(after_all, e)
|
298
|
+
run_options.reporter.failure(after_all, e)
|
260
299
|
return false
|
261
300
|
end
|
262
301
|
|
263
|
-
def examples_to_run
|
264
|
-
all_examples = examples
|
265
|
-
return all_examples unless specified_examples?
|
302
|
+
def examples_to_run(run_options)
|
303
|
+
all_examples = examples(run_options)
|
304
|
+
return all_examples unless specified_examples?(run_options)
|
266
305
|
all_examples.reject do |example|
|
267
306
|
matcher = ExampleGroupMethods.matcher_class.
|
268
307
|
new(description.to_s, example.description)
|
269
|
-
!matcher.matches?(
|
308
|
+
!matcher.matches?(run_options.examples)
|
270
309
|
end
|
271
310
|
end
|
272
311
|
|
273
|
-
def specified_examples?
|
274
|
-
|
275
|
-
end
|
276
|
-
|
277
|
-
def specified_examples
|
278
|
-
Spec::Runner.options.examples
|
279
|
-
end
|
280
|
-
|
281
|
-
def reporter
|
282
|
-
Spec::Runner.options.reporter
|
283
|
-
end
|
284
|
-
|
285
|
-
def dry_run?
|
286
|
-
Spec::Runner.options.dry_run
|
312
|
+
def specified_examples?(run_options)
|
313
|
+
run_options.examples && !run_options.examples.empty?
|
287
314
|
end
|
288
315
|
|
289
316
|
def example_objects
|
290
317
|
@example_objects ||= []
|
291
318
|
end
|
292
319
|
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
classes.each do |example_group|
|
302
|
-
yield example_group
|
320
|
+
class ExampleGroupHierarchy < Array
|
321
|
+
def initialize(example_group_class)
|
322
|
+
current_class = example_group_class
|
323
|
+
while current_class.kind_of?(ExampleGroupMethods)
|
324
|
+
unshift(current_class)
|
325
|
+
break unless current_class.respond_to? :superclass
|
326
|
+
current_class = current_class.superclass
|
327
|
+
end
|
303
328
|
end
|
304
329
|
end
|
305
|
-
|
306
|
-
def
|
307
|
-
|
330
|
+
|
331
|
+
def example_group_hierarchy
|
332
|
+
@example_group_hierarchy ||= ExampleGroupHierarchy.new(self)
|
308
333
|
end
|
309
334
|
|
310
|
-
def plugin_mock_framework
|
311
|
-
case mock_framework =
|
335
|
+
def plugin_mock_framework(run_options)
|
336
|
+
case mock_framework = run_options.mock_framework
|
312
337
|
when Module
|
313
338
|
include mock_framework
|
314
339
|
else
|
315
|
-
require
|
316
|
-
include Spec::
|
340
|
+
require mock_framework
|
341
|
+
include Spec::Adapters::MockFramework
|
317
342
|
end
|
318
343
|
end
|
319
344
|
|
320
|
-
def define_methods_from_predicate_matchers # :nodoc:
|
345
|
+
def define_methods_from_predicate_matchers(run_options) # :nodoc:
|
321
346
|
all_predicate_matchers = predicate_matchers.merge(
|
322
|
-
|
347
|
+
run_options.predicate_matchers
|
323
348
|
)
|
324
349
|
all_predicate_matchers.each_pair do |matcher_method, method_on_object|
|
325
350
|
define_method matcher_method do |*args|
|
@@ -329,7 +354,7 @@ module Spec
|
|
329
354
|
end
|
330
355
|
|
331
356
|
def add_method_examples(examples)
|
332
|
-
instance_methods.
|
357
|
+
instance_methods.each do |method_name|
|
333
358
|
if example_method?(method_name)
|
334
359
|
examples << new(method_name) do
|
335
360
|
__send__(method_name)
|
@@ -354,7 +379,7 @@ module Spec
|
|
354
379
|
when SharedExampleGroup
|
355
380
|
include shared_example_group
|
356
381
|
else
|
357
|
-
example_group = SharedExampleGroup.
|
382
|
+
example_group = SharedExampleGroup.find(shared_example_group)
|
358
383
|
unless example_group
|
359
384
|
raise RuntimeError.new("Shared Example Group '#{shared_example_group}' can not be found")
|
360
385
|
end
|