newbamboo-rspec 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 +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,28 @@
|
|
|
1
|
+
module Spec
|
|
2
|
+
module Mocks
|
|
3
|
+
class Space
|
|
4
|
+
def add(obj)
|
|
5
|
+
mocks << obj unless mocks.detect {|m| m.equal? obj}
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def verify_all
|
|
9
|
+
mocks.each do |mock|
|
|
10
|
+
mock.rspec_verify
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def reset_all
|
|
15
|
+
mocks.each do |mock|
|
|
16
|
+
mock.rspec_reset
|
|
17
|
+
end
|
|
18
|
+
mocks.clear
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
def mocks
|
|
24
|
+
@mocks ||= []
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
module Spec
|
|
2
|
+
module Mocks
|
|
3
|
+
module ExampleMethods
|
|
4
|
+
include Spec::Mocks::ArgumentMatchers
|
|
5
|
+
|
|
6
|
+
# Shortcut for creating an instance of Spec::Mocks::Mock.
|
|
7
|
+
#
|
|
8
|
+
# +name+ is used for failure reporting, so you should use the
|
|
9
|
+
# role that the mock is playing in the example.
|
|
10
|
+
#
|
|
11
|
+
# +stubs_and_options+ lets you assign options and stub values
|
|
12
|
+
# at the same time. The only option available is :null_object.
|
|
13
|
+
# Anything else is treated as a stub value.
|
|
14
|
+
#
|
|
15
|
+
# == Examples
|
|
16
|
+
#
|
|
17
|
+
# stub_thing = mock("thing", :a => "A")
|
|
18
|
+
# stub_thing.a == "A" => true
|
|
19
|
+
#
|
|
20
|
+
# stub_person = stub("thing", :name => "Joe", :email => "joe@domain.com")
|
|
21
|
+
# stub_person.name => "Joe"
|
|
22
|
+
# stub_person.email => "joe@domain.com"
|
|
23
|
+
def mock(name, stubs_and_options={})
|
|
24
|
+
Spec::Mocks::Mock.new(name, stubs_and_options)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
alias :stub :mock
|
|
28
|
+
|
|
29
|
+
# DEPRECATED - use mock('name').as_null_object instead
|
|
30
|
+
#
|
|
31
|
+
# Shortcut for creating a mock object that will return itself in response
|
|
32
|
+
# to any message it receives that it hasn't been explicitly instructed
|
|
33
|
+
# to respond to.
|
|
34
|
+
def stub_everything(name = 'stub')
|
|
35
|
+
Kernel.warn(<<-WARNING)
|
|
36
|
+
|
|
37
|
+
DEPRECATION: stub_everything('#{name}') is deprecated and will be removed
|
|
38
|
+
from a future version of rspec. Please use mock('#{name}').as_null_object
|
|
39
|
+
or stub('#{name}').as_null_object instead.
|
|
40
|
+
|
|
41
|
+
WARNING
|
|
42
|
+
mock(name, :null_object => true)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Disables warning messages about expectations being set on nil.
|
|
46
|
+
#
|
|
47
|
+
# By default warning messages are issued when expectations are set on nil. This is to
|
|
48
|
+
# prevent false-positives and to catch potential bugs early on.
|
|
49
|
+
def allow_message_expectations_on_nil
|
|
50
|
+
Proxy.allow_message_expectations_on_nil
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
data/lib/spec/mocks.rb
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
require 'spec/mocks/framework'
|
|
2
|
+
require 'spec/mocks/extensions/object'
|
|
3
|
+
|
|
4
|
+
module Spec
|
|
5
|
+
# == Mocks and Stubs
|
|
6
|
+
#
|
|
7
|
+
# RSpec will create Mock Objects and Stubs for you at runtime, or attach stub/mock behaviour
|
|
8
|
+
# to any of your real objects (Partial Mock/Stub). Because the underlying implementation
|
|
9
|
+
# for mocks and stubs is the same, you can intermingle mock and stub
|
|
10
|
+
# behaviour in either dynamically generated mocks or your pre-existing classes.
|
|
11
|
+
# There is a semantic difference in how they are created, however,
|
|
12
|
+
# which can help clarify the role it is playing within a given spec.
|
|
13
|
+
#
|
|
14
|
+
# == Mock Objects
|
|
15
|
+
#
|
|
16
|
+
# Mocks are objects that allow you to set and verify expectations that they will
|
|
17
|
+
# receive specific messages during run time. They are very useful for specifying how the subject of
|
|
18
|
+
# the spec interacts with its collaborators. This approach is widely known as "interaction
|
|
19
|
+
# testing".
|
|
20
|
+
#
|
|
21
|
+
# Mocks are also very powerful as a design tool. As you are
|
|
22
|
+
# driving the implementation of a given class, Mocks provide an anonymous
|
|
23
|
+
# collaborator that can change in behaviour as quickly as you can write an expectation in your
|
|
24
|
+
# spec. This flexibility allows you to design the interface of a collaborator that often
|
|
25
|
+
# does not yet exist. As the shape of the class being specified becomes more clear, so do the
|
|
26
|
+
# requirements for its collaborators - often leading to the discovery of new types that are
|
|
27
|
+
# needed in your system.
|
|
28
|
+
#
|
|
29
|
+
# Read Endo-Testing[http://www.mockobjects.com/files/endotesting.pdf] for a much
|
|
30
|
+
# more in depth description of this process.
|
|
31
|
+
#
|
|
32
|
+
# == Stubs
|
|
33
|
+
#
|
|
34
|
+
# Stubs are objects that allow you to set "stub" responses to
|
|
35
|
+
# messages. As Martin Fowler points out on his site,
|
|
36
|
+
# mocks_arent_stubs[http://www.martinfowler.com/articles/mocksArentStubs.html].
|
|
37
|
+
# Paraphrasing Fowler's paraphrasing
|
|
38
|
+
# of Gerard Meszaros: Stubs provide canned responses to messages they might receive in a test, while
|
|
39
|
+
# mocks allow you to specify and, subsquently, verify that certain messages should be received during
|
|
40
|
+
# the execution of a test.
|
|
41
|
+
#
|
|
42
|
+
# == Partial Mocks/Stubs
|
|
43
|
+
#
|
|
44
|
+
# RSpec also supports partial mocking/stubbing, allowing you to add stub/mock behaviour
|
|
45
|
+
# to instances of your existing classes. This is generally
|
|
46
|
+
# something to be avoided, because changes to the class can have ripple effects on
|
|
47
|
+
# seemingly unrelated specs. When specs fail due to these ripple effects, the fact
|
|
48
|
+
# that some methods are being mocked can make it difficult to understand why a
|
|
49
|
+
# failure is occurring.
|
|
50
|
+
#
|
|
51
|
+
# That said, partials do allow you to expect and
|
|
52
|
+
# verify interactions with class methods such as +#find+ and +#create+
|
|
53
|
+
# on Ruby on Rails model classes.
|
|
54
|
+
#
|
|
55
|
+
# == Further Reading
|
|
56
|
+
#
|
|
57
|
+
# There are many different viewpoints about the meaning of mocks and stubs. If you are interested
|
|
58
|
+
# in learning more, here is some recommended reading:
|
|
59
|
+
#
|
|
60
|
+
# * Mock Objects: http://www.mockobjects.com/
|
|
61
|
+
# * Endo-Testing: http://www.mockobjects.com/files/endotesting.pdf
|
|
62
|
+
# * Mock Roles, Not Objects: http://www.mockobjects.com/files/mockrolesnotobjects.pdf
|
|
63
|
+
# * Test Double Patterns: http://xunitpatterns.com/Test%20Double%20Patterns.html
|
|
64
|
+
# * Mocks aren't stubs: http://www.martinfowler.com/articles/mocksArentStubs.html
|
|
65
|
+
#
|
|
66
|
+
# == Creating a Mock
|
|
67
|
+
#
|
|
68
|
+
# You can create a mock in any specification (or setup) using:
|
|
69
|
+
#
|
|
70
|
+
# mock(name, options={})
|
|
71
|
+
#
|
|
72
|
+
# The optional +options+ argument is a +Hash+. Currently the only supported
|
|
73
|
+
# option is +:null_object+. Setting this to true instructs the mock to ignore
|
|
74
|
+
# any messages it hasn’t been told to expect – and quietly return itself. For example:
|
|
75
|
+
#
|
|
76
|
+
# mock("person", :null_object => true)
|
|
77
|
+
#
|
|
78
|
+
# == Creating a Stub
|
|
79
|
+
#
|
|
80
|
+
# You can create a stub in any specification (or setup) using:
|
|
81
|
+
#
|
|
82
|
+
# stub(name, stub_methods_and_values_hash)
|
|
83
|
+
#
|
|
84
|
+
# For example, if you wanted to create an object that always returns
|
|
85
|
+
# "More?!?!?!" to "please_sir_may_i_have_some_more" you would do this:
|
|
86
|
+
#
|
|
87
|
+
# stub("Mr Sykes", :please_sir_may_i_have_some_more => "More?!?!?!")
|
|
88
|
+
#
|
|
89
|
+
# == Creating a Partial Mock
|
|
90
|
+
#
|
|
91
|
+
# You don't really "create" a partial mock, you simply add method stubs and/or
|
|
92
|
+
# mock expectations to existing classes and objects:
|
|
93
|
+
#
|
|
94
|
+
# Factory.should_receive(:find).with(id).and_return(value)
|
|
95
|
+
# obj.stub!(:to_i).and_return(3)
|
|
96
|
+
# etc ...
|
|
97
|
+
#
|
|
98
|
+
# == Expecting Messages
|
|
99
|
+
#
|
|
100
|
+
# my_mock.should_receive(:sym)
|
|
101
|
+
# my_mock.should_not_receive(:sym)
|
|
102
|
+
#
|
|
103
|
+
# == Expecting Arguments
|
|
104
|
+
#
|
|
105
|
+
# my_mock.should_receive(:sym).with(*args)
|
|
106
|
+
# my_mock.should_not_receive(:sym).with(*args)
|
|
107
|
+
#
|
|
108
|
+
# == Argument Matchers
|
|
109
|
+
#
|
|
110
|
+
# Arguments that are passed to #with are compared with actual arguments received
|
|
111
|
+
# using == by default. In cases in which you want to specify things about the arguments
|
|
112
|
+
# rather than the arguments themselves, you can use any of RSpec's Expression Matchers.
|
|
113
|
+
# They don't all make syntactic sense (they were primarily designed for use with
|
|
114
|
+
# Spec::Expectations), but you are free to create your own custom Spec::Matchers.
|
|
115
|
+
#
|
|
116
|
+
# Spec::Mocks does provide one additional Matcher method named #ducktype.
|
|
117
|
+
#
|
|
118
|
+
# In addition, Spec::Mocks adds some keyword Symbols that you can use to
|
|
119
|
+
# specify certain kinds of arguments:
|
|
120
|
+
#
|
|
121
|
+
# my_mock.should_receive(:sym).with(no_args())
|
|
122
|
+
# my_mock.should_receive(:sym).with(any_args())
|
|
123
|
+
# my_mock.should_receive(:sym).with(1, kind_of(Numeric), "b") #2nd argument can any kind of Numeric
|
|
124
|
+
# my_mock.should_receive(:sym).with(1, boolean(), "b") #2nd argument can true or false
|
|
125
|
+
# my_mock.should_receive(:sym).with(1, /abc/, "b") #2nd argument can be any String matching the submitted Regexp
|
|
126
|
+
# my_mock.should_receive(:sym).with(1, anything(), "b") #2nd argument can be anything at all
|
|
127
|
+
# my_mock.should_receive(:sym).with(1, ducktype(:abs, :div), "b")
|
|
128
|
+
# #2nd argument can be object that responds to #abs and #div
|
|
129
|
+
#
|
|
130
|
+
# == Receive Counts
|
|
131
|
+
#
|
|
132
|
+
# my_mock.should_receive(:sym).once
|
|
133
|
+
# my_mock.should_receive(:sym).twice
|
|
134
|
+
# my_mock.should_receive(:sym).exactly(n).times
|
|
135
|
+
# my_mock.should_receive(:sym).at_least(:once)
|
|
136
|
+
# my_mock.should_receive(:sym).at_least(:twice)
|
|
137
|
+
# my_mock.should_receive(:sym).at_least(n).times
|
|
138
|
+
# my_mock.should_receive(:sym).at_most(:once)
|
|
139
|
+
# my_mock.should_receive(:sym).at_most(:twice)
|
|
140
|
+
# my_mock.should_receive(:sym).at_most(n).times
|
|
141
|
+
# my_mock.should_receive(:sym).any_number_of_times
|
|
142
|
+
#
|
|
143
|
+
# == Ordering
|
|
144
|
+
#
|
|
145
|
+
# my_mock.should_receive(:sym).ordered
|
|
146
|
+
# my_mock.should_receive(:other_sym).ordered
|
|
147
|
+
# #This will fail if the messages are received out of order
|
|
148
|
+
#
|
|
149
|
+
# == Setting Reponses
|
|
150
|
+
#
|
|
151
|
+
# Whether you are setting a mock expectation or a simple stub, you can tell the
|
|
152
|
+
# object precisely how to respond:
|
|
153
|
+
#
|
|
154
|
+
# my_mock.should_receive(:sym).and_return(value)
|
|
155
|
+
# my_mock.should_receive(:sym).exactly(3).times.and_return(value1, value2, value3)
|
|
156
|
+
# # returns value1 the first time, value2 the second, etc
|
|
157
|
+
# my_mock.should_receive(:sym).and_return { ... } #returns value returned by the block
|
|
158
|
+
# my_mock.should_receive(:sym).and_raise(error)
|
|
159
|
+
# #error can be an instantiated object or a class
|
|
160
|
+
# #if it is a class, it must be instantiable with no args
|
|
161
|
+
# my_mock.should_receive(:sym).and_throw(:sym)
|
|
162
|
+
# my_mock.should_receive(:sym).and_yield(values,to,yield)
|
|
163
|
+
# my_mock.should_receive(:sym).and_yield(values,to,yield).and_yield(some,other,values,this,time)
|
|
164
|
+
# # for methods that yield to a block multiple times
|
|
165
|
+
#
|
|
166
|
+
# Any of these responses can be applied to a stub as well, but stubs do
|
|
167
|
+
# not support any qualifiers about the message received (i.e. you can't specify arguments
|
|
168
|
+
# or receive counts):
|
|
169
|
+
#
|
|
170
|
+
# my_mock.stub!(:sym).and_return(value)
|
|
171
|
+
# my_mock.stub!(:sym).and_return(value1, value2, value3)
|
|
172
|
+
# my_mock.stub!(:sym).and_raise(error)
|
|
173
|
+
# my_mock.stub!(:sym).and_throw(:sym)
|
|
174
|
+
# my_mock.stub!(:sym).and_yield(values,to,yield)
|
|
175
|
+
# my_mock.stub!(:sym).and_yield(values,to,yield).and_yield(some,other,values,this,time)
|
|
176
|
+
#
|
|
177
|
+
# == Arbitrary Handling
|
|
178
|
+
#
|
|
179
|
+
# Once in a while you'll find that the available expectations don't solve the
|
|
180
|
+
# particular problem you are trying to solve. Imagine that you expect the message
|
|
181
|
+
# to come with an Array argument that has a specific length, but you don't care
|
|
182
|
+
# what is in it. You could do this:
|
|
183
|
+
#
|
|
184
|
+
# my_mock.should_receive(:sym) do |arg|
|
|
185
|
+
# arg.should be_an_istance_of(Array)
|
|
186
|
+
# arg.length.should == 7
|
|
187
|
+
# end
|
|
188
|
+
#
|
|
189
|
+
# Note that this would fail if the number of arguments received was different from
|
|
190
|
+
# the number of block arguments (in this case 1).
|
|
191
|
+
#
|
|
192
|
+
# == Combining Expectation Details
|
|
193
|
+
#
|
|
194
|
+
# Combining the message name with specific arguments, receive counts and responses
|
|
195
|
+
# you can get quite a bit of detail in your expectations:
|
|
196
|
+
#
|
|
197
|
+
# my_mock.should_receive(:<<).with("illegal value").once.and_raise(ArgumentError)
|
|
198
|
+
module Mocks
|
|
199
|
+
end
|
|
200
|
+
end
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
# Define a task library for running RSpec contexts.
|
|
4
|
+
|
|
5
|
+
require 'rake'
|
|
6
|
+
require 'rake/tasklib'
|
|
7
|
+
|
|
8
|
+
module Spec
|
|
9
|
+
module Rake
|
|
10
|
+
|
|
11
|
+
# A Rake task that runs a set of specs.
|
|
12
|
+
#
|
|
13
|
+
# Example:
|
|
14
|
+
#
|
|
15
|
+
# Spec::Rake::SpecTask.new do |t|
|
|
16
|
+
# t.warning = true
|
|
17
|
+
# t.rcov = true
|
|
18
|
+
# end
|
|
19
|
+
#
|
|
20
|
+
# This will create a task that can be run with:
|
|
21
|
+
#
|
|
22
|
+
# rake spec
|
|
23
|
+
#
|
|
24
|
+
# If rake is invoked with a "SPEC=filename" command line option,
|
|
25
|
+
# then the list of spec files will be overridden to include only the
|
|
26
|
+
# filename specified on the command line. This provides an easy way
|
|
27
|
+
# to run just one spec.
|
|
28
|
+
#
|
|
29
|
+
# If rake is invoked with a "SPEC_OPTS=options" command line option,
|
|
30
|
+
# then the given options will override the value of the +spec_opts+
|
|
31
|
+
# attribute.
|
|
32
|
+
#
|
|
33
|
+
# If rake is invoked with a "RCOV_OPTS=options" command line option,
|
|
34
|
+
# then the given options will override the value of the +rcov_opts+
|
|
35
|
+
# attribute.
|
|
36
|
+
#
|
|
37
|
+
# Examples:
|
|
38
|
+
#
|
|
39
|
+
# rake spec # run specs normally
|
|
40
|
+
# rake spec SPEC=just_one_file.rb # run just one spec file.
|
|
41
|
+
# rake spec SPEC_OPTS="--diff" # enable diffing
|
|
42
|
+
# rake spec RCOV_OPTS="--aggregate myfile.txt" # see rcov --help for details
|
|
43
|
+
#
|
|
44
|
+
# Each attribute of this task may be a proc. This allows for lazy evaluation,
|
|
45
|
+
# which is sometimes handy if you want to defer the evaluation of an attribute value
|
|
46
|
+
# until the task is run (as opposed to when it is defined).
|
|
47
|
+
#
|
|
48
|
+
# This task can also be used to run existing Test::Unit tests and get RSpec
|
|
49
|
+
# output, for example like this:
|
|
50
|
+
#
|
|
51
|
+
# require 'rubygems'
|
|
52
|
+
# require 'spec/rake/spectask'
|
|
53
|
+
# Spec::Rake::SpecTask.new do |t|
|
|
54
|
+
# t.ruby_opts = ['-rtest/unit']
|
|
55
|
+
# t.spec_files = FileList['test/**/*_test.rb']
|
|
56
|
+
# end
|
|
57
|
+
#
|
|
58
|
+
class SpecTask < ::Rake::TaskLib
|
|
59
|
+
def self.attr_accessor(*names)
|
|
60
|
+
super(*names)
|
|
61
|
+
names.each do |name|
|
|
62
|
+
module_eval "def #{name}() evaluate(@#{name}) end" # Allows use of procs
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# Name of spec task. (default is :spec)
|
|
67
|
+
attr_accessor :name
|
|
68
|
+
|
|
69
|
+
# Array of directories to be added to $LOAD_PATH before running the
|
|
70
|
+
# specs. Defaults to ['<the absolute path to RSpec's lib directory>']
|
|
71
|
+
attr_accessor :libs
|
|
72
|
+
|
|
73
|
+
# If true, requests that the specs be run with the warning flag set.
|
|
74
|
+
# E.g. warning=true implies "ruby -w" used to run the specs. Defaults to false.
|
|
75
|
+
attr_accessor :warning
|
|
76
|
+
|
|
77
|
+
# Glob pattern to match spec files. (default is 'spec/**/*_spec.rb')
|
|
78
|
+
# Setting the SPEC environment variable overrides this.
|
|
79
|
+
attr_accessor :pattern
|
|
80
|
+
|
|
81
|
+
# Array of commandline options to pass to RSpec. Defaults to [].
|
|
82
|
+
# Setting the SPEC_OPTS environment variable overrides this.
|
|
83
|
+
attr_accessor :spec_opts
|
|
84
|
+
|
|
85
|
+
# Whether or not to use RCov (default is false)
|
|
86
|
+
# See http://eigenclass.org/hiki.rb?rcov
|
|
87
|
+
attr_accessor :rcov
|
|
88
|
+
|
|
89
|
+
# Array of commandline options to pass to RCov. Defaults to ['--exclude', 'lib\/spec,bin\/spec'].
|
|
90
|
+
# Ignored if rcov=false
|
|
91
|
+
# Setting the RCOV_OPTS environment variable overrides this.
|
|
92
|
+
attr_accessor :rcov_opts
|
|
93
|
+
|
|
94
|
+
# Directory where the RCov report is written. Defaults to "coverage"
|
|
95
|
+
# Ignored if rcov=false
|
|
96
|
+
attr_accessor :rcov_dir
|
|
97
|
+
|
|
98
|
+
# Array of commandline options to pass to ruby. Defaults to [].
|
|
99
|
+
attr_accessor :ruby_opts
|
|
100
|
+
|
|
101
|
+
# Whether or not to fail Rake when an error occurs (typically when specs fail).
|
|
102
|
+
# Defaults to true.
|
|
103
|
+
attr_accessor :fail_on_error
|
|
104
|
+
|
|
105
|
+
# A message to print to stderr when there are failures.
|
|
106
|
+
attr_accessor :failure_message
|
|
107
|
+
|
|
108
|
+
# Where RSpec's output is written. Defaults to $stdout.
|
|
109
|
+
# DEPRECATED. Use --format FORMAT:WHERE in spec_opts.
|
|
110
|
+
attr_accessor :out
|
|
111
|
+
|
|
112
|
+
# Explicitly define the list of spec files to be included in a
|
|
113
|
+
# spec. +spec_files+ is expected to be an array of file names (a
|
|
114
|
+
# FileList is acceptable). If both +pattern+ and +spec_files+ are
|
|
115
|
+
# used, then the list of spec files is the union of the two.
|
|
116
|
+
# Setting the SPEC environment variable overrides this.
|
|
117
|
+
attr_accessor :spec_files
|
|
118
|
+
|
|
119
|
+
# Use verbose output. If this is set to true, the task will print
|
|
120
|
+
# the executed spec command to stdout. Defaults to false.
|
|
121
|
+
attr_accessor :verbose
|
|
122
|
+
|
|
123
|
+
# Defines a new task, using the name +name+.
|
|
124
|
+
def initialize(name=:spec)
|
|
125
|
+
@name = name
|
|
126
|
+
@libs = [File.expand_path(File.dirname(__FILE__) + '/../../../lib')]
|
|
127
|
+
@pattern = nil
|
|
128
|
+
@spec_files = nil
|
|
129
|
+
@spec_opts = []
|
|
130
|
+
@warning = false
|
|
131
|
+
@ruby_opts = []
|
|
132
|
+
@fail_on_error = true
|
|
133
|
+
@rcov = false
|
|
134
|
+
@rcov_opts = ['--exclude', 'lib\/spec,bin\/spec,config\/boot.rb']
|
|
135
|
+
@rcov_dir = "coverage"
|
|
136
|
+
|
|
137
|
+
yield self if block_given?
|
|
138
|
+
@pattern = 'spec/**/*_spec.rb' if pattern.nil? && spec_files.nil?
|
|
139
|
+
define
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def define # :nodoc:
|
|
143
|
+
spec_script = File.expand_path(File.dirname(__FILE__) + '/../../../bin/spec')
|
|
144
|
+
|
|
145
|
+
lib_path = libs.join(File::PATH_SEPARATOR)
|
|
146
|
+
actual_name = Hash === name ? name.keys.first : name
|
|
147
|
+
unless ::Rake.application.last_comment
|
|
148
|
+
desc "Run specs" + (rcov ? " using RCov" : "")
|
|
149
|
+
end
|
|
150
|
+
task name do
|
|
151
|
+
RakeFileUtils.verbose(verbose) do
|
|
152
|
+
unless spec_file_list.empty?
|
|
153
|
+
# ruby [ruby_opts] -Ilib -S rcov [rcov_opts] bin/spec -- examples [spec_opts]
|
|
154
|
+
# or
|
|
155
|
+
# ruby [ruby_opts] -Ilib bin/spec examples [spec_opts]
|
|
156
|
+
cmd_parts = [RUBY]
|
|
157
|
+
cmd_parts += ruby_opts
|
|
158
|
+
cmd_parts << %[-I"#{lib_path}"]
|
|
159
|
+
cmd_parts << "-S rcov" if rcov
|
|
160
|
+
cmd_parts << "-w" if warning
|
|
161
|
+
cmd_parts << rcov_option_list
|
|
162
|
+
cmd_parts << %[-o "#{rcov_dir}"] if rcov
|
|
163
|
+
cmd_parts << %["#{spec_script}"]
|
|
164
|
+
cmd_parts << "--" if rcov
|
|
165
|
+
cmd_parts += spec_file_list.collect { |fn| %["#{fn}"] }
|
|
166
|
+
cmd_parts << spec_option_list
|
|
167
|
+
if out
|
|
168
|
+
cmd_parts << %[> "#{out}"]
|
|
169
|
+
STDERR.puts "The Spec::Rake::SpecTask#out attribute is DEPRECATED and will be removed in a future version. Use --format FORMAT:WHERE instead."
|
|
170
|
+
end
|
|
171
|
+
cmd = cmd_parts.join(" ")
|
|
172
|
+
puts cmd if verbose
|
|
173
|
+
unless system(cmd)
|
|
174
|
+
STDERR.puts failure_message if failure_message
|
|
175
|
+
raise("Command #{cmd} failed") if fail_on_error
|
|
176
|
+
end
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
if rcov
|
|
182
|
+
desc "Remove rcov products for #{actual_name}"
|
|
183
|
+
task paste("clobber_", actual_name) do
|
|
184
|
+
rm_r rcov_dir rescue nil
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
clobber_task = paste("clobber_", actual_name)
|
|
188
|
+
task :clobber => [clobber_task]
|
|
189
|
+
|
|
190
|
+
task actual_name => clobber_task
|
|
191
|
+
end
|
|
192
|
+
self
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
def rcov_option_list # :nodoc:
|
|
196
|
+
return "" unless rcov
|
|
197
|
+
ENV['RCOV_OPTS'] || rcov_opts.join(" ") || ""
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
def spec_option_list # :nodoc:
|
|
201
|
+
STDERR.puts "RSPECOPTS is DEPRECATED and will be removed in a future version. Use SPEC_OPTS instead." if ENV['RSPECOPTS']
|
|
202
|
+
ENV['SPEC_OPTS'] || ENV['RSPECOPTS'] || spec_opts.join(" ") || ""
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
def evaluate(o) # :nodoc:
|
|
206
|
+
case o
|
|
207
|
+
when Proc then o.call
|
|
208
|
+
else o
|
|
209
|
+
end
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
def spec_file_list # :nodoc:
|
|
213
|
+
if ENV['SPEC']
|
|
214
|
+
FileList[ ENV['SPEC'] ]
|
|
215
|
+
else
|
|
216
|
+
result = []
|
|
217
|
+
result += spec_files.to_a if spec_files
|
|
218
|
+
result += FileList[ pattern ].to_a if pattern
|
|
219
|
+
FileList[result]
|
|
220
|
+
end
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
end
|
|
224
|
+
end
|
|
225
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
module RCov
|
|
2
|
+
# A task that can verify that the RCov coverage doesn't
|
|
3
|
+
# drop below a certain threshold. It should be run after
|
|
4
|
+
# running Spec::Rake::SpecTask.
|
|
5
|
+
class VerifyTask < Rake::TaskLib
|
|
6
|
+
# Name of the task. Defaults to :verify_rcov
|
|
7
|
+
attr_accessor :name
|
|
8
|
+
|
|
9
|
+
# Path to the index.html file generated by RCov, which
|
|
10
|
+
# is the file containing the total coverage.
|
|
11
|
+
# Defaults to 'coverage/index.html'
|
|
12
|
+
attr_accessor :index_html
|
|
13
|
+
|
|
14
|
+
# Whether or not to output details. Defaults to true.
|
|
15
|
+
attr_accessor :verbose
|
|
16
|
+
|
|
17
|
+
# The threshold value (in percent) for coverage. If the
|
|
18
|
+
# actual coverage is not equal to this value, the task will raise an
|
|
19
|
+
# exception.
|
|
20
|
+
attr_accessor :threshold
|
|
21
|
+
|
|
22
|
+
# Require the threshold value be met exactly. This is the default.
|
|
23
|
+
attr_accessor :require_exact_threshold
|
|
24
|
+
|
|
25
|
+
def initialize(name=:verify_rcov)
|
|
26
|
+
@name = name
|
|
27
|
+
@index_html = 'coverage/index.html'
|
|
28
|
+
@verbose = true
|
|
29
|
+
@require_exact_threshold = true
|
|
30
|
+
yield self if block_given?
|
|
31
|
+
raise "Threshold must be set" if @threshold.nil?
|
|
32
|
+
define
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def define
|
|
36
|
+
desc "Verify that rcov coverage is at least #{threshold}%"
|
|
37
|
+
task @name do
|
|
38
|
+
total_coverage = 0
|
|
39
|
+
|
|
40
|
+
File.open(index_html).each_line do |line|
|
|
41
|
+
if line =~ /<tt class='coverage_total'>\s*(\d+\.\d+)%\s*<\/tt>/
|
|
42
|
+
total_coverage = $1.to_f
|
|
43
|
+
break
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
puts "Coverage: #{total_coverage}% (threshold: #{threshold}%)" if verbose
|
|
47
|
+
raise "Coverage must be at least #{threshold}% but was #{total_coverage}%" if total_coverage < threshold
|
|
48
|
+
raise "Coverage has increased above the threshold of #{threshold}% to #{total_coverage}%. You should update your threshold value." if (total_coverage > threshold) and require_exact_threshold
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
data/lib/spec/ruby.rb
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
module Spec
|
|
2
|
+
module Runner
|
|
3
|
+
class BacktraceTweaker
|
|
4
|
+
def clean_up_double_slashes(line)
|
|
5
|
+
line.gsub!('//','/')
|
|
6
|
+
end
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
class NoisyBacktraceTweaker < BacktraceTweaker
|
|
10
|
+
def tweak_backtrace(error)
|
|
11
|
+
return if error.backtrace.nil?
|
|
12
|
+
tweaked = error.backtrace.collect do |line|
|
|
13
|
+
clean_up_double_slashes(line)
|
|
14
|
+
line
|
|
15
|
+
end
|
|
16
|
+
error.set_backtrace(tweaked)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Tweaks raised Exceptions to mask noisy (unneeded) parts of the backtrace
|
|
21
|
+
class QuietBacktraceTweaker < BacktraceTweaker
|
|
22
|
+
unless defined?(IGNORE_PATTERNS)
|
|
23
|
+
root_dir = File.expand_path(File.join(__FILE__, '..', '..', '..', '..'))
|
|
24
|
+
spec_files = Dir["#{root_dir}/lib/*"].map do |path|
|
|
25
|
+
subpath = path[root_dir.length..-1]
|
|
26
|
+
/#{subpath}/
|
|
27
|
+
end
|
|
28
|
+
IGNORE_PATTERNS = spec_files + [
|
|
29
|
+
/\/lib\/ruby\//,
|
|
30
|
+
/bin\/spec:/,
|
|
31
|
+
/bin\/rcov:/,
|
|
32
|
+
/lib\/rspec-rails/,
|
|
33
|
+
/vendor\/rails/,
|
|
34
|
+
# TextMate's Ruby and RSpec plugins
|
|
35
|
+
/Ruby\.tmbundle\/Support\/tmruby.rb:/,
|
|
36
|
+
/RSpec\.tmbundle\/Support\/lib/,
|
|
37
|
+
/temp_textmate\./,
|
|
38
|
+
/mock_frameworks\/rspec/,
|
|
39
|
+
/spec_server/
|
|
40
|
+
]
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def tweak_backtrace(error)
|
|
44
|
+
return if error.backtrace.nil?
|
|
45
|
+
tweaked = error.backtrace.collect do |message|
|
|
46
|
+
clean_up_double_slashes(message)
|
|
47
|
+
kept_lines = message.split("\n").select do |line|
|
|
48
|
+
IGNORE_PATTERNS.each do |ignore|
|
|
49
|
+
break if line =~ ignore
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
kept_lines.empty?? nil : kept_lines.join("\n")
|
|
53
|
+
end
|
|
54
|
+
error.set_backtrace(tweaked.select {|line| line})
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
require 'spec/runner/option_parser'
|
|
2
|
+
require 'rubygems'
|
|
3
|
+
require 'eventmachine'
|
|
4
|
+
|
|
5
|
+
module Spec
|
|
6
|
+
module Runner
|
|
7
|
+
class CommandLine
|
|
8
|
+
|
|
9
|
+
def self.run(tmp_options=Spec::Runner.options)
|
|
10
|
+
orig_options = Spec::Runner.options
|
|
11
|
+
Spec::Runner.use tmp_options
|
|
12
|
+
tmp_options.run_examples
|
|
13
|
+
ensure
|
|
14
|
+
Spec::Runner.use orig_options
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def self.evented_run(tmp_options=Spec::Runner.options)
|
|
19
|
+
EM.run do
|
|
20
|
+
begin
|
|
21
|
+
original_run(tmp_options)
|
|
22
|
+
ensure
|
|
23
|
+
EM.add_timer(3) {EventMachine::stop}
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class << self
|
|
30
|
+
alias :original_run :run
|
|
31
|
+
alias :run :evented_run
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|