rspec 1.1.11 → 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 +55 -0
- data/Manifest.txt +102 -122
- data/README.txt +30 -12
- data/Rakefile +10 -10
- data/TODO.txt +10 -2
- data/{failing_examples → examples/failing}/README.txt +0 -0
- data/{failing_examples → examples/failing}/diffing_spec.rb +0 -0
- data/{failing_examples → examples/failing}/failing_autogenerated_docstrings_example.rb +0 -0
- data/{failing_examples/failure_in_teardown.rb → examples/failing/failure_in_after.rb} +1 -1
- data/{failing_examples/failure_in_setup.rb → examples/failing/failure_in_before.rb} +1 -1
- data/{failing_examples → examples/failing}/mocking_example.rb +0 -0
- data/{failing_examples → examples/failing}/mocking_with_flexmock.rb +0 -0
- data/{failing_examples → examples/failing}/mocking_with_mocha.rb +0 -0
- data/{failing_examples → examples/failing}/mocking_with_rr.rb +0 -0
- data/{failing_examples → examples/failing}/partial_mock_example.rb +0 -0
- data/{failing_examples → examples/failing}/predicate_example.rb +5 -0
- data/{failing_examples → examples/failing}/raising_example.rb +0 -0
- data/{failing_examples → examples/failing}/spec_helper.rb +1 -1
- data/{failing_examples → examples/failing}/syntax_error_example.rb +0 -0
- data/{failing_examples → examples/failing}/team_spec.rb +0 -0
- data/{failing_examples → examples/failing}/timeout_behaviour.rb +0 -0
- data/examples/{pure → passing}/autogenerated_docstrings_example.rb +6 -0
- data/examples/{pure → passing}/before_and_after_example.rb +0 -0
- data/examples/{pure → passing}/behave_as_example.rb +0 -0
- data/examples/{pure → passing}/custom_expectation_matchers.rb +0 -0
- data/examples/{pure → passing}/custom_formatter.rb +1 -1
- data/examples/{pure → passing}/dynamic_spec.rb +2 -2
- data/examples/{pure → passing}/file_accessor.rb +0 -0
- data/examples/{pure → passing}/file_accessor_spec.rb +0 -0
- data/examples/{pure → passing}/greeter_spec.rb +0 -0
- data/examples/{pure → passing}/helper_method_example.rb +0 -0
- data/examples/{pure → passing}/io_processor.rb +0 -0
- data/examples/{pure → passing}/io_processor_spec.rb +0 -0
- data/examples/{pure → passing}/legacy_spec.rb +0 -0
- data/examples/{pure → passing}/mocking_example.rb +0 -0
- data/examples/{pure/multi_threaded_behaviour_runner.rb → passing/multi_threaded_example_group_runner.rb} +1 -3
- data/examples/{pure → passing}/nested_classes_example.rb +0 -0
- data/examples/{pure → passing}/partial_mock_example.rb +0 -0
- data/examples/{pure → passing}/pending_example.rb +0 -0
- data/examples/{pure → passing}/predicate_example.rb +0 -0
- data/examples/{pure → passing}/priority.txt +0 -0
- data/examples/{pure → passing}/shared_example_group_example.rb +0 -0
- data/examples/{pure → passing}/shared_stack_examples.rb +1 -3
- data/examples/passing/simple_matcher_example.rb +31 -0
- data/examples/{pure → passing}/spec_helper.rb +0 -0
- data/examples/{pure → passing}/stack.rb +0 -0
- data/examples/{pure → passing}/stack_spec.rb +3 -2
- data/examples/{pure → passing}/stack_spec_with_nested_example_groups.rb +0 -0
- data/examples/{pure → passing}/stubbing_example.rb +0 -0
- data/examples/{pure → passing}/yielding_example.rb +0 -0
- data/examples/ruby1.9.compatibility/access_to_constants_spec.rb +86 -0
- data/features/before_and_after_blocks/before_and_after_blocks.feature +168 -0
- data/{stories/example_groups/autogenerated_docstrings → features/example_groups/autogenerated_docstrings.feature} +5 -5
- data/{stories/example_groups/example_group_with_should_methods → features/example_groups/example_group_with_should_methods.feature} +3 -3
- data/{stories/example_groups/nested_groups → features/example_groups/nested_groups.feature} +4 -4
- data/{stories/example_groups/output → features/example_groups/output.feature} +3 -8
- data/{stories/interop/examples_and_tests_together → features/interop/examples_and_tests_together.feature} +5 -4
- data/features/interop/test_but_not_test_unit.feature +14 -0
- data/{stories/interop/test_case_with_should_methods → features/interop/test_case_with_should_methods.feature} +2 -2
- data/{stories/mock_framework_integration/use_flexmock.story → features/mock_framework_integration/use_flexmock.feature} +1 -1
- data/features/step_definitions/running_rspec.rb +54 -0
- data/features/support/env.rb +26 -0
- data/{stories/resources → features/support}/helpers/cmdline.rb +0 -0
- data/{stories/resources → features/support}/helpers/story_helper.rb +1 -1
- data/{stories/resources → features/support}/matchers/smart_match.rb +0 -0
- data/{plugins → lib/adapters}/mock_frameworks/flexmock.rb +1 -1
- data/{plugins → lib/adapters}/mock_frameworks/mocha.rb +1 -1
- data/{plugins → lib/adapters}/mock_frameworks/rr.rb +1 -1
- data/{plugins → lib/adapters}/mock_frameworks/rspec.rb +2 -2
- data/lib/autotest/rspec.rb +4 -3
- data/lib/spec.rb +2 -27
- data/lib/spec/dsl.rb +1 -0
- data/lib/spec/{extensions → dsl}/main.rb +10 -10
- data/lib/spec/example.rb +175 -1
- data/lib/spec/example/before_and_after_hooks.rb +30 -24
- data/lib/spec/example/example_group.rb +1 -0
- data/lib/spec/example/example_group_factory.rb +26 -9
- data/lib/spec/example/example_group_methods.rb +138 -113
- data/lib/spec/example/example_methods.rb +88 -25
- data/lib/spec/example/shared_example_group.rb +28 -21
- data/lib/spec/expectations.rb +22 -18
- data/lib/spec/expectations/handler.rb +16 -36
- data/lib/spec/interop/test/unit/testcase.rb +19 -17
- data/lib/spec/interop/test/unit/testresult.rb +1 -1
- data/lib/spec/interop/test/unit/testsuite_adapter.rb +1 -1
- data/lib/spec/matchers.rb +7 -28
- data/lib/spec/matchers/be.rb +103 -116
- data/lib/spec/matchers/be_close.rb +6 -22
- data/lib/spec/matchers/eql.rb +7 -25
- data/lib/spec/matchers/equal.rb +7 -25
- data/lib/spec/matchers/errors.rb +5 -0
- data/lib/spec/matchers/exist.rb +8 -14
- data/lib/spec/matchers/generated_descriptions.rb +48 -0
- data/lib/spec/matchers/has.rb +12 -28
- data/lib/spec/matchers/include.rb +12 -9
- data/lib/spec/matchers/match.rb +8 -27
- data/lib/spec/matchers/match_array.rb +79 -0
- data/lib/spec/matchers/method_missing.rb +9 -0
- data/lib/spec/matchers/operator_matcher.rb +39 -48
- data/lib/spec/matchers/raise_error.rb +4 -8
- data/lib/spec/matchers/respond_to.rb +33 -8
- data/lib/spec/matchers/throw_symbol.rb +49 -17
- data/lib/spec/matchers/wrap_expectation.rb +55 -0
- data/lib/spec/mocks/argument_constraints.rb +77 -5
- data/lib/spec/mocks/message_expectation.rb +7 -7
- data/lib/spec/mocks/proxy.rb +14 -12
- data/lib/spec/rake/spectask.rb +4 -6
- data/lib/spec/ruby.rb +9 -0
- data/lib/spec/runner.rb +37 -162
- data/lib/spec/runner/backtrace_tweaker.rb +5 -3
- data/lib/spec/runner/class_and_arguments_parser.rb +7 -9
- data/lib/spec/runner/command_line.rb +6 -8
- data/lib/spec/{example → runner}/configuration.rb +46 -47
- data/lib/spec/runner/example_group_runner.rb +15 -4
- data/lib/spec/runner/formatter/base_text_formatter.rb +4 -3
- data/lib/spec/runner/formatter/html_formatter.rb +14 -11
- data/lib/spec/runner/formatter/nested_text_formatter.rb +2 -2
- data/lib/spec/runner/heckle_runner.rb +58 -56
- data/lib/spec/runner/option_parser.rb +8 -4
- data/lib/spec/runner/options.rb +29 -14
- data/lib/spec/runner/reporter.rb +1 -1
- data/lib/spec/runner/spec_parser.rb +11 -9
- data/lib/spec/story/runner.rb +40 -42
- data/lib/spec/story/runner/story_runner.rb +10 -6
- data/lib/spec/story/world.rb +66 -70
- data/lib/spec/version.rb +4 -2
- data/{rake_tasks → resources/rake}/examples.rake +0 -0
- data/{rake_tasks → resources/rake}/examples_with_rcov.rake +0 -0
- data/{rake_tasks → resources/rake}/failing_examples_with_html.rake +0 -0
- data/{rake_tasks → resources/rake}/verify_rcov.rake +0 -0
- data/{stories/resources → resources}/spec/example_group_with_should_methods.rb +1 -1
- data/{stories/resources → resources}/spec/simple_spec.rb +1 -1
- data/resources/spec/spec_with_flexmock.rb +19 -0
- data/{stories/resources → resources}/test/spec_and_test_together.rb +1 -1
- data/resources/test/spec_including_test_but_not_unit.rb +11 -0
- data/{stories/resources → resources}/test/test_case_with_should_methods.rb +2 -2
- data/rspec.gemspec +16 -6
- data/spec/autotest/autotest_helper.rb +2 -2
- data/spec/autotest/discover_spec.rb +4 -15
- data/spec/autotest/failed_results_re_spec.rb +24 -0
- data/spec/autotest/rspec_spec.rb +2 -38
- data/spec/spec/dsl/main_spec.rb +88 -0
- data/spec/spec/example/example_group_class_definition_spec.rb +6 -2
- data/spec/spec/example/example_group_factory_spec.rb +50 -10
- data/spec/spec/example/example_group_methods_spec.rb +210 -160
- data/spec/spec/example/example_group_spec.rb +44 -52
- data/spec/spec/example/example_matcher_spec.rb +6 -23
- data/spec/spec/example/example_methods_spec.rb +176 -54
- data/spec/spec/example/helper_method_spec.rb +24 -0
- data/spec/spec/example/pending_module_spec.rb +2 -8
- data/spec/spec/example/shared_example_group_spec.rb +56 -80
- data/spec/spec/expectations/extensions/object_spec.rb +0 -50
- data/spec/spec/expectations/wrap_expectation_spec.rb +30 -0
- data/spec/spec/interop/test/unit/spec_spec.rb +1 -5
- data/spec/spec/interop/test/unit/test_unit_spec_helper.rb +4 -0
- data/spec/spec/matchers/be_close_spec.rb +12 -10
- data/spec/spec/matchers/be_spec.rb +62 -7
- data/spec/spec/matchers/description_generation_spec.rb +19 -0
- data/spec/spec/matchers/eql_spec.rb +7 -6
- data/spec/spec/matchers/equal_spec.rb +7 -6
- data/spec/spec/matchers/handler_spec.rb +4 -43
- data/spec/spec/matchers/has_spec.rb +1 -1
- data/spec/spec/matchers/have_spec.rb +23 -18
- data/spec/spec/matchers/include_spec.rb +24 -0
- data/spec/spec/matchers/match_array_spec.rb +83 -0
- data/spec/spec/matchers/matcher_methods_spec.rb +1 -13
- data/spec/spec/matchers/raise_error_spec.rb +18 -0
- data/spec/spec/matchers/respond_to_spec.rb +71 -9
- data/spec/spec/matchers/throw_symbol_spec.rb +85 -43
- data/spec/spec/mocks/bug_report_11545_spec.rb +4 -5
- data/spec/spec/mocks/bug_report_496.rb +11 -9
- data/spec/spec/mocks/bug_report_600_spec.rb +22 -0
- data/spec/spec/mocks/hash_including_matcher_spec.rb +39 -2
- data/spec/spec/mocks/hash_not_including_matcher_spec.rb +67 -0
- data/spec/spec/mocks/mock_spec.rb +5 -6
- data/spec/spec/mocks/nil_expectation_warning_spec.rb +2 -2
- data/spec/spec/mocks/passing_mock_argument_constraints_spec.rb +18 -3
- data/spec/spec/mocks/stub_spec.rb +6 -0
- data/spec/spec/mocks/stubbed_message_expectations_spec.rb +14 -0
- data/spec/spec/runner/command_line_spec.rb +4 -4
- data/spec/spec/runner/configuration_spec.rb +301 -0
- data/spec/spec/runner/drb_command_line_spec.rb +4 -4
- data/spec/spec/runner/example_group_runner_spec.rb +33 -0
- data/spec/spec/runner/formatter/base_formatter_spec.rb +13 -102
- data/spec/spec/runner/formatter/base_text_formatter_spec.rb +23 -0
- data/spec/spec/runner/formatter/failing_example_groups_formatter_spec.rb +5 -5
- data/spec/spec/runner/formatter/failing_examples_formatter_spec.rb +3 -3
- data/spec/spec/runner/formatter/html_formatted-1.8.4.html +6 -6
- data/spec/spec/runner/formatter/html_formatted-1.8.5-jruby.html +9 -9
- data/spec/spec/runner/formatter/html_formatted-1.8.5.html +6 -6
- data/spec/spec/runner/formatter/html_formatted-1.8.6-jruby.html +10 -10
- data/spec/spec/runner/formatter/html_formatted-1.8.6.html +39 -30
- data/spec/spec/runner/formatter/html_formatted-1.8.7.html +379 -0
- data/spec/spec/runner/formatter/html_formatted-1.9.1.html +379 -0
- data/spec/spec/runner/formatter/html_formatter_spec.rb +14 -13
- data/spec/spec/runner/formatter/nested_text_formatter_spec.rb +5 -5
- data/spec/spec/runner/formatter/progress_bar_formatter_spec.rb +7 -17
- data/spec/spec/runner/formatter/spec_mate_formatter_spec.rb +18 -17
- data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +5 -5
- data/spec/spec/runner/formatter/text_mate_formatted-1.8.4.html +6 -6
- data/spec/spec/runner/formatter/text_mate_formatted-1.8.6.html +33 -30
- data/spec/spec/runner/formatter/text_mate_formatted-1.8.7.html +373 -0
- data/spec/spec/runner/formatter/text_mate_formatted-1.9.1.html +373 -0
- data/spec/spec/runner/heckler_spec.rb +16 -9
- data/spec/spec/runner/option_parser_spec.rb +3 -18
- data/spec/spec/runner/options_spec.rb +27 -8
- data/spec/spec/runner/reporter_spec.rb +5 -5
- data/spec/spec/runner/resources/custom_example_group_runner.rb +14 -0
- data/spec/spec/runner/resources/utf8_encoded.rb +7 -0
- data/spec/spec/runner/spec_parser_spec.rb +85 -79
- data/spec/spec/spec_spec.rb +21 -0
- data/spec/spec_helper.rb +9 -1
- data/story_server/prototype/javascripts/prototype.js +1 -1
- metadata +119 -131
- data/examples/stories/adder.rb +0 -13
- data/examples/stories/addition +0 -34
- data/examples/stories/addition.rb +0 -9
- data/examples/stories/calculator.rb +0 -65
- data/examples/stories/game-of-life/.loadpath +0 -5
- data/examples/stories/game-of-life/README.txt +0 -21
- data/examples/stories/game-of-life/behaviour/everything.rb +0 -6
- data/examples/stories/game-of-life/behaviour/examples/examples.rb +0 -3
- data/examples/stories/game-of-life/behaviour/examples/game_behaviour.rb +0 -35
- data/examples/stories/game-of-life/behaviour/examples/grid_behaviour.rb +0 -66
- data/examples/stories/game-of-life/behaviour/stories/CellsWithLessThanTwoNeighboursDie.story +0 -21
- data/examples/stories/game-of-life/behaviour/stories/CellsWithMoreThanThreeNeighboursDie.story +0 -21
- data/examples/stories/game-of-life/behaviour/stories/EmptySpacesWithThreeNeighboursCreateACell.story +0 -42
- data/examples/stories/game-of-life/behaviour/stories/ICanCreateACell.story +0 -42
- data/examples/stories/game-of-life/behaviour/stories/ICanKillACell.story +0 -17
- data/examples/stories/game-of-life/behaviour/stories/TheGridWraps.story +0 -53
- data/examples/stories/game-of-life/behaviour/stories/create_a_cell.rb +0 -52
- data/examples/stories/game-of-life/behaviour/stories/helper.rb +0 -6
- data/examples/stories/game-of-life/behaviour/stories/kill_a_cell.rb +0 -26
- data/examples/stories/game-of-life/behaviour/stories/steps.rb +0 -5
- data/examples/stories/game-of-life/behaviour/stories/stories.rb +0 -3
- data/examples/stories/game-of-life/behaviour/stories/stories.txt +0 -22
- data/examples/stories/game-of-life/life.rb +0 -3
- data/examples/stories/game-of-life/life/game.rb +0 -23
- data/examples/stories/game-of-life/life/grid.rb +0 -43
- data/examples/stories/helper.rb +0 -9
- data/examples/stories/steps/addition_steps.rb +0 -18
- data/lib/spec/adapters.rb +0 -1
- data/lib/spec/adapters/ruby_engine.rb +0 -26
- data/lib/spec/adapters/ruby_engine/mri.rb +0 -8
- data/lib/spec/adapters/ruby_engine/rubinius.rb +0 -8
- data/lib/spec/extensions.rb +0 -4
- data/lib/spec/extensions/class.rb +0 -24
- data/lib/spec/extensions/metaclass.rb +0 -7
- data/lib/spec/extensions/object.rb +0 -6
- data/spec/spec/adapters/ruby_engine_spec.rb +0 -16
- data/spec/spec/example/configuration_spec.rb +0 -296
- data/spec/spec/example/example_runner_spec.rb +0 -194
- data/spec/spec/extensions/main_spec.rb +0 -71
- data/stories/all.rb +0 -5
- data/stories/configuration/before_blocks.story +0 -21
- data/stories/configuration/stories.rb +0 -7
- data/stories/example_groups/stories.rb +0 -7
- data/stories/helper.rb +0 -6
- data/stories/interop/stories.rb +0 -7
- data/stories/mock_framework_integration/stories.rb +0 -7
- data/stories/pending_stories/README +0 -3
- data/stories/resources/spec/before_blocks_example.rb +0 -32
- data/stories/resources/spec/spec_with_flexmock.rb +0 -18
- data/stories/resources/steps/running_rspec.rb +0 -50
- data/stories/resources/stories/failing_story.rb +0 -15
- data/stories/stories/multiline_steps.story +0 -23
- data/stories/stories/steps/multiline_steps.rb +0 -13
- data/stories/stories/stories.rb +0 -6
@@ -4,6 +4,43 @@ module Spec
|
|
4
4
|
|
5
5
|
extend ModuleReopeningFix
|
6
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
|
31
|
+
|
32
|
+
def violated(message="")
|
33
|
+
raise Spec::Expectations::ExpectationNotMetError.new(message)
|
34
|
+
end
|
35
|
+
|
36
|
+
def description
|
37
|
+
@_defined_description || ::Spec::Matchers.generated_description || "NO NAME"
|
38
|
+
end
|
39
|
+
|
40
|
+
def options
|
41
|
+
@_options
|
42
|
+
end
|
43
|
+
|
7
44
|
def execute(options, instance_variables)
|
8
45
|
options.reporter.example_started(self)
|
9
46
|
set_instance_variables_from_hash(instance_variables)
|
@@ -27,28 +64,24 @@ module Spec
|
|
27
64
|
success = execution_error.nil? || ExamplePendingError === execution_error
|
28
65
|
end
|
29
66
|
|
30
|
-
def instance_variable_hash
|
67
|
+
def instance_variable_hash # :nodoc:
|
31
68
|
instance_variables.inject({}) do |variable_hash, variable_name|
|
32
69
|
variable_hash[variable_name] = instance_variable_get(variable_name)
|
33
70
|
variable_hash
|
34
71
|
end
|
35
72
|
end
|
36
73
|
|
37
|
-
def
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
def eval_each_fail_fast(procs) #:nodoc:
|
42
|
-
procs.each do |proc|
|
43
|
-
instance_eval(&proc)
|
74
|
+
def eval_each_fail_fast(examples) # :nodoc:
|
75
|
+
examples.each do |example|
|
76
|
+
instance_eval(&example)
|
44
77
|
end
|
45
78
|
end
|
46
79
|
|
47
|
-
def eval_each_fail_slow(
|
80
|
+
def eval_each_fail_slow(examples) # :nodoc:
|
48
81
|
first_exception = nil
|
49
|
-
|
82
|
+
examples.each do |example|
|
50
83
|
begin
|
51
|
-
instance_eval(&
|
84
|
+
instance_eval(&example)
|
52
85
|
rescue Exception => e
|
53
86
|
first_exception ||= e
|
54
87
|
end
|
@@ -56,19 +89,19 @@ module Spec
|
|
56
89
|
raise first_exception if first_exception
|
57
90
|
end
|
58
91
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
def
|
92
|
+
# Concats the class description with the example description.
|
93
|
+
#
|
94
|
+
# describe Account do
|
95
|
+
# it "should start with a balance of 0" do
|
96
|
+
# ...
|
97
|
+
#
|
98
|
+
# full_description
|
99
|
+
# => "Account should start with a balance of 0"
|
100
|
+
def full_description
|
68
101
|
"#{self.class.description} #{self.description}"
|
69
102
|
end
|
70
103
|
|
71
|
-
def set_instance_variables_from_hash(ivars)
|
104
|
+
def set_instance_variables_from_hash(ivars) # :nodoc:
|
72
105
|
ivars.each do |variable_name, value|
|
73
106
|
# Ruby 1.9 requires variable.to_s on the next line
|
74
107
|
unless ['@_implementation', '@_defined_description', '@_matcher_description', '@method_name'].include?(variable_name.to_s)
|
@@ -77,15 +110,25 @@ module Spec
|
|
77
110
|
end
|
78
111
|
end
|
79
112
|
|
80
|
-
def eval_block
|
113
|
+
def eval_block # :nodoc:
|
81
114
|
instance_eval(&@_implementation)
|
82
115
|
end
|
83
116
|
|
84
|
-
|
85
|
-
|
117
|
+
# Provides the backtrace up to where this example was declared.
|
118
|
+
def backtrace
|
119
|
+
@_backtrace
|
86
120
|
end
|
87
121
|
|
88
|
-
|
122
|
+
# Deprecated - use +backtrace()+
|
123
|
+
def implementation_backtrace
|
124
|
+
Kernel.warn <<-WARNING
|
125
|
+
ExampleMethods#implementation_backtrace is deprecated and will be removed
|
126
|
+
from a future version. Please use ExampleMethods#backtrace instead.
|
127
|
+
WARNING
|
128
|
+
backtrace
|
129
|
+
end
|
130
|
+
|
131
|
+
private
|
89
132
|
include Matchers
|
90
133
|
include Pending
|
91
134
|
|
@@ -100,6 +143,26 @@ module Spec
|
|
100
143
|
ensure
|
101
144
|
teardown_mocks_for_rspec
|
102
145
|
end
|
146
|
+
|
147
|
+
def subject_variable_name
|
148
|
+
'@' << (described_class ? underscore(described_class.name) : '__this_does_not_exist')
|
149
|
+
end
|
150
|
+
|
151
|
+
def described_class
|
152
|
+
Class === described_type ? described_type : nil
|
153
|
+
end
|
154
|
+
|
155
|
+
def described_type
|
156
|
+
self.class.described_type
|
157
|
+
end
|
158
|
+
|
159
|
+
def underscore(camel_cased_word)
|
160
|
+
camel_cased_word.to_s.gsub(/::/, '_').
|
161
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
162
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
163
|
+
tr("-", "_").
|
164
|
+
downcase
|
165
|
+
end
|
103
166
|
end
|
104
167
|
end
|
105
168
|
end
|
@@ -2,31 +2,43 @@ module Spec
|
|
2
2
|
module Example
|
3
3
|
class SharedExampleGroup < Module
|
4
4
|
module ClassMethods
|
5
|
-
def
|
6
|
-
|
7
|
-
shared_example_groups << new_example_group
|
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}
|
8
13
|
end
|
9
14
|
|
10
|
-
def
|
11
|
-
shared_example_groups.
|
12
|
-
|
13
|
-
|
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
|
14
25
|
end
|
15
26
|
|
27
|
+
private
|
28
|
+
|
16
29
|
def shared_example_groups
|
17
30
|
@shared_example_groups ||= []
|
18
31
|
end
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
return
|
24
|
-
return if new_example_group
|
25
|
-
return if spec_path(new_example_group) == spec_path(existing_example_group)
|
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)
|
26
38
|
raise ArgumentError.new("Shared Example '#{existing_example_group.description}' already exists")
|
27
39
|
end
|
28
40
|
|
29
|
-
def
|
41
|
+
def expanded_path(example_group)
|
30
42
|
File.expand_path(example_group.spec_path)
|
31
43
|
end
|
32
44
|
end
|
@@ -35,18 +47,13 @@ module Spec
|
|
35
47
|
include ExampleGroupMethods
|
36
48
|
|
37
49
|
def initialize(*args, &example_group_block)
|
38
|
-
|
50
|
+
set_description(*args)
|
39
51
|
@example_group_block = example_group_block
|
40
|
-
self.class.add_shared_example_group(self)
|
41
52
|
end
|
42
53
|
|
43
54
|
def included(mod) # :nodoc:
|
44
55
|
mod.module_eval(&@example_group_block)
|
45
56
|
end
|
46
|
-
|
47
|
-
def each_ancestor_example_group_class(superclass_last=false)
|
48
|
-
yield self
|
49
|
-
end
|
50
57
|
end
|
51
58
|
end
|
52
59
|
end
|
data/lib/spec/expectations.rb
CHANGED
@@ -30,27 +30,31 @@ module Spec
|
|
30
30
|
# RSpec ships with a standard set of useful matchers, and writing your own
|
31
31
|
# matchers is quite simple. See Spec::Matchers for details.
|
32
32
|
module Expectations
|
33
|
-
|
34
|
-
|
33
|
+
def self.differ
|
34
|
+
@differ
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.differ=(differ)
|
38
|
+
@differ = differ
|
39
|
+
end
|
35
40
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
end
|
41
|
+
# raises a Spec::Expectations::ExpectationNotMetError with message
|
42
|
+
#
|
43
|
+
# When a differ has been assigned and fail_with is passed
|
44
|
+
# <code>expected</code> and <code>target</code>, passes them
|
45
|
+
# to the differ to append a diff message to the failure message.
|
46
|
+
def self.fail_with(message, expected=nil, target=nil) # :nodoc:
|
47
|
+
if Array === message && message.length == 3
|
48
|
+
message, expected, target = message[0], message[1], message[2]
|
49
|
+
end
|
50
|
+
unless (differ.nil? || expected.nil? || target.nil?)
|
51
|
+
if expected.is_a?(String)
|
52
|
+
message << "\nDiff:" << self.differ.diff_as_string(target.to_s, expected)
|
53
|
+
elsif !target.is_a?(Proc)
|
54
|
+
message << "\nDiff:" << self.differ.diff_as_object(target, expected)
|
51
55
|
end
|
52
|
-
Kernel::raise(Spec::Expectations::ExpectationNotMetError.new(message))
|
53
56
|
end
|
57
|
+
Kernel::raise(Spec::Expectations::ExpectationNotMetError.new(message))
|
54
58
|
end
|
55
59
|
end
|
56
60
|
end
|
@@ -3,50 +3,30 @@ module Spec
|
|
3
3
|
class InvalidMatcherError < ArgumentError; end
|
4
4
|
|
5
5
|
class ExpectationMatcherHandler
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
return Spec::Matchers::PositiveOperatorMatcher.new(actual) if matcher.nil?
|
6
|
+
def self.handle_matcher(actual, matcher, &block)
|
7
|
+
::Spec::Matchers.last_should = :should
|
8
|
+
::Spec::Matchers.last_matcher = matcher
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
::Spec::Matchers.last_matcher = matcher
|
17
|
-
Spec::Expectations.fail_with(matcher.failure_message) unless match
|
18
|
-
match
|
19
|
-
end
|
10
|
+
return ::Spec::Matchers::PositiveOperatorMatcher.new(actual) if matcher.nil?
|
11
|
+
|
12
|
+
match = matcher.matches?(actual, &block)
|
13
|
+
::Spec::Expectations.fail_with(matcher.failure_message) unless match
|
14
|
+
match
|
20
15
|
end
|
21
16
|
end
|
22
17
|
|
23
18
|
class NegativeExpectationMatcherHandler
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
return Spec::Matchers::NegativeOperatorMatcher.new(actual) if matcher.nil?
|
28
|
-
|
29
|
-
unless matcher.respond_to?(:matches?)
|
30
|
-
raise InvalidMatcherError, "Expected a matcher, got #{matcher.inspect}."
|
31
|
-
end
|
19
|
+
def self.handle_matcher(actual, matcher, &block)
|
20
|
+
::Spec::Matchers.last_should = :should_not
|
21
|
+
::Spec::Matchers.last_matcher = matcher
|
32
22
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
about matchers.
|
39
|
-
EOF
|
40
|
-
)
|
41
|
-
end
|
42
|
-
match = matcher.matches?(actual, &block)
|
43
|
-
::Spec::Matchers.last_matcher = matcher
|
44
|
-
Spec::Expectations.fail_with(matcher.negative_failure_message) if match
|
45
|
-
match
|
46
|
-
end
|
23
|
+
return ::Spec::Matchers::NegativeOperatorMatcher.new(actual) if matcher.nil?
|
24
|
+
|
25
|
+
match = matcher.matches?(actual, &block)
|
26
|
+
::Spec::Expectations.fail_with(matcher.negative_failure_message) if match
|
27
|
+
match
|
47
28
|
end
|
48
29
|
end
|
49
|
-
|
50
30
|
end
|
51
31
|
end
|
52
32
|
|
@@ -23,26 +23,24 @@ module Test
|
|
23
23
|
extend Spec::Example::ExampleGroupMethods
|
24
24
|
include Spec::Example::ExampleMethods
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
class << self
|
30
|
-
def suite
|
31
|
-
Test::Unit::TestSuiteAdapter.new(self)
|
32
|
-
end
|
26
|
+
def self.suite
|
27
|
+
Test::Unit::TestSuiteAdapter.new(self)
|
28
|
+
end
|
33
29
|
|
34
|
-
|
35
|
-
|
36
|
-
|
30
|
+
def self.example_method?(method_name)
|
31
|
+
should_method?(method_name) || test_method?(method_name)
|
32
|
+
end
|
37
33
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
end
|
34
|
+
def self.test_method?(method_name)
|
35
|
+
method_name =~ /^test[_A-Z]./ && (
|
36
|
+
instance_method(method_name).arity == 0 ||
|
37
|
+
instance_method(method_name).arity == -1
|
38
|
+
)
|
44
39
|
end
|
45
40
|
|
41
|
+
before(:each) {setup}
|
42
|
+
after(:each) {teardown}
|
43
|
+
|
46
44
|
def initialize(defined_description, options={}, &implementation)
|
47
45
|
@_defined_description = defined_description
|
48
46
|
|
@@ -51,9 +49,13 @@ module Test
|
|
51
49
|
@_implementation = implementation || pending_implementation
|
52
50
|
|
53
51
|
@_result = ::Test::Unit::TestResult.new
|
54
|
-
# @method_name is important to set here because it
|
52
|
+
# @method_name is important to set here because it complies with Test::Unit's interface.
|
55
53
|
# Some Test::Unit extensions depend on @method_name being present.
|
56
54
|
@method_name = @_defined_description
|
55
|
+
|
56
|
+
# TODO - this is necessary to run single examples in rspec-rails, but I haven't
|
57
|
+
# found a good way to write a failing example just within rspec core
|
58
|
+
@_backtrace = caller
|
57
59
|
end
|
58
60
|
|
59
61
|
def run(ignore_this_argument=nil)
|
data/lib/spec/matchers.rb
CHANGED
@@ -1,7 +1,12 @@
|
|
1
|
+
require 'spec/matchers/operator_matcher'
|
2
|
+
require 'spec/matchers/generated_descriptions'
|
3
|
+
require 'spec/matchers/errors'
|
4
|
+
require 'spec/matchers/method_missing'
|
1
5
|
require 'spec/matchers/simple_matcher'
|
2
6
|
require 'spec/matchers/be'
|
3
7
|
require 'spec/matchers/be_close'
|
4
8
|
require 'spec/matchers/change'
|
9
|
+
require 'spec/matchers/match_array'
|
5
10
|
require 'spec/matchers/eql'
|
6
11
|
require 'spec/matchers/equal'
|
7
12
|
require 'spec/matchers/exist'
|
@@ -13,7 +18,7 @@ require 'spec/matchers/raise_error'
|
|
13
18
|
require 'spec/matchers/respond_to'
|
14
19
|
require 'spec/matchers/satisfy'
|
15
20
|
require 'spec/matchers/throw_symbol'
|
16
|
-
require 'spec/matchers/
|
21
|
+
require 'spec/matchers/wrap_expectation'
|
17
22
|
|
18
23
|
module Spec
|
19
24
|
|
@@ -132,31 +137,5 @@ module Spec
|
|
132
137
|
# config.include(CustomGameMatchers)
|
133
138
|
# end
|
134
139
|
#
|
135
|
-
module Matchers
|
136
|
-
module ModuleMethods
|
137
|
-
attr_accessor :last_matcher, :last_should
|
138
|
-
|
139
|
-
def clear_generated_description
|
140
|
-
self.last_matcher = nil
|
141
|
-
self.last_should = nil
|
142
|
-
end
|
143
|
-
|
144
|
-
def generated_description
|
145
|
-
last_should.nil? ? nil :
|
146
|
-
"#{last_should} #{last_matcher.respond_to?(:description) ? last_matcher.description : 'NO NAME'}"
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
extend ModuleMethods
|
151
|
-
|
152
|
-
def method_missing(sym, *args, &block) # :nodoc:
|
153
|
-
return Matchers::Be.new(sym, *args) if sym.starts_with?("be_")
|
154
|
-
return Matchers::Has.new(sym, *args) if sym.starts_with?("have_")
|
155
|
-
super
|
156
|
-
end
|
157
|
-
|
158
|
-
class MatcherError < StandardError
|
159
|
-
end
|
160
|
-
|
161
|
-
end
|
140
|
+
module Matchers; end
|
162
141
|
end
|