rspec 1.1.12 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.autotest +2 -1
- data/.document +7 -0
- data/History.txt +58 -0
- data/License.txt +1 -1
- data/Manifest.txt +45 -82
- data/README.txt +3 -6
- data/Rakefile +33 -13
- data/Ruby1.9.markdown +32 -0
- data/TODO.txt +10 -4
- data/Upgrade.markdown +63 -0
- data/bin/spec +1 -1
- data/cucumber.yml +3 -0
- data/examples/failing/{failing_autogenerated_docstrings_example.rb → failing_implicit_docstrings_example.rb} +0 -0
- data/examples/failing/pending_example.rb +9 -0
- data/examples/failing/spec_helper.rb +1 -1
- data/examples/passing/{custom_expectation_matchers.rb → custom_matchers.rb} +0 -0
- data/examples/passing/filtered_formatter.rb +18 -0
- data/examples/passing/filtered_formatter_example.rb +31 -0
- data/examples/passing/implicit_docstrings_example.rb +18 -0
- data/examples/passing/spec_helper.rb +1 -1
- data/examples/ruby1.9.compatibility/access_to_constants_spec.rb +17 -18
- data/features/before_and_after_blocks/before_and_after_blocks.feature +4 -4
- data/features/example_groups/example_group_with_should_methods.feature +1 -1
- data/features/example_groups/{autogenerated_docstrings.feature → implicit_docstrings.feature} +7 -9
- data/features/example_groups/nested_groups.feature +1 -1
- data/features/heckle/heckle.feature +56 -0
- data/features/interop/examples_and_tests_together.feature +1 -1
- data/features/interop/test_but_not_test_unit.feature +1 -1
- data/features/interop/test_case_with_should_methods.feature +1 -1
- data/features/matchers/create_matcher.feature +115 -0
- data/features/mock_framework_integration/use_flexmock.feature +22 -4
- data/features/mock_framework_integration/use_mocha.feature +27 -0
- data/features/mock_framework_integration/use_rr.feature +27 -0
- data/features/mocks/mix_stubs_and_mocks.feature +22 -0
- data/features/pending/pending_examples.feature +81 -0
- data/features/step_definitions/running_rspec.rb +5 -3
- data/features/support/env.rb +1 -1
- data/features/support/matchers/smart_match.rb +2 -2
- data/lib/autotest/rspec.rb +1 -1
- data/lib/spec.rb +1 -1
- data/lib/{adapters → spec/adapters}/mock_frameworks/flexmock.rb +0 -0
- data/lib/{adapters → spec/adapters}/mock_frameworks/mocha.rb +0 -0
- data/lib/{adapters → spec/adapters}/mock_frameworks/rr.rb +0 -0
- data/lib/{adapters → spec/adapters}/mock_frameworks/rspec.rb +0 -1
- data/lib/spec/autorun.rb +3 -0
- data/lib/spec/dsl.rb +3 -1
- data/lib/spec/dsl/matchers.rb +13 -0
- data/lib/spec/example.rb +4 -0
- data/lib/spec/example/before_and_after_hooks.rb +5 -20
- data/lib/spec/example/errors.rb +3 -3
- data/lib/spec/example/example_description.rb +15 -0
- data/lib/spec/example/example_group.rb +0 -15
- data/lib/spec/example/example_group_factory.rb +34 -46
- data/lib/spec/example/example_group_hierarchy.rb +53 -0
- data/lib/spec/example/example_group_methods.rb +101 -211
- data/lib/spec/example/example_methods.rb +61 -81
- data/lib/spec/example/module_reopening_fix.rb +23 -1
- data/lib/spec/example/pending.rb +3 -2
- data/lib/spec/example/predicate_matchers.rb +47 -0
- data/lib/spec/example/subject.rb +91 -0
- data/lib/spec/expectations.rb +1 -1
- data/lib/spec/expectations/differs/default.rb +0 -1
- data/lib/spec/expectations/extensions.rb +0 -1
- data/lib/spec/expectations/handler.rb +13 -6
- data/lib/spec/interop/test.rb +5 -0
- data/lib/spec/interop/test/unit/testcase.rb +5 -22
- data/lib/spec/matchers.rb +22 -8
- data/lib/spec/matchers/be.rb +4 -9
- data/lib/spec/matchers/be_close.rb +20 -5
- data/lib/spec/matchers/be_instance_of.rb +45 -0
- data/lib/spec/matchers/be_kind_of.rb +45 -0
- data/lib/spec/matchers/change.rb +8 -6
- data/lib/spec/matchers/compatibility.rb +14 -0
- data/lib/spec/matchers/eql.rb +24 -6
- data/lib/spec/matchers/equal.rb +24 -6
- data/lib/spec/matchers/exist.rb +21 -5
- data/lib/spec/matchers/extensions/instance_exec.rb +25 -0
- data/lib/spec/matchers/generated_descriptions.rb +2 -2
- data/lib/spec/matchers/has.rb +28 -11
- data/lib/spec/matchers/have.rb +2 -2
- data/lib/spec/matchers/include.rb +2 -2
- data/lib/spec/matchers/match.rb +25 -7
- data/lib/spec/matchers/match_array.rb +3 -3
- data/lib/spec/matchers/matcher.rb +51 -0
- data/lib/spec/matchers/method_missing.rb +2 -2
- data/lib/spec/matchers/operator_matcher.rb +12 -5
- data/lib/spec/matchers/raise_error.rb +3 -3
- data/lib/spec/matchers/respond_to.rb +3 -3
- data/lib/spec/matchers/satisfy.rb +7 -7
- data/lib/spec/matchers/throw_symbol.rb +3 -5
- data/lib/spec/mocks.rb +3 -3
- data/lib/spec/mocks/argument_expectation.rb +15 -15
- data/lib/spec/mocks/{argument_constraints.rb → argument_matchers.rb} +19 -23
- data/lib/spec/mocks/error_generator.rb +5 -8
- data/lib/spec/mocks/framework.rb +1 -1
- data/lib/spec/mocks/message_expectation.rb +5 -13
- data/lib/spec/mocks/mock.rb +4 -5
- data/lib/spec/mocks/proxy.rb +9 -5
- data/lib/spec/mocks/spec_methods.rb +10 -1
- data/lib/spec/rake/spectask.rb +0 -1
- data/lib/spec/runner.rb +6 -28
- data/lib/spec/runner/configuration.rb +3 -3
- data/lib/spec/runner/drb_command_line.rb +2 -1
- data/lib/spec/runner/example_group_runner.rb +3 -2
- data/lib/spec/runner/formatter/base_text_formatter.rb +34 -19
- data/lib/spec/runner/formatter/failing_example_groups_formatter.rb +3 -5
- data/lib/spec/runner/formatter/html_formatter.rb +2 -3
- data/lib/spec/runner/formatter/nested_text_formatter.rb +7 -25
- data/lib/spec/runner/formatter/progress_bar_formatter.rb +1 -1
- data/lib/spec/runner/formatter/snippet_extractor.rb +1 -1
- data/lib/spec/runner/formatter/specdoc_formatter.rb +1 -7
- data/lib/spec/runner/heckle_runner.rb +3 -6
- data/lib/spec/runner/heckle_runner_unsupported.rb +1 -1
- data/lib/spec/runner/option_parser.rb +19 -21
- data/lib/spec/runner/options.rb +32 -27
- data/lib/spec/runner/reporter.rb +8 -9
- data/lib/spec/test/unit.rb +10 -0
- data/lib/spec/version.rb +2 -2
- data/{features/support → resources}/helpers/cmdline.rb +2 -2
- data/resources/rake/verify_rcov.rake +1 -1
- data/resources/spec/example_group_with_should_methods.rb +1 -1
- data/resources/spec/simple_spec.rb +1 -1
- data/resources/test/spec_and_test_together.rb +2 -3
- data/resources/test/spec_including_test_but_not_unit.rb +1 -1
- data/resources/test/test_case_with_should_methods.rb +2 -3
- data/spec/autotest/autotest_helper.rb +0 -1
- data/spec/autotest/rspec_spec.rb +95 -98
- data/spec/spec/dsl/main_spec.rb +3 -3
- data/spec/spec/dsl/matchers_spec.rb +25 -0
- data/spec/spec/example/example_group_class_definition_spec.rb +14 -15
- data/spec/spec/example/example_group_factory_spec.rb +31 -44
- data/spec/spec/example/example_group_methods_spec.rb +86 -52
- data/spec/spec/example/example_group_spec.rb +32 -79
- data/spec/spec/example/example_matcher_spec.rb +10 -10
- data/spec/spec/example/example_methods_spec.rb +108 -242
- data/spec/spec/example/nested_example_group_spec.rb +2 -2
- data/spec/spec/example/pending_module_spec.rb +66 -41
- data/spec/spec/example/shared_example_group_spec.rb +4 -4
- data/spec/spec/{matchers → expectations}/handler_spec.rb +52 -4
- data/spec/spec/interop/test/unit/resources/spec_that_fails.rb +2 -2
- data/spec/spec/interop/test/unit/resources/spec_that_passes.rb +2 -2
- data/spec/spec/interop/test/unit/resources/spec_with_errors.rb +2 -2
- data/spec/spec/interop/test/unit/resources/spec_with_options_hash.rb +2 -2
- data/spec/spec/interop/test/unit/resources/test_case_that_fails.rb +2 -2
- data/spec/spec/interop/test/unit/resources/test_case_that_passes.rb +2 -2
- data/spec/spec/interop/test/unit/resources/test_case_with_errors.rb +2 -2
- data/spec/spec/interop/test/unit/resources/testsuite_adapter_spec_with_test_unit.rb +2 -2
- data/spec/spec/interop/test/unit/testcase_spec.rb +0 -4
- data/spec/spec/matchers/be_close_spec.rb +1 -1
- data/spec/spec/matchers/be_instance_of_spec.rb +29 -0
- data/spec/spec/matchers/be_kind_of_spec.rb +29 -0
- data/spec/spec/matchers/change_spec.rb +20 -0
- data/spec/spec/matchers/compatibility_spec.rb +34 -0
- data/spec/spec/matchers/description_generation_spec.rb +0 -12
- data/spec/spec/matchers/eql_spec.rb +2 -2
- data/spec/spec/matchers/equal_spec.rb +2 -2
- data/spec/spec/matchers/exist_spec.rb +8 -4
- data/spec/spec/matchers/have_spec.rb +4 -4
- data/spec/spec/matchers/match_spec.rb +2 -2
- data/spec/spec/matchers/matcher_methods_spec.rb +1 -1
- data/spec/spec/matchers/matcher_spec.rb +97 -0
- data/spec/spec/matchers/throw_symbol_spec.rb +8 -8
- data/spec/spec/mocks/{bug_report_496.rb → bug_report_496_spec.rb} +0 -0
- data/spec/spec/mocks/{failing_mock_argument_constraints_spec.rb → failing_argument_matchers_spec.rb} +2 -2
- data/spec/spec/mocks/hash_including_matcher_spec.rb +4 -4
- data/spec/spec/mocks/hash_not_including_matcher_spec.rb +3 -3
- data/spec/spec/mocks/mock_spec.rb +27 -2
- data/spec/spec/mocks/nil_expectation_warning_spec.rb +1 -1
- data/spec/spec/mocks/partial_mock_spec.rb +18 -3
- data/spec/spec/mocks/{passing_mock_argument_constraints_spec.rb → passing_argument_matchers_spec.rb} +6 -6
- data/spec/spec/mocks/stubbed_message_expectations_spec.rb +13 -1
- data/spec/spec/package/bin_spec_spec.rb +2 -2
- data/spec/spec/runner/configuration_spec.rb +12 -12
- data/spec/spec/runner/drb_command_line_spec.rb +71 -73
- data/spec/spec/runner/formatter/base_text_formatter_spec.rb +82 -1
- data/spec/spec/runner/formatter/failing_example_groups_formatter_spec.rb +8 -8
- data/spec/spec/runner/formatter/failing_examples_formatter_spec.rb +4 -4
- data/spec/spec/runner/formatter/html_formatted-1.8.6.html +8 -8
- data/spec/spec/runner/formatter/html_formatted-1.8.7.html +38 -26
- data/spec/spec/runner/formatter/html_formatted-1.9.1.html +61 -53
- data/spec/spec/runner/formatter/html_formatter_spec.rb +100 -48
- data/spec/spec/runner/formatter/nested_text_formatter_spec.rb +20 -34
- data/spec/spec/runner/formatter/profile_formatter_spec.rb +2 -1
- data/spec/spec/runner/formatter/progress_bar_formatter_spec.rb +9 -6
- data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +6 -6
- data/spec/spec/runner/formatter/text_mate_formatted-1.8.6.html +20 -20
- data/spec/spec/runner/formatter/text_mate_formatted-1.8.7.html +38 -26
- data/spec/spec/runner/formatter/text_mate_formatted-1.9.1.html +55 -47
- data/spec/spec/runner/formatter/{spec_mate_formatter_spec.rb → text_mate_formatter_spec.rb} +11 -9
- data/spec/spec/runner/heckle_runner_spec.rb +1 -1
- data/spec/spec/runner/heckler_spec.rb +1 -1
- data/spec/spec/runner/option_parser_spec.rb +28 -11
- data/spec/spec/runner/options_spec.rb +34 -0
- data/spec/spec/runner/reporter_spec.rb +66 -62
- data/spec/spec/runner/resources/utf8_encoded.rb +1 -0
- data/spec/spec/runner/spec_drb.opts +1 -0
- data/spec/spec/runner_spec.rb +7 -5
- data/spec/spec_helper.rb +24 -2
- metadata +49 -90
- data/examples/passing/autogenerated_docstrings_example.rb +0 -25
- data/examples/passing/before_and_after_example.rb +0 -40
- data/examples/passing/behave_as_example.rb +0 -45
- data/examples/passing/legacy_spec.rb +0 -11
- data/examples/passing/priority.txt +0 -1
- data/features/support/helpers/story_helper.rb +0 -16
- data/lib/spec/expectations/extensions/string_and_symbol.rb +0 -17
- data/lib/spec/runner/formatter/story/html_formatter.rb +0 -174
- data/lib/spec/runner/formatter/story/plain_text_formatter.rb +0 -194
- data/lib/spec/runner/formatter/story/progress_bar_formatter.rb +0 -42
- data/lib/spec/story.rb +0 -10
- data/lib/spec/story/extensions.rb +0 -3
- data/lib/spec/story/extensions/main.rb +0 -86
- data/lib/spec/story/extensions/regexp.rb +0 -9
- data/lib/spec/story/extensions/string.rb +0 -9
- data/lib/spec/story/given_scenario.rb +0 -14
- data/lib/spec/story/runner.rb +0 -57
- data/lib/spec/story/runner/plain_text_story_runner.rb +0 -48
- data/lib/spec/story/runner/scenario_collector.rb +0 -18
- data/lib/spec/story/runner/scenario_runner.rb +0 -54
- data/lib/spec/story/runner/story_mediator.rb +0 -137
- data/lib/spec/story/runner/story_parser.rb +0 -247
- data/lib/spec/story/runner/story_runner.rb +0 -74
- data/lib/spec/story/scenario.rb +0 -14
- data/lib/spec/story/step.rb +0 -70
- data/lib/spec/story/step_group.rb +0 -89
- data/lib/spec/story/step_mother.rb +0 -38
- data/lib/spec/story/story.rb +0 -39
- data/lib/spec/story/world.rb +0 -124
- data/resources/spec/spec_with_flexmock.rb +0 -19
- data/rspec.gemspec +0 -32
- data/spec/spec/matchers/mock_constraint_matchers_spec.rb +0 -24
- data/spec/spec/runner/formatter/story/html_formatter_spec.rb +0 -135
- data/spec/spec/runner/formatter/story/plain_text_formatter_spec.rb +0 -600
- data/spec/spec/runner/formatter/story/progress_bar_formatter_spec.rb +0 -82
- data/spec/spec/spec_spec.rb +0 -21
- data/spec/spec/story/builders.rb +0 -46
- data/spec/spec/story/extensions/main_spec.rb +0 -161
- data/spec/spec/story/extensions_spec.rb +0 -14
- data/spec/spec/story/given_scenario_spec.rb +0 -27
- data/spec/spec/story/runner/plain_text_story_runner_spec.rb +0 -90
- data/spec/spec/story/runner/scenario_collector_spec.rb +0 -27
- data/spec/spec/story/runner/scenario_runner_spec.rb +0 -214
- data/spec/spec/story/runner/story_mediator_spec.rb +0 -143
- data/spec/spec/story/runner/story_parser_spec.rb +0 -401
- data/spec/spec/story/runner/story_runner_spec.rb +0 -294
- data/spec/spec/story/runner_spec.rb +0 -93
- data/spec/spec/story/scenario_spec.rb +0 -18
- data/spec/spec/story/step_group_spec.rb +0 -157
- data/spec/spec/story/step_mother_spec.rb +0 -84
- data/spec/spec/story/step_spec.rb +0 -272
- data/spec/spec/story/story_helper.rb +0 -2
- data/spec/spec/story/story_spec.rb +0 -84
- data/spec/spec/story/world_spec.rb +0 -423
- data/story_server/prototype/javascripts/builder.js +0 -136
- data/story_server/prototype/javascripts/controls.js +0 -972
- data/story_server/prototype/javascripts/dragdrop.js +0 -976
- data/story_server/prototype/javascripts/effects.js +0 -1117
- data/story_server/prototype/javascripts/prototype.js +0 -4140
- data/story_server/prototype/javascripts/rspec.js +0 -149
- data/story_server/prototype/javascripts/scriptaculous.js +0 -58
- data/story_server/prototype/javascripts/slider.js +0 -276
- data/story_server/prototype/javascripts/sound.js +0 -55
- data/story_server/prototype/javascripts/unittest.js +0 -568
- data/story_server/prototype/lib/server.rb +0 -24
- data/story_server/prototype/stories.html +0 -176
- data/story_server/prototype/stylesheets/rspec.css +0 -136
- data/story_server/prototype/stylesheets/test.css +0 -90
@@ -2,54 +2,41 @@ module Spec
|
|
2
2
|
module Example
|
3
3
|
module ExampleMethods
|
4
4
|
|
5
|
-
extend
|
6
|
-
|
7
|
-
def subject # :nodoc: this is somewhat experimental
|
8
|
-
@subject ||= ( instance_variable_get(subject_variable_name) ||
|
9
|
-
instance_eval(&self.class.subject_block) ||
|
10
|
-
(described_class ? described_class.new : nil) )
|
11
|
-
end
|
12
|
-
|
13
|
-
# When +should+ is called with no explicit receiver, the call is
|
14
|
-
# delegated to the *subject* of the example group. This could be either
|
15
|
-
# an explicit subject generated by calling the block passed to
|
16
|
-
# +ExampleGroupMethods#subject+, or, if the group is describing a class,
|
17
|
-
# an implicitly generated instance of that class.
|
18
|
-
def should(matcher=nil)
|
19
|
-
if matcher
|
20
|
-
subject.should(matcher)
|
21
|
-
else
|
22
|
-
subject.should
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
# Just like +should+, +should_not+ delegates to the subject (implicit or
|
27
|
-
# explicit) of the example group.
|
28
|
-
def should_not(matcher)
|
29
|
-
subject.should_not(matcher)
|
30
|
-
end
|
5
|
+
extend Spec::Example::ModuleReopeningFix
|
6
|
+
include Spec::Example::Subject::ExampleMethods
|
31
7
|
|
32
8
|
def violated(message="")
|
33
9
|
raise Spec::Expectations::ExpectationNotMetError.new(message)
|
34
10
|
end
|
35
11
|
|
12
|
+
# Declared description for this example:
|
13
|
+
#
|
14
|
+
# describe Account do
|
15
|
+
# it "should start with a balance of 0" do
|
16
|
+
# ...
|
17
|
+
#
|
18
|
+
# description
|
19
|
+
# => "should start with a balance of 0"
|
36
20
|
def description
|
37
21
|
@_defined_description || ::Spec::Matchers.generated_description || "NO NAME"
|
38
22
|
end
|
39
23
|
|
40
|
-
def options
|
24
|
+
def options # :nodoc:
|
41
25
|
@_options
|
42
26
|
end
|
43
27
|
|
44
|
-
def execute(
|
45
|
-
|
28
|
+
def execute(run_options, instance_variables) # :nodoc:
|
29
|
+
# FIXME - there is no reason to have example_started pass a name
|
30
|
+
# - in fact, it would introduce bugs in cases where no docstring
|
31
|
+
# is passed to it()
|
32
|
+
run_options.reporter.example_started("")
|
46
33
|
set_instance_variables_from_hash(instance_variables)
|
47
34
|
|
48
35
|
execution_error = nil
|
49
|
-
Timeout.timeout(
|
36
|
+
Timeout.timeout(run_options.timeout) do
|
50
37
|
begin
|
51
38
|
before_each_example
|
52
|
-
|
39
|
+
instance_eval(&@_implementation)
|
53
40
|
rescue Exception => e
|
54
41
|
execution_error ||= e
|
55
42
|
end
|
@@ -60,28 +47,19 @@ module Spec
|
|
60
47
|
end
|
61
48
|
end
|
62
49
|
|
63
|
-
|
50
|
+
run_options.reporter.example_finished(ExampleDescription.new(description, options), execution_error)
|
64
51
|
success = execution_error.nil? || ExamplePendingError === execution_error
|
65
52
|
end
|
66
53
|
|
67
|
-
def
|
68
|
-
|
69
|
-
variable_hash[variable_name] = instance_variable_get(variable_name)
|
70
|
-
variable_hash
|
71
|
-
end
|
54
|
+
def eval_each_fail_fast(blocks) # :nodoc:
|
55
|
+
blocks.each {|block| instance_eval(&block)}
|
72
56
|
end
|
73
57
|
|
74
|
-
def
|
75
|
-
examples.each do |example|
|
76
|
-
instance_eval(&example)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def eval_each_fail_slow(examples) # :nodoc:
|
58
|
+
def eval_each_fail_slow(blocks) # :nodoc:
|
81
59
|
first_exception = nil
|
82
|
-
|
60
|
+
blocks.each do |block|
|
83
61
|
begin
|
84
|
-
instance_eval(&
|
62
|
+
instance_eval(&block)
|
85
63
|
rescue Exception => e
|
86
64
|
first_exception ||= e
|
87
65
|
end
|
@@ -89,31 +67,22 @@ module Spec
|
|
89
67
|
raise first_exception if first_exception
|
90
68
|
end
|
91
69
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
#
|
98
|
-
# full_description
|
99
|
-
# => "Account should start with a balance of 0"
|
100
|
-
def full_description
|
101
|
-
"#{self.class.description} #{self.description}"
|
70
|
+
def instance_variable_hash # :nodoc:
|
71
|
+
instance_variables.inject({}) do |variable_hash, variable_name|
|
72
|
+
variable_hash[variable_name] = instance_variable_get(variable_name)
|
73
|
+
variable_hash
|
74
|
+
end
|
102
75
|
end
|
103
|
-
|
76
|
+
|
104
77
|
def set_instance_variables_from_hash(ivars) # :nodoc:
|
105
78
|
ivars.each do |variable_name, value|
|
106
79
|
# Ruby 1.9 requires variable.to_s on the next line
|
107
|
-
unless ['@
|
80
|
+
unless ['@_defined_description', '@_options', '@_implementation', '@method_name'].include?(variable_name.to_s)
|
108
81
|
instance_variable_set variable_name, value
|
109
82
|
end
|
110
83
|
end
|
111
84
|
end
|
112
85
|
|
113
|
-
def eval_block # :nodoc:
|
114
|
-
instance_eval(&@_implementation)
|
115
|
-
end
|
116
|
-
|
117
86
|
# Provides the backtrace up to where this example was declared.
|
118
87
|
def backtrace
|
119
88
|
@_backtrace
|
@@ -127,42 +96,53 @@ from a future version. Please use ExampleMethods#backtrace instead.
|
|
127
96
|
WARNING
|
128
97
|
backtrace
|
129
98
|
end
|
99
|
+
|
100
|
+
# Run all the before(:each) blocks for this example
|
101
|
+
def run_before_each
|
102
|
+
example_group_hierarchy.run_before_each(self)
|
103
|
+
end
|
104
|
+
|
105
|
+
# Run all the after(:each) blocks for this example
|
106
|
+
def run_after_each
|
107
|
+
example_group_hierarchy.run_after_each(self)
|
108
|
+
end
|
130
109
|
|
131
|
-
|
110
|
+
def initialize(description, options={}, &implementation)
|
111
|
+
@_options = options
|
112
|
+
@_defined_description = description
|
113
|
+
@_implementation = implementation
|
114
|
+
@_backtrace = caller
|
115
|
+
end
|
116
|
+
|
117
|
+
private
|
118
|
+
|
132
119
|
include Matchers
|
133
120
|
include Pending
|
134
121
|
|
135
|
-
def before_each_example
|
122
|
+
def before_each_example # :nodoc:
|
136
123
|
setup_mocks_for_rspec
|
137
|
-
|
124
|
+
run_before_each
|
138
125
|
end
|
139
126
|
|
140
|
-
def after_each_example
|
141
|
-
|
127
|
+
def after_each_example # :nodoc:
|
128
|
+
run_after_each
|
142
129
|
verify_mocks_for_rspec
|
143
130
|
ensure
|
144
131
|
teardown_mocks_for_rspec
|
145
132
|
end
|
146
133
|
|
147
|
-
def
|
148
|
-
|
134
|
+
def described_class # :nodoc:
|
135
|
+
self.class.described_class
|
149
136
|
end
|
150
137
|
|
151
|
-
def
|
152
|
-
|
153
|
-
end
|
154
|
-
|
155
|
-
def described_type
|
156
|
-
self.class.described_type
|
138
|
+
def description_args
|
139
|
+
self.class.description_args
|
157
140
|
end
|
158
141
|
|
159
|
-
def
|
160
|
-
|
161
|
-
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
162
|
-
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
163
|
-
tr("-", "_").
|
164
|
-
downcase
|
142
|
+
def example_group_hierarchy
|
143
|
+
self.class.example_group_hierarchy
|
165
144
|
end
|
145
|
+
|
166
146
|
end
|
167
147
|
end
|
168
148
|
end
|
@@ -1,6 +1,28 @@
|
|
1
1
|
module Spec
|
2
2
|
module Example
|
3
|
-
#
|
3
|
+
# When you reopen a module that is included in another module that is included in a class,
|
4
|
+
# the new material you define does not make it to the class. This fixes that.
|
5
|
+
#
|
6
|
+
# == Example
|
7
|
+
#
|
8
|
+
# module M1; end
|
9
|
+
#
|
10
|
+
# module M2
|
11
|
+
# def foo; "FOO"; end
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# class C
|
15
|
+
# include M1
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# module M1
|
19
|
+
# include M2
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
# c = C.new
|
23
|
+
# c.foo
|
24
|
+
# NoMethodError: undefined method `foo' for #<C:0x5e89a4>
|
25
|
+
# from (irb):12
|
4
26
|
module ModuleReopeningFix
|
5
27
|
def child_modules
|
6
28
|
@child_modules ||= []
|
data/lib/spec/example/pending.rb
CHANGED
@@ -2,15 +2,16 @@ module Spec
|
|
2
2
|
module Example
|
3
3
|
module Pending
|
4
4
|
def pending(message = "TODO")
|
5
|
+
pending_caller = caller[0]
|
5
6
|
if block_given?
|
6
7
|
begin
|
7
8
|
yield
|
8
9
|
rescue Exception => e
|
9
|
-
raise Spec::Example::ExamplePendingError.new(message)
|
10
|
+
raise Spec::Example::ExamplePendingError.new(message, pending_caller)
|
10
11
|
end
|
11
12
|
raise Spec::Example::PendingExampleFixedError.new("Expected pending '#{message}' to fail. No Error was raised.")
|
12
13
|
else
|
13
|
-
raise Spec::Example::ExamplePendingError.new(message)
|
14
|
+
raise Spec::Example::ExamplePendingError.new(message, pending_caller)
|
14
15
|
end
|
15
16
|
end
|
16
17
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Spec
|
2
|
+
module Example
|
3
|
+
module PredicateMatchers
|
4
|
+
# :call-seq:
|
5
|
+
# predicate_matchers[matcher_name] = method_on_object
|
6
|
+
# predicate_matchers[matcher_name] = [method1_on_object, method2_on_object]
|
7
|
+
#
|
8
|
+
# Dynamically generates a custom matcher that will match
|
9
|
+
# a predicate on your class. RSpec provides a couple of these
|
10
|
+
# out of the box:
|
11
|
+
#
|
12
|
+
# exist (for state expectations)
|
13
|
+
# File.should exist("path/to/file")
|
14
|
+
#
|
15
|
+
# an_instance_of (for mock argument matchers)
|
16
|
+
# mock.should_receive(:message).with(an_instance_of(String))
|
17
|
+
#
|
18
|
+
# == Examples
|
19
|
+
#
|
20
|
+
# class Fish
|
21
|
+
# def can_swim?
|
22
|
+
# true
|
23
|
+
# end
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# describe Fish do
|
27
|
+
# predicate_matchers[:swim] = :can_swim?
|
28
|
+
# it "should swim" do
|
29
|
+
# Fish.new.should swim
|
30
|
+
# end
|
31
|
+
# end
|
32
|
+
def predicate_matchers
|
33
|
+
@predicate_matchers ||= {}
|
34
|
+
end
|
35
|
+
|
36
|
+
def define_methods_from_predicate_matchers # :nodoc:
|
37
|
+
predicate_matchers.each_pair do |matcher_method, method_on_object|
|
38
|
+
define_method matcher_method do |*args|
|
39
|
+
eval("be_#{method_on_object.to_s.gsub('?','')}(*args)")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
@@ -0,0 +1,91 @@
|
|
1
|
+
module Spec
|
2
|
+
module Example
|
3
|
+
module Subject
|
4
|
+
module ExampleGroupMethods
|
5
|
+
# Defines an explicit subject for an example group which can then be the
|
6
|
+
# implicit receiver (through delegation) of calls to +should+.
|
7
|
+
#
|
8
|
+
# == Examples
|
9
|
+
#
|
10
|
+
# describe CheckingAccount, "with $50" do
|
11
|
+
# subject { CheckingAccount.new(:amount => 50, :currency => :USD) }
|
12
|
+
# it { should have_a_balance_of(50, :USD) }
|
13
|
+
# it { should_not be_overdrawn }
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# See +ExampleMethods#should+ for more information about this approach.
|
17
|
+
def subject(&block)
|
18
|
+
if block.nil?
|
19
|
+
@_subject_block || (described_class ? lambda {described_class.new} : lambda {description_args.first})
|
20
|
+
else
|
21
|
+
@_subject_block = block
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
module ExampleMethods
|
27
|
+
# Returns the subject defined in ExampleGroupMethods#subject. The
|
28
|
+
# subject block is only executed once per example, the result of which
|
29
|
+
# is cached and returned by any subsequent calls to +subject+.
|
30
|
+
#
|
31
|
+
# If a class is passed to +describe+ and no subject is explicitly
|
32
|
+
# declared in the example group, then +subject+ will return a new
|
33
|
+
# instance of that class.
|
34
|
+
#
|
35
|
+
# == Examples
|
36
|
+
#
|
37
|
+
# # explicit subject defined by the subject method
|
38
|
+
# describe Person do
|
39
|
+
# subject { Person.new(:birthdate => 19.years.ago) }
|
40
|
+
# it "should be eligible to vote" do
|
41
|
+
# subject.should be_eligible_to_vote
|
42
|
+
# end
|
43
|
+
# end
|
44
|
+
#
|
45
|
+
# # implicit subject => { Person.new }
|
46
|
+
# describe Person do
|
47
|
+
# it "should be eligible to vote" do
|
48
|
+
# subject.should be_eligible_to_vote
|
49
|
+
# end
|
50
|
+
# end
|
51
|
+
def subject
|
52
|
+
@subject ||= instance_eval(&self.class.subject)
|
53
|
+
end
|
54
|
+
|
55
|
+
# When +should+ is called with no explicit receiver, the call is
|
56
|
+
# delegated to the object returned by +subject+. Combined with
|
57
|
+
# an implicit subject (see +subject+), this supports very concise
|
58
|
+
# expressions.
|
59
|
+
#
|
60
|
+
# == Examples
|
61
|
+
#
|
62
|
+
# describe Person do
|
63
|
+
# it { should be_eligible_to_vote }
|
64
|
+
# end
|
65
|
+
def should(matcher=nil)
|
66
|
+
if matcher
|
67
|
+
subject.should(matcher)
|
68
|
+
else
|
69
|
+
subject.should
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# Just like +should+, +should_not+ delegates to the subject (implicit or
|
74
|
+
# explicit) of the example group.
|
75
|
+
#
|
76
|
+
# == Examples
|
77
|
+
#
|
78
|
+
# describe Person do
|
79
|
+
# it { should_not be_eligible_to_vote }
|
80
|
+
# end
|
81
|
+
def should_not(matcher=nil)
|
82
|
+
if matcher
|
83
|
+
subject.should_not(matcher)
|
84
|
+
else
|
85
|
+
subject.should_not
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
data/lib/spec/expectations.rb
CHANGED
@@ -44,7 +44,7 @@ module Spec
|
|
44
44
|
# <code>expected</code> and <code>target</code>, passes them
|
45
45
|
# to the differ to append a diff message to the failure message.
|
46
46
|
def self.fail_with(message, expected=nil, target=nil) # :nodoc:
|
47
|
-
if Array === message
|
47
|
+
if (Array === message) & (message.length == 3)
|
48
48
|
message, expected, target = message[0], message[1], message[2]
|
49
49
|
end
|
50
50
|
unless (differ.nil? || expected.nil? || target.nil?)
|
@@ -6,12 +6,14 @@ module Spec
|
|
6
6
|
def self.handle_matcher(actual, matcher, &block)
|
7
7
|
::Spec::Matchers.last_should = :should
|
8
8
|
::Spec::Matchers.last_matcher = matcher
|
9
|
-
|
10
9
|
return ::Spec::Matchers::PositiveOperatorMatcher.new(actual) if matcher.nil?
|
11
10
|
|
12
11
|
match = matcher.matches?(actual, &block)
|
13
|
-
|
14
|
-
|
12
|
+
return match if match
|
13
|
+
|
14
|
+
::Spec::Expectations.fail_with matcher.respond_to?(:failure_message_for_should) ?
|
15
|
+
matcher.failure_message_for_should :
|
16
|
+
matcher.failure_message
|
15
17
|
end
|
16
18
|
end
|
17
19
|
|
@@ -22,9 +24,14 @@ module Spec
|
|
22
24
|
|
23
25
|
return ::Spec::Matchers::NegativeOperatorMatcher.new(actual) if matcher.nil?
|
24
26
|
|
25
|
-
match = matcher.
|
26
|
-
|
27
|
-
|
27
|
+
match = matcher.respond_to?(:does_not_match?) ?
|
28
|
+
!matcher.does_not_match?(actual, &block) :
|
29
|
+
matcher.matches?(actual, &block)
|
30
|
+
return match unless match
|
31
|
+
|
32
|
+
::Spec::Expectations.fail_with matcher.respond_to?(:failure_message_for_should_not) ?
|
33
|
+
matcher.failure_message_for_should_not :
|
34
|
+
matcher.negative_failure_message
|
28
35
|
end
|
29
36
|
end
|
30
37
|
end
|