newbamboo-rspec 1.1.12
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +4 -0
- data/History.txt +1263 -0
- data/License.txt +22 -0
- data/Manifest.txt +327 -0
- data/README.txt +57 -0
- data/Rakefile +104 -0
- data/TODO.txt +18 -0
- data/bin/autospec +4 -0
- data/bin/spec +4 -0
- data/examples/failing/README.txt +7 -0
- data/examples/failing/diffing_spec.rb +36 -0
- data/examples/failing/failing_autogenerated_docstrings_example.rb +19 -0
- data/examples/failing/failure_in_after.rb +10 -0
- data/examples/failing/failure_in_before.rb +10 -0
- data/examples/failing/mocking_example.rb +40 -0
- data/examples/failing/mocking_with_flexmock.rb +26 -0
- data/examples/failing/mocking_with_mocha.rb +25 -0
- data/examples/failing/mocking_with_rr.rb +27 -0
- data/examples/failing/partial_mock_example.rb +20 -0
- data/examples/failing/predicate_example.rb +34 -0
- data/examples/failing/raising_example.rb +47 -0
- data/examples/failing/spec_helper.rb +3 -0
- data/examples/failing/syntax_error_example.rb +7 -0
- data/examples/failing/team_spec.rb +44 -0
- data/examples/failing/timeout_behaviour.rb +7 -0
- data/examples/passing/autogenerated_docstrings_example.rb +25 -0
- data/examples/passing/before_and_after_example.rb +40 -0
- data/examples/passing/behave_as_example.rb +45 -0
- data/examples/passing/custom_expectation_matchers.rb +54 -0
- data/examples/passing/custom_formatter.rb +12 -0
- data/examples/passing/dynamic_spec.rb +9 -0
- data/examples/passing/file_accessor.rb +19 -0
- data/examples/passing/file_accessor_spec.rb +38 -0
- data/examples/passing/greeter_spec.rb +31 -0
- data/examples/passing/helper_method_example.rb +14 -0
- data/examples/passing/io_processor.rb +8 -0
- data/examples/passing/io_processor_spec.rb +21 -0
- data/examples/passing/legacy_spec.rb +11 -0
- data/examples/passing/mocking_example.rb +27 -0
- data/examples/passing/multi_threaded_example_group_runner.rb +26 -0
- data/examples/passing/nested_classes_example.rb +36 -0
- data/examples/passing/partial_mock_example.rb +29 -0
- data/examples/passing/pending_example.rb +20 -0
- data/examples/passing/predicate_example.rb +27 -0
- data/examples/passing/priority.txt +1 -0
- data/examples/passing/shared_example_group_example.rb +81 -0
- data/examples/passing/shared_stack_examples.rb +36 -0
- data/examples/passing/simple_matcher_example.rb +31 -0
- data/examples/passing/spec_helper.rb +3 -0
- data/examples/passing/stack.rb +36 -0
- data/examples/passing/stack_spec.rb +64 -0
- data/examples/passing/stack_spec_with_nested_example_groups.rb +67 -0
- data/examples/passing/stubbing_example.rb +69 -0
- data/examples/passing/yielding_example.rb +33 -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/features/example_groups/autogenerated_docstrings.feature +45 -0
- data/features/example_groups/example_group_with_should_methods.feature +17 -0
- data/features/example_groups/nested_groups.feature +17 -0
- data/features/example_groups/output.feature +20 -0
- data/features/interop/examples_and_tests_together.feature +31 -0
- data/features/interop/test_but_not_test_unit.feature +14 -0
- data/features/interop/test_case_with_should_methods.feature +17 -0
- data/features/mock_framework_integration/use_flexmock.feature +27 -0
- data/features/step_definitions/running_rspec.rb +54 -0
- data/features/support/env.rb +26 -0
- data/features/support/helpers/cmdline.rb +9 -0
- data/features/support/matchers/smart_match.rb +37 -0
- data/init.rb +9 -0
- data/lib/adapters/mock_frameworks/flexmock.rb +24 -0
- data/lib/adapters/mock_frameworks/mocha.rb +20 -0
- data/lib/adapters/mock_frameworks/rr.rb +22 -0
- data/lib/adapters/mock_frameworks/rspec.rb +20 -0
- data/lib/autotest/discover.rb +3 -0
- data/lib/autotest/rspec.rb +47 -0
- data/lib/spec/dsl/main.rb +87 -0
- data/lib/spec/dsl.rb +1 -0
- data/lib/spec/example/before_and_after_hooks.rb +99 -0
- data/lib/spec/example/errors.rb +30 -0
- data/lib/spec/example/example_group.rb +26 -0
- data/lib/spec/example/example_group_factory.rb +98 -0
- data/lib/spec/example/example_group_methods.rb +376 -0
- data/lib/spec/example/example_matcher.rb +44 -0
- data/lib/spec/example/example_methods.rb +137 -0
- data/lib/spec/example/module_reopening_fix.rb +21 -0
- data/lib/spec/example/pending.rb +18 -0
- data/lib/spec/example/shared_example_group.rb +59 -0
- data/lib/spec/example.rb +187 -0
- data/lib/spec/expectations/differs/default.rb +66 -0
- data/lib/spec/expectations/errors.rb +12 -0
- data/lib/spec/expectations/extensions/object.rb +63 -0
- data/lib/spec/expectations/extensions/string_and_symbol.rb +17 -0
- data/lib/spec/expectations/extensions.rb +2 -0
- data/lib/spec/expectations/handler.rb +32 -0
- data/lib/spec/expectations.rb +60 -0
- data/lib/spec/interop/test/unit/autorunner.rb +6 -0
- data/lib/spec/interop/test/unit/testcase.rb +73 -0
- data/lib/spec/interop/test/unit/testresult.rb +6 -0
- data/lib/spec/interop/test/unit/testsuite_adapter.rb +34 -0
- data/lib/spec/interop/test/unit/ui/console/testrunner.rb +61 -0
- data/lib/spec/interop/test.rb +12 -0
- data/lib/spec/matchers/be.rb +208 -0
- data/lib/spec/matchers/be_close.rb +21 -0
- data/lib/spec/matchers/change.rb +148 -0
- data/lib/spec/matchers/eql.rb +25 -0
- data/lib/spec/matchers/equal.rb +25 -0
- data/lib/spec/matchers/errors.rb +5 -0
- data/lib/spec/matchers/exist.rb +16 -0
- data/lib/spec/matchers/generated_descriptions.rb +48 -0
- data/lib/spec/matchers/has.rb +15 -0
- data/lib/spec/matchers/have.rb +150 -0
- data/lib/spec/matchers/include.rb +80 -0
- data/lib/spec/matchers/match.rb +22 -0
- 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 +70 -0
- data/lib/spec/matchers/raise_error.rb +128 -0
- data/lib/spec/matchers/respond_to.rb +71 -0
- data/lib/spec/matchers/satisfy.rb +47 -0
- data/lib/spec/matchers/simple_matcher.rb +132 -0
- data/lib/spec/matchers/throw_symbol.rb +106 -0
- data/lib/spec/matchers/wrap_expectation.rb +55 -0
- data/lib/spec/matchers.rb +141 -0
- data/lib/spec/mocks/argument_expectation.rb +49 -0
- data/lib/spec/mocks/argument_matchers.rb +237 -0
- data/lib/spec/mocks/error_generator.rb +82 -0
- data/lib/spec/mocks/errors.rb +10 -0
- data/lib/spec/mocks/extensions/object.rb +3 -0
- data/lib/spec/mocks/extensions.rb +1 -0
- data/lib/spec/mocks/framework.rb +15 -0
- data/lib/spec/mocks/message_expectation.rb +331 -0
- data/lib/spec/mocks/methods.rb +51 -0
- data/lib/spec/mocks/mock.rb +55 -0
- data/lib/spec/mocks/order_group.rb +29 -0
- data/lib/spec/mocks/proxy.rb +230 -0
- data/lib/spec/mocks/space.rb +28 -0
- data/lib/spec/mocks/spec_methods.rb +55 -0
- data/lib/spec/mocks.rb +200 -0
- data/lib/spec/rake/spectask.rb +225 -0
- data/lib/spec/rake/verify_rcov.rb +52 -0
- data/lib/spec/ruby.rb +9 -0
- data/lib/spec/runner/backtrace_tweaker.rb +58 -0
- data/lib/spec/runner/class_and_arguments_parser.rb +14 -0
- data/lib/spec/runner/command_line.rb +35 -0
- data/lib/spec/runner/configuration.rb +166 -0
- data/lib/spec/runner/drb_command_line.rb +20 -0
- data/lib/spec/runner/example_group_runner.rb +70 -0
- data/lib/spec/runner/formatter/base_formatter.rb +79 -0
- data/lib/spec/runner/formatter/base_text_formatter.rb +127 -0
- data/lib/spec/runner/formatter/failing_example_groups_formatter.rb +27 -0
- data/lib/spec/runner/formatter/failing_examples_formatter.rb +20 -0
- data/lib/spec/runner/formatter/html_formatter.rb +340 -0
- data/lib/spec/runner/formatter/nested_text_formatter.rb +65 -0
- data/lib/spec/runner/formatter/profile_formatter.rb +51 -0
- data/lib/spec/runner/formatter/progress_bar_formatter.rb +34 -0
- data/lib/spec/runner/formatter/snippet_extractor.rb +52 -0
- data/lib/spec/runner/formatter/specdoc_formatter.rb +39 -0
- data/lib/spec/runner/formatter/text_mate_formatter.rb +16 -0
- data/lib/spec/runner/heckle_runner.rb +74 -0
- data/lib/spec/runner/heckle_runner_unsupported.rb +10 -0
- data/lib/spec/runner/option_parser.rb +204 -0
- data/lib/spec/runner/options.rb +320 -0
- data/lib/spec/runner/reporter.rb +167 -0
- data/lib/spec/runner/spec_parser.rb +73 -0
- data/lib/spec/runner.rb +88 -0
- data/lib/spec/version.rb +15 -0
- data/lib/spec.rb +7 -0
- data/resources/rake/examples.rake +7 -0
- data/resources/rake/examples_with_rcov.rake +9 -0
- data/resources/rake/failing_examples_with_html.rake +9 -0
- data/resources/rake/verify_rcov.rake +7 -0
- data/resources/spec/example_group_with_should_methods.rb +12 -0
- data/resources/spec/simple_spec.rb +8 -0
- data/resources/test/spec_and_test_together.rb +57 -0
- data/resources/test/spec_including_test_but_not_unit.rb +11 -0
- data/resources/test/test_case_with_should_methods.rb +30 -0
- data/rspec.gemspec +32 -0
- data/spec/README.jruby +15 -0
- data/spec/autotest/autotest_helper.rb +6 -0
- data/spec/autotest/autotest_matchers.rb +47 -0
- data/spec/autotest/discover_spec.rb +8 -0
- data/spec/autotest/failed_results_re_spec.rb +24 -0
- data/spec/autotest/rspec_spec.rb +114 -0
- data/spec/rspec_suite.rb +6 -0
- data/spec/ruby_forker.rb +13 -0
- data/spec/spec/dsl/main_spec.rb +88 -0
- data/spec/spec/example/example_group_class_definition_spec.rb +49 -0
- data/spec/spec/example/example_group_factory_spec.rb +224 -0
- data/spec/spec/example/example_group_methods_spec.rb +653 -0
- data/spec/spec/example/example_group_spec.rb +661 -0
- data/spec/spec/example/example_matcher_spec.rb +79 -0
- data/spec/spec/example/example_methods_spec.rb +204 -0
- data/spec/spec/example/helper_method_spec.rb +24 -0
- data/spec/spec/example/nested_example_group_spec.rb +71 -0
- data/spec/spec/example/pending_module_spec.rb +139 -0
- data/spec/spec/example/predicate_matcher_spec.rb +21 -0
- data/spec/spec/example/shared_example_group_spec.rb +257 -0
- data/spec/spec/example/subclassing_example_group_spec.rb +25 -0
- data/spec/spec/expectations/differs/default_spec.rb +127 -0
- data/spec/spec/expectations/extensions/object_spec.rb +45 -0
- data/spec/spec/expectations/fail_with_spec.rb +71 -0
- data/spec/spec/expectations/wrap_expectation_spec.rb +30 -0
- data/spec/spec/interop/test/unit/resources/spec_that_fails.rb +10 -0
- data/spec/spec/interop/test/unit/resources/spec_that_passes.rb +10 -0
- data/spec/spec/interop/test/unit/resources/spec_with_errors.rb +10 -0
- data/spec/spec/interop/test/unit/resources/spec_with_options_hash.rb +13 -0
- data/spec/spec/interop/test/unit/resources/test_case_that_fails.rb +10 -0
- data/spec/spec/interop/test/unit/resources/test_case_that_passes.rb +10 -0
- data/spec/spec/interop/test/unit/resources/test_case_with_errors.rb +10 -0
- data/spec/spec/interop/test/unit/resources/testsuite_adapter_spec_with_test_unit.rb +38 -0
- data/spec/spec/interop/test/unit/spec_spec.rb +48 -0
- data/spec/spec/interop/test/unit/test_unit_spec_helper.rb +18 -0
- data/spec/spec/interop/test/unit/testcase_spec.rb +49 -0
- data/spec/spec/interop/test/unit/testsuite_adapter_spec.rb +9 -0
- data/spec/spec/matchers/be_close_spec.rb +41 -0
- data/spec/spec/matchers/be_spec.rb +303 -0
- data/spec/spec/matchers/change_spec.rb +329 -0
- data/spec/spec/matchers/description_generation_spec.rb +172 -0
- data/spec/spec/matchers/eql_spec.rb +29 -0
- data/spec/spec/matchers/equal_spec.rb +29 -0
- data/spec/spec/matchers/exist_spec.rb +57 -0
- data/spec/spec/matchers/handler_spec.rb +111 -0
- data/spec/spec/matchers/has_spec.rb +63 -0
- data/spec/spec/matchers/have_spec.rb +399 -0
- data/spec/spec/matchers/include_spec.rb +88 -0
- data/spec/spec/matchers/match_array_spec.rb +83 -0
- data/spec/spec/matchers/match_spec.rb +37 -0
- data/spec/spec/matchers/matcher_methods_spec.rb +66 -0
- data/spec/spec/matchers/operator_matcher_spec.rb +191 -0
- data/spec/spec/matchers/raise_error_spec.rb +333 -0
- data/spec/spec/matchers/respond_to_spec.rb +116 -0
- data/spec/spec/matchers/satisfy_spec.rb +36 -0
- data/spec/spec/matchers/simple_matcher_spec.rb +93 -0
- data/spec/spec/matchers/throw_symbol_spec.rb +96 -0
- data/spec/spec/mocks/any_number_of_times_spec.rb +36 -0
- data/spec/spec/mocks/argument_expectation_spec.rb +23 -0
- data/spec/spec/mocks/at_least_spec.rb +97 -0
- data/spec/spec/mocks/at_most_spec.rb +93 -0
- data/spec/spec/mocks/bug_report_10260_spec.rb +8 -0
- data/spec/spec/mocks/bug_report_10263_spec.rb +24 -0
- data/spec/spec/mocks/bug_report_11545_spec.rb +32 -0
- data/spec/spec/mocks/bug_report_15719_spec.rb +30 -0
- data/spec/spec/mocks/bug_report_496.rb +19 -0
- data/spec/spec/mocks/bug_report_600_spec.rb +22 -0
- data/spec/spec/mocks/bug_report_7611_spec.rb +19 -0
- data/spec/spec/mocks/bug_report_7805_spec.rb +22 -0
- data/spec/spec/mocks/bug_report_8165_spec.rb +31 -0
- data/spec/spec/mocks/bug_report_8302_spec.rb +26 -0
- data/spec/spec/mocks/failing_argument_matchers_spec.rb +95 -0
- data/spec/spec/mocks/hash_including_matcher_spec.rb +90 -0
- data/spec/spec/mocks/hash_not_including_matcher_spec.rb +67 -0
- data/spec/spec/mocks/mock_ordering_spec.rb +84 -0
- data/spec/spec/mocks/mock_space_spec.rb +54 -0
- data/spec/spec/mocks/mock_spec.rb +579 -0
- data/spec/spec/mocks/multiple_return_value_spec.rb +113 -0
- data/spec/spec/mocks/nil_expectation_warning_spec.rb +53 -0
- data/spec/spec/mocks/null_object_mock_spec.rb +54 -0
- data/spec/spec/mocks/once_counts_spec.rb +53 -0
- data/spec/spec/mocks/options_hash_spec.rb +35 -0
- data/spec/spec/mocks/partial_mock_spec.rb +149 -0
- data/spec/spec/mocks/partial_mock_using_mocks_directly_spec.rb +66 -0
- data/spec/spec/mocks/passing_argument_matchers_spec.rb +145 -0
- data/spec/spec/mocks/precise_counts_spec.rb +52 -0
- data/spec/spec/mocks/record_messages_spec.rb +26 -0
- data/spec/spec/mocks/stub_spec.rb +194 -0
- data/spec/spec/mocks/stubbed_message_expectations_spec.rb +14 -0
- data/spec/spec/mocks/twice_counts_spec.rb +67 -0
- data/spec/spec/package/bin_spec_spec.rb +22 -0
- data/spec/spec/runner/class_and_argument_parser_spec.rb +23 -0
- data/spec/spec/runner/command_line_spec.rb +141 -0
- data/spec/spec/runner/configuration_spec.rb +301 -0
- data/spec/spec/runner/drb_command_line_spec.rb +97 -0
- data/spec/spec/runner/empty_file.txt +0 -0
- data/spec/spec/runner/example_group_runner_spec.rb +33 -0
- data/spec/spec/runner/examples.txt +2 -0
- data/spec/spec/runner/failed.txt +3 -0
- data/spec/spec/runner/formatter/base_formatter_spec.rb +23 -0
- data/spec/spec/runner/formatter/base_text_formatter_spec.rb +23 -0
- data/spec/spec/runner/formatter/failing_example_groups_formatter_spec.rb +45 -0
- data/spec/spec/runner/formatter/failing_examples_formatter_spec.rb +33 -0
- data/spec/spec/runner/formatter/html_formatted-1.8.4.html +365 -0
- data/spec/spec/runner/formatter/html_formatted-1.8.5-jruby.html +387 -0
- data/spec/spec/runner/formatter/html_formatted-1.8.5.html +371 -0
- data/spec/spec/runner/formatter/html_formatted-1.8.6-jruby.html +381 -0
- data/spec/spec/runner/formatter/html_formatted-1.8.6.html +379 -0
- 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 +62 -0
- data/spec/spec/runner/formatter/nested_text_formatter_spec.rb +318 -0
- data/spec/spec/runner/formatter/profile_formatter_spec.rb +65 -0
- data/spec/spec/runner/formatter/progress_bar_formatter_spec.rb +145 -0
- data/spec/spec/runner/formatter/snippet_extractor_spec.rb +18 -0
- data/spec/spec/runner/formatter/spec_mate_formatter_spec.rb +104 -0
- data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +159 -0
- data/spec/spec/runner/formatter/text_mate_formatted-1.8.4.html +365 -0
- data/spec/spec/runner/formatter/text_mate_formatted-1.8.6.html +373 -0
- 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/heckle_runner_spec.rb +78 -0
- data/spec/spec/runner/heckler_spec.rb +20 -0
- data/spec/spec/runner/noisy_backtrace_tweaker_spec.rb +45 -0
- data/spec/spec/runner/option_parser_spec.rb +396 -0
- data/spec/spec/runner/options_spec.rb +469 -0
- data/spec/spec/runner/output_one_time_fixture.rb +7 -0
- data/spec/spec/runner/output_one_time_fixture_runner.rb +8 -0
- data/spec/spec/runner/output_one_time_spec.rb +16 -0
- data/spec/spec/runner/quiet_backtrace_tweaker_spec.rb +62 -0
- data/spec/spec/runner/reporter_spec.rb +238 -0
- data/spec/spec/runner/resources/a_bar.rb +0 -0
- data/spec/spec/runner/resources/a_foo.rb +0 -0
- data/spec/spec/runner/resources/a_spec.rb +1 -0
- 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.opts +2 -0
- data/spec/spec/runner/spec_drb.opts +1 -0
- data/spec/spec/runner/spec_parser/spec_parser_fixture.rb +70 -0
- data/spec/spec/runner/spec_parser_spec.rb +91 -0
- data/spec/spec/runner/spec_spaced.opts +2 -0
- data/spec/spec/runner_spec.rb +11 -0
- data/spec/spec/spec_classes.rb +133 -0
- data/spec/spec/spec_spec.rb +21 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helper.rb +107 -0
- metadata +388 -0
@@ -0,0 +1,376 @@
|
|
1
|
+
module Spec
|
2
|
+
module Example
|
3
|
+
|
4
|
+
module ExampleGroupMethods
|
5
|
+
class << self
|
6
|
+
attr_accessor :matcher_class
|
7
|
+
|
8
|
+
def description_text(*args)
|
9
|
+
text = args.inject("") do |description, arg|
|
10
|
+
description << " " unless (description == "" || arg.to_s =~ /^(\s|\.|#)/)
|
11
|
+
description << arg.to_s
|
12
|
+
end
|
13
|
+
text == "" ? nil : text
|
14
|
+
end
|
15
|
+
|
16
|
+
def example_group_creation_listeners
|
17
|
+
@example_group_creation_listeners ||= []
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
include Spec::Example::BeforeAndAfterHooks
|
22
|
+
include Spec::Example::Subject::ExampleGroupMethods
|
23
|
+
|
24
|
+
attr_reader :description_options, :spec_path
|
25
|
+
alias :options :description_options
|
26
|
+
|
27
|
+
def inherited(klass)
|
28
|
+
super
|
29
|
+
register_example_group(klass)
|
30
|
+
end
|
31
|
+
|
32
|
+
def register_example_group(klass)
|
33
|
+
ExampleGroupMethods.example_group_creation_listeners.each do |listener|
|
34
|
+
listener.register_example_group(klass)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Provides the backtrace up to where this example_group was declared.
|
39
|
+
def backtrace
|
40
|
+
@backtrace
|
41
|
+
end
|
42
|
+
|
43
|
+
# Deprecated - use +backtrace()+
|
44
|
+
def example_group_backtrace
|
45
|
+
Kernel.warn <<-WARNING
|
46
|
+
ExampleGroupMethods#example_group_backtrace is deprecated and will be removed
|
47
|
+
from a future version. Please use ExampleGroupMethods#backtrace instead.
|
48
|
+
WARNING
|
49
|
+
backtrace
|
50
|
+
end
|
51
|
+
|
52
|
+
def description_args
|
53
|
+
@description_args ||= []
|
54
|
+
end
|
55
|
+
|
56
|
+
# Makes the describe/it syntax available from a class. For example:
|
57
|
+
#
|
58
|
+
# class StackSpec < Spec::ExampleGroup
|
59
|
+
# describe Stack, "with no elements"
|
60
|
+
#
|
61
|
+
# before
|
62
|
+
# @stack = Stack.new
|
63
|
+
# end
|
64
|
+
#
|
65
|
+
# it "should raise on pop" do
|
66
|
+
# lambda{ @stack.pop }.should raise_error
|
67
|
+
# end
|
68
|
+
# end
|
69
|
+
#
|
70
|
+
def describe(*args, &example_group_block)
|
71
|
+
if example_group_block
|
72
|
+
Spec::Example::add_spec_path_to(args)
|
73
|
+
options = args.last
|
74
|
+
if options[:shared]
|
75
|
+
create_shared_example_group(*args, &example_group_block)
|
76
|
+
else
|
77
|
+
create_example_group_subclass(*args, &example_group_block)
|
78
|
+
end
|
79
|
+
else
|
80
|
+
set_description(*args)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
alias :context :describe
|
84
|
+
|
85
|
+
def create_shared_example_group(*args, &example_group_block) # :nodoc:
|
86
|
+
SharedExampleGroup.register(*args, &example_group_block)
|
87
|
+
end
|
88
|
+
|
89
|
+
# Creates a new subclass of self, with a name "under" our own name.
|
90
|
+
# Example:
|
91
|
+
#
|
92
|
+
# x = Foo::Bar.subclass('Zap'){}
|
93
|
+
# x.name # => Foo::Bar::Zap_1
|
94
|
+
# x.superclass.name # => Foo::Bar
|
95
|
+
def create_example_group_subclass(*args, &example_group_block) # :nodoc:
|
96
|
+
@class_count ||= 0
|
97
|
+
@class_count += 1
|
98
|
+
klass = const_set("Subclass_#{@class_count}", Class.new(self))
|
99
|
+
klass.set_description(*args)
|
100
|
+
example_group_block = ExampleGroupFactory.include_constants_in(args.last[:scope], &example_group_block)
|
101
|
+
klass.module_eval(&example_group_block)
|
102
|
+
klass
|
103
|
+
end
|
104
|
+
|
105
|
+
# Use this to pull in examples from shared example groups.
|
106
|
+
def it_should_behave_like(*shared_example_groups)
|
107
|
+
shared_example_groups.each do |group|
|
108
|
+
include_shared_example_group(group)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
# :call-seq:
|
113
|
+
# predicate_matchers[matcher_name] = method_on_object
|
114
|
+
# predicate_matchers[matcher_name] = [method1_on_object, method2_on_object]
|
115
|
+
#
|
116
|
+
# Dynamically generates a custom matcher that will match
|
117
|
+
# a predicate on your class. RSpec provides a couple of these
|
118
|
+
# out of the box:
|
119
|
+
#
|
120
|
+
# exist (for state expectations)
|
121
|
+
# File.should exist("path/to/file")
|
122
|
+
#
|
123
|
+
# an_instance_of (for mock argument matchers)
|
124
|
+
# mock.should_receive(:message).with(an_instance_of(String))
|
125
|
+
#
|
126
|
+
# == Examples
|
127
|
+
#
|
128
|
+
# class Fish
|
129
|
+
# def can_swim?
|
130
|
+
# true
|
131
|
+
# end
|
132
|
+
# end
|
133
|
+
#
|
134
|
+
# describe Fish do
|
135
|
+
# predicate_matchers[:swim] = :can_swim?
|
136
|
+
# it "should swim" do
|
137
|
+
# Fish.new.should swim
|
138
|
+
# end
|
139
|
+
# end
|
140
|
+
def predicate_matchers
|
141
|
+
@predicate_matchers ||= {}
|
142
|
+
end
|
143
|
+
|
144
|
+
# Creates an instance of the current example group class and adds it to
|
145
|
+
# a collection of examples of the current example group.
|
146
|
+
def example(description=nil, options={}, &implementation)
|
147
|
+
e = new(description, options, &implementation)
|
148
|
+
example_objects << e
|
149
|
+
e
|
150
|
+
end
|
151
|
+
|
152
|
+
alias_method :it, :example
|
153
|
+
alias_method :specify, :example
|
154
|
+
|
155
|
+
# Use this to temporarily disable an example.
|
156
|
+
def xexample(description=nil, opts={}, &block)
|
157
|
+
Kernel.warn("Example disabled: #{description}")
|
158
|
+
end
|
159
|
+
|
160
|
+
alias_method :xit, :xexample
|
161
|
+
alias_method :xspecify, :xexample
|
162
|
+
|
163
|
+
def run(run_options)
|
164
|
+
examples = examples_to_run(run_options)
|
165
|
+
run_options.reporter.add_example_group(self) unless examples.empty?
|
166
|
+
return true if examples.empty?
|
167
|
+
return dry_run(examples, run_options) if run_options.dry_run?
|
168
|
+
|
169
|
+
plugin_mock_framework(run_options)
|
170
|
+
define_methods_from_predicate_matchers(run_options)
|
171
|
+
|
172
|
+
success, before_all_instance_variables = run_before_all(run_options)
|
173
|
+
success, after_all_instance_variables = execute_examples(success, before_all_instance_variables, examples, run_options)
|
174
|
+
success = run_after_all(success, after_all_instance_variables, run_options)
|
175
|
+
end
|
176
|
+
|
177
|
+
def description
|
178
|
+
@description ||= ExampleGroupMethods.description_text(*description_parts) || to_s
|
179
|
+
end
|
180
|
+
|
181
|
+
def described_type
|
182
|
+
@described_type ||= description_parts.reverse.find {|part| part.is_a?(Module)}
|
183
|
+
end
|
184
|
+
|
185
|
+
def described_class
|
186
|
+
Class === described_type ? described_type : nil
|
187
|
+
end
|
188
|
+
|
189
|
+
def description_parts #:nodoc:
|
190
|
+
@description_parts ||= example_group_hierarchy.inject([]) do |parts, example_group_class|
|
191
|
+
[parts << example_group_class.description_args].flatten
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
def set_description(*args)
|
196
|
+
args, options = Spec::Example.args_and_options(*args)
|
197
|
+
@description_args = args
|
198
|
+
@description_options = options
|
199
|
+
@description_text = ExampleGroupMethods.description_text(*args)
|
200
|
+
@backtrace = caller(1)
|
201
|
+
@spec_path = File.expand_path(options[:spec_path]) if options[:spec_path]
|
202
|
+
self
|
203
|
+
end
|
204
|
+
|
205
|
+
def examples(run_options=nil) #:nodoc:
|
206
|
+
examples = example_objects.dup
|
207
|
+
add_method_examples(examples)
|
208
|
+
(run_options && run_options.reverse) ? examples.reverse : examples
|
209
|
+
end
|
210
|
+
|
211
|
+
def number_of_examples #:nodoc:
|
212
|
+
examples.length
|
213
|
+
end
|
214
|
+
|
215
|
+
def run_before_each(example)
|
216
|
+
example.eval_each_fail_fast(all_before_each_parts)
|
217
|
+
end
|
218
|
+
|
219
|
+
def all_before_each_parts
|
220
|
+
unless @all_before_each_parts
|
221
|
+
@all_before_each_parts = []
|
222
|
+
example_group_hierarchy.each do |example_group_class|
|
223
|
+
@all_before_each_parts += example_group_class.before_each_parts
|
224
|
+
end
|
225
|
+
end
|
226
|
+
@all_before_each_parts
|
227
|
+
end
|
228
|
+
|
229
|
+
def run_after_each(example)
|
230
|
+
example_group_hierarchy.reverse.each do |example_group_class|
|
231
|
+
example.eval_each_fail_slow(example_group_class.after_each_parts)
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
private
|
236
|
+
def dry_run(examples, run_options)
|
237
|
+
examples.each do |example|
|
238
|
+
run_options.reporter.example_started(example)
|
239
|
+
run_options.reporter.example_finished(example)
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
def run_before_all(run_options)
|
244
|
+
before_all = new("before(:all)")
|
245
|
+
begin
|
246
|
+
example_group_hierarchy.each do |example_group_class|
|
247
|
+
before_all.eval_each_fail_fast(example_group_class.before_all_parts)
|
248
|
+
end
|
249
|
+
return [true, before_all.instance_variable_hash]
|
250
|
+
rescue Exception => e
|
251
|
+
run_options.reporter.failure(before_all, e)
|
252
|
+
return [false, before_all.instance_variable_hash]
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
def execute_examples(success, instance_variables, examples, run_options)
|
257
|
+
return [success, instance_variables] unless success
|
258
|
+
|
259
|
+
after_all_instance_variables = instance_variables
|
260
|
+
examples.each do |example_group_instance|
|
261
|
+
success &= example_group_instance.execute(run_options, instance_variables)
|
262
|
+
after_all_instance_variables = example_group_instance.instance_variable_hash
|
263
|
+
end
|
264
|
+
return [success, after_all_instance_variables]
|
265
|
+
end
|
266
|
+
|
267
|
+
def run_after_all(success, instance_variables, run_options)
|
268
|
+
after_all = new("after(:all)")
|
269
|
+
after_all.set_instance_variables_from_hash(instance_variables)
|
270
|
+
example_group_hierarchy.reverse.each do |example_group_class|
|
271
|
+
after_all.eval_each_fail_slow(example_group_class.after_all_parts)
|
272
|
+
end
|
273
|
+
return success
|
274
|
+
rescue Exception => e
|
275
|
+
run_options.reporter.failure(after_all, e)
|
276
|
+
return false
|
277
|
+
end
|
278
|
+
|
279
|
+
def examples_to_run(run_options)
|
280
|
+
all_examples = examples(run_options)
|
281
|
+
return all_examples unless specified_examples?(run_options)
|
282
|
+
all_examples.reject do |example|
|
283
|
+
matcher = ExampleGroupMethods.matcher_class.
|
284
|
+
new(description.to_s, example.description)
|
285
|
+
!matcher.matches?(run_options.examples)
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
def specified_examples?(run_options)
|
290
|
+
run_options.examples && !run_options.examples.empty?
|
291
|
+
end
|
292
|
+
|
293
|
+
def example_objects
|
294
|
+
@example_objects ||= []
|
295
|
+
end
|
296
|
+
|
297
|
+
class ExampleGroupHierarchy < Array
|
298
|
+
def initialize(example_group_class)
|
299
|
+
current_class = example_group_class
|
300
|
+
while current_class.kind_of?(ExampleGroupMethods)
|
301
|
+
unshift(current_class)
|
302
|
+
break unless current_class.respond_to? :superclass
|
303
|
+
current_class = current_class.superclass
|
304
|
+
end
|
305
|
+
end
|
306
|
+
end
|
307
|
+
|
308
|
+
def example_group_hierarchy
|
309
|
+
@example_group_hierarchy ||= ExampleGroupHierarchy.new(self)
|
310
|
+
end
|
311
|
+
|
312
|
+
def plugin_mock_framework(run_options)
|
313
|
+
case mock_framework = run_options.mock_framework
|
314
|
+
when Module
|
315
|
+
include mock_framework
|
316
|
+
else
|
317
|
+
require mock_framework
|
318
|
+
include Spec::Adapters::MockFramework
|
319
|
+
end
|
320
|
+
end
|
321
|
+
|
322
|
+
def define_methods_from_predicate_matchers(run_options) # :nodoc:
|
323
|
+
all_predicate_matchers = predicate_matchers.merge(
|
324
|
+
run_options.predicate_matchers
|
325
|
+
)
|
326
|
+
all_predicate_matchers.each_pair do |matcher_method, method_on_object|
|
327
|
+
define_method matcher_method do |*args|
|
328
|
+
eval("be_#{method_on_object.to_s.gsub('?','')}(*args)")
|
329
|
+
end
|
330
|
+
end
|
331
|
+
end
|
332
|
+
|
333
|
+
def add_method_examples(examples)
|
334
|
+
example_methods.each do |method_name|
|
335
|
+
examples << new(method_name) do
|
336
|
+
__send__(method_name)
|
337
|
+
end
|
338
|
+
end
|
339
|
+
end
|
340
|
+
|
341
|
+
def method_added(name)
|
342
|
+
example_methods << name.to_s if example_method?(name.to_s)
|
343
|
+
end
|
344
|
+
|
345
|
+
def example_methods
|
346
|
+
@example_methods ||= []
|
347
|
+
end
|
348
|
+
|
349
|
+
def example_method?(method_name)
|
350
|
+
should_method?(method_name)
|
351
|
+
end
|
352
|
+
|
353
|
+
def should_method?(method_name)
|
354
|
+
!(method_name =~ /^should(_not)?$/) &&
|
355
|
+
method_name =~ /^should/ && (
|
356
|
+
[-1,0].include?(instance_method(method_name).arity)
|
357
|
+
)
|
358
|
+
end
|
359
|
+
|
360
|
+
def include_shared_example_group(shared_example_group)
|
361
|
+
case shared_example_group
|
362
|
+
when SharedExampleGroup
|
363
|
+
include shared_example_group
|
364
|
+
else
|
365
|
+
example_group = SharedExampleGroup.find(shared_example_group)
|
366
|
+
unless example_group
|
367
|
+
raise RuntimeError.new("Shared Example Group '#{shared_example_group}' can not be found")
|
368
|
+
end
|
369
|
+
include(example_group)
|
370
|
+
end
|
371
|
+
end
|
372
|
+
|
373
|
+
end
|
374
|
+
|
375
|
+
end
|
376
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Spec
|
2
|
+
module Example
|
3
|
+
class ExampleMatcher
|
4
|
+
def initialize(example_group_description, example_name)
|
5
|
+
@example_group_description = example_group_description
|
6
|
+
@example_name = example_name
|
7
|
+
end
|
8
|
+
|
9
|
+
def matches?(specified_examples)
|
10
|
+
specified_examples.each do |specified_example|
|
11
|
+
return true if matches_literal_example?(specified_example) || matches_example_not_considering_modules?(specified_example)
|
12
|
+
end
|
13
|
+
false
|
14
|
+
end
|
15
|
+
|
16
|
+
protected
|
17
|
+
def matches_literal_example?(specified_example)
|
18
|
+
specified_example =~ /(^#{example_group_regex} #{example_regexp}$|^#{example_group_regex}$|^#{example_group_with_before_all_regexp}$|^#{example_regexp}$)/
|
19
|
+
end
|
20
|
+
|
21
|
+
def matches_example_not_considering_modules?(specified_example)
|
22
|
+
specified_example =~ /(^#{example_group_regex_not_considering_modules} #{example_regexp}$|^#{example_group_regex_not_considering_modules}$|^#{example_regexp}$)/
|
23
|
+
end
|
24
|
+
|
25
|
+
def example_group_regex
|
26
|
+
Regexp.escape(@example_group_description)
|
27
|
+
end
|
28
|
+
|
29
|
+
def example_group_with_before_all_regexp
|
30
|
+
Regexp.escape("#{@example_group_description} before(:all)")
|
31
|
+
end
|
32
|
+
|
33
|
+
def example_group_regex_not_considering_modules
|
34
|
+
Regexp.escape(@example_group_description.split('::').last)
|
35
|
+
end
|
36
|
+
|
37
|
+
def example_regexp
|
38
|
+
Regexp.escape(@example_name)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
ExampleGroupMethods.matcher_class = ExampleMatcher
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
module Spec
|
2
|
+
module Example
|
3
|
+
module ExampleMethods
|
4
|
+
|
5
|
+
extend Spec::Example::ModuleReopeningFix
|
6
|
+
include Spec::Example::Subject::ExampleMethods
|
7
|
+
|
8
|
+
|
9
|
+
def violated(message="")
|
10
|
+
raise Spec::Expectations::ExpectationNotMetError.new(message)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Declared description for this example:
|
14
|
+
#
|
15
|
+
# describe Account do
|
16
|
+
# it "should start with a balance of 0" do
|
17
|
+
# ...
|
18
|
+
#
|
19
|
+
# description
|
20
|
+
# => "should start with a balance of 0"
|
21
|
+
def description
|
22
|
+
@_defined_description || ::Spec::Matchers.generated_description || "NO NAME"
|
23
|
+
end
|
24
|
+
|
25
|
+
# Concats the class description with the example description.
|
26
|
+
#
|
27
|
+
# describe Account do
|
28
|
+
# it "should start with a balance of 0" do
|
29
|
+
# ...
|
30
|
+
#
|
31
|
+
# full_description
|
32
|
+
# => "Account should start with a balance of 0"
|
33
|
+
def full_description
|
34
|
+
"#{self.class.description} #{self.description}"
|
35
|
+
end
|
36
|
+
|
37
|
+
def options # :nodoc:
|
38
|
+
@_options
|
39
|
+
end
|
40
|
+
|
41
|
+
def execute(options, instance_variables) # :nodoc:
|
42
|
+
options.reporter.example_started(self)
|
43
|
+
set_instance_variables_from_hash(instance_variables)
|
44
|
+
|
45
|
+
execution_error = nil
|
46
|
+
Timeout.timeout(options.timeout) do
|
47
|
+
begin
|
48
|
+
before_each_example
|
49
|
+
eval_block
|
50
|
+
rescue Exception => e
|
51
|
+
execution_error ||= e
|
52
|
+
end
|
53
|
+
begin
|
54
|
+
after_each_example
|
55
|
+
rescue Exception => e
|
56
|
+
execution_error ||= e
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
options.reporter.example_finished(self, execution_error)
|
61
|
+
success = execution_error.nil? || ExamplePendingError === execution_error
|
62
|
+
end
|
63
|
+
|
64
|
+
def instance_variable_hash # :nodoc:
|
65
|
+
instance_variables.inject({}) do |variable_hash, variable_name|
|
66
|
+
variable_hash[variable_name] = instance_variable_get(variable_name)
|
67
|
+
variable_hash
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def eval_each_fail_fast(blocks) # :nodoc:
|
72
|
+
blocks.each do |block|
|
73
|
+
instance_eval(&block)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def eval_each_fail_slow(blocks) # :nodoc:
|
78
|
+
first_exception = nil
|
79
|
+
blocks.each do |block|
|
80
|
+
begin
|
81
|
+
instance_eval(&block)
|
82
|
+
rescue Exception => e
|
83
|
+
first_exception ||= e
|
84
|
+
end
|
85
|
+
end
|
86
|
+
raise first_exception if first_exception
|
87
|
+
end
|
88
|
+
|
89
|
+
def set_instance_variables_from_hash(ivars) # :nodoc:
|
90
|
+
ivars.each do |variable_name, value|
|
91
|
+
# Ruby 1.9 requires variable.to_s on the next line
|
92
|
+
unless ['@_implementation', '@_defined_description', '@_matcher_description', '@method_name'].include?(variable_name.to_s)
|
93
|
+
instance_variable_set variable_name, value
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def eval_block # :nodoc:
|
99
|
+
instance_eval(&@_implementation)
|
100
|
+
end
|
101
|
+
|
102
|
+
# Provides the backtrace up to where this example was declared.
|
103
|
+
def backtrace
|
104
|
+
@_backtrace
|
105
|
+
end
|
106
|
+
|
107
|
+
# Deprecated - use +backtrace()+
|
108
|
+
def implementation_backtrace
|
109
|
+
Kernel.warn <<-WARNING
|
110
|
+
ExampleMethods#implementation_backtrace is deprecated and will be removed
|
111
|
+
from a future version. Please use ExampleMethods#backtrace instead.
|
112
|
+
WARNING
|
113
|
+
backtrace
|
114
|
+
end
|
115
|
+
|
116
|
+
private
|
117
|
+
include Matchers
|
118
|
+
include Pending
|
119
|
+
|
120
|
+
def before_each_example # :nodoc:
|
121
|
+
setup_mocks_for_rspec
|
122
|
+
self.class.run_before_each(self)
|
123
|
+
end
|
124
|
+
|
125
|
+
def after_each_example # :nodoc:
|
126
|
+
self.class.run_after_each(self)
|
127
|
+
verify_mocks_for_rspec
|
128
|
+
ensure
|
129
|
+
teardown_mocks_for_rspec
|
130
|
+
end
|
131
|
+
|
132
|
+
def described_class # :nodoc:
|
133
|
+
self.class.described_class
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Spec
|
2
|
+
module Example
|
3
|
+
# This is a fix for ...Something in Ruby 1.8.6??... (Someone fill in here please - Aslak)
|
4
|
+
module ModuleReopeningFix
|
5
|
+
def child_modules
|
6
|
+
@child_modules ||= []
|
7
|
+
end
|
8
|
+
|
9
|
+
def included(mod)
|
10
|
+
child_modules << mod
|
11
|
+
end
|
12
|
+
|
13
|
+
def include(mod)
|
14
|
+
super
|
15
|
+
child_modules.each do |child_module|
|
16
|
+
child_module.__send__(:include, mod)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Spec
|
2
|
+
module Example
|
3
|
+
module Pending
|
4
|
+
def pending(message = "TODO")
|
5
|
+
if block_given?
|
6
|
+
begin
|
7
|
+
yield
|
8
|
+
rescue Exception => e
|
9
|
+
raise Spec::Example::ExamplePendingError.new(message)
|
10
|
+
end
|
11
|
+
raise Spec::Example::PendingExampleFixedError.new("Expected pending '#{message}' to fail. No Error was raised.")
|
12
|
+
else
|
13
|
+
raise Spec::Example::ExamplePendingError.new(message)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module Spec
|
2
|
+
module Example
|
3
|
+
class SharedExampleGroup < Module
|
4
|
+
module ClassMethods
|
5
|
+
def register(*args, &block)
|
6
|
+
new_example_group = new(*args, &block)
|
7
|
+
shared_example_groups << new_example_group unless already_registered?(new_example_group)
|
8
|
+
new_example_group
|
9
|
+
end
|
10
|
+
|
11
|
+
def find(example_group_description)
|
12
|
+
shared_example_groups.find {|b| b.description == example_group_description}
|
13
|
+
end
|
14
|
+
|
15
|
+
def clear
|
16
|
+
shared_example_groups.clear
|
17
|
+
end
|
18
|
+
|
19
|
+
def include?(group)
|
20
|
+
shared_example_groups.include?(group)
|
21
|
+
end
|
22
|
+
|
23
|
+
def count
|
24
|
+
shared_example_groups.length
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def shared_example_groups
|
30
|
+
@shared_example_groups ||= []
|
31
|
+
end
|
32
|
+
|
33
|
+
def already_registered?(new_example_group)
|
34
|
+
existing_example_group = find(new_example_group.description)
|
35
|
+
return false unless existing_example_group
|
36
|
+
return true if new_example_group.equal?(existing_example_group)
|
37
|
+
return true if expanded_path(new_example_group) == expanded_path(existing_example_group)
|
38
|
+
raise ArgumentError.new("Shared Example '#{existing_example_group.description}' already exists")
|
39
|
+
end
|
40
|
+
|
41
|
+
def expanded_path(example_group)
|
42
|
+
File.expand_path(example_group.spec_path)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
extend ClassMethods
|
47
|
+
include ExampleGroupMethods
|
48
|
+
|
49
|
+
def initialize(*args, &example_group_block)
|
50
|
+
set_description(*args)
|
51
|
+
@example_group_block = example_group_block
|
52
|
+
end
|
53
|
+
|
54
|
+
def included(mod) # :nodoc:
|
55
|
+
mod.module_eval(&@example_group_block)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|