rspec 1.1.12 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec/ruby'
|
2
|
+
|
3
|
+
if ::Spec::Ruby.version < "1.8.7"
|
4
|
+
# based on Bounded Spec InstanceExec (Mauricio Fernandez)
|
5
|
+
# http://eigenclass.org/hiki/bounded+space+instance_exec
|
6
|
+
class Object
|
7
|
+
module InstanceExecHelper; end
|
8
|
+
include InstanceExecHelper
|
9
|
+
def instance_exec(*args, &block)
|
10
|
+
begin
|
11
|
+
orig_critical, Thread.critical = Thread.critical, true
|
12
|
+
n = 0
|
13
|
+
n += 1 while respond_to?(method_name="__instance_exec#{n}")
|
14
|
+
InstanceExecHelper.module_eval{ define_method(method_name, &block) }
|
15
|
+
ensure
|
16
|
+
Thread.critical = orig_critical
|
17
|
+
end
|
18
|
+
begin
|
19
|
+
return send(method_name, *args)
|
20
|
+
ensure
|
21
|
+
InstanceExecHelper.module_eval{ remove_method(method_name) } rescue nil
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -38,11 +38,11 @@ or this:
|
|
38
38
|
|
39
39
|
it { should matcher }
|
40
40
|
|
41
|
-
the runner expects the matcher to have a #
|
41
|
+
the runner expects the matcher to have a #description method. You should either
|
42
42
|
add a String to the example this matcher is being used in, or give it a
|
43
43
|
description method. Then you won't have to suffer this lengthy warning again.
|
44
44
|
MESSAGE
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
48
|
-
|
48
|
+
|
data/lib/spec/matchers/has.rb
CHANGED
@@ -1,18 +1,35 @@
|
|
1
1
|
module Spec
|
2
2
|
module Matchers
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
actual.__send__(predicate(sym), *args)
|
3
|
+
|
4
|
+
class Has
|
5
|
+
|
6
|
+
def initialize(expected, *args)
|
7
|
+
@expected, @args = expected, args
|
9
8
|
end
|
10
|
-
|
9
|
+
|
10
|
+
def matches?(actual)
|
11
|
+
actual.__send__(predicate(@expected), *@args)
|
12
|
+
end
|
13
|
+
|
14
|
+
def failure_message_for_should
|
15
|
+
"expected ##{predicate(@expected)}(#{@args[0].inspect}) to return true, got false"
|
16
|
+
end
|
17
|
+
|
18
|
+
def failure_message_for_should_not
|
19
|
+
"expected ##{predicate(@expected)}(#{@args[0].inspect}) to return false, got true"
|
20
|
+
end
|
21
|
+
|
22
|
+
def description
|
23
|
+
"have key #{@args[0].inspect}"
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
11
27
|
|
12
|
-
|
13
|
-
|
14
|
-
|
28
|
+
def predicate(sym)
|
29
|
+
"#{sym.to_s.sub("have_","has_")}?".to_sym
|
30
|
+
end
|
31
|
+
|
15
32
|
end
|
16
|
-
|
33
|
+
|
17
34
|
end
|
18
35
|
end
|
data/lib/spec/matchers/have.rb
CHANGED
@@ -36,11 +36,11 @@ module Spec
|
|
36
36
|
"expected #{@collection_name} to be a collection but it does not respond to #length or #size"
|
37
37
|
end
|
38
38
|
|
39
|
-
def
|
39
|
+
def failure_message_for_should
|
40
40
|
"expected #{relative_expectation} #{@collection_name}, got #{@given}"
|
41
41
|
end
|
42
42
|
|
43
|
-
def
|
43
|
+
def failure_message_for_should_not
|
44
44
|
if @relativity == :exactly
|
45
45
|
return "expected target not to have #{@expected} #{@collection_name}, got #{@given}"
|
46
46
|
elsif @relativity == :at_most
|
data/lib/spec/matchers/match.rb
CHANGED
@@ -1,5 +1,28 @@
|
|
1
1
|
module Spec
|
2
2
|
module Matchers
|
3
|
+
class Match
|
4
|
+
def initialize(expected)
|
5
|
+
@expected = expected
|
6
|
+
end
|
7
|
+
|
8
|
+
def matches?(actual)
|
9
|
+
@actual = actual
|
10
|
+
actual =~ @expected
|
11
|
+
end
|
12
|
+
|
13
|
+
def failure_message_for_should
|
14
|
+
return "expected #{@actual.inspect} to match #{@expected.inspect}", @expected, @actual
|
15
|
+
end
|
16
|
+
|
17
|
+
def failure_message_for_should_not
|
18
|
+
return "expected #{@actual.inspect} not to match #{@expected.inspect}", @expected, @actual
|
19
|
+
end
|
20
|
+
|
21
|
+
def description
|
22
|
+
"match #{@expected.inspect}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
3
26
|
|
4
27
|
# :call-seq:
|
5
28
|
# should match(regexp)
|
@@ -10,13 +33,8 @@ module Spec
|
|
10
33
|
# == Examples
|
11
34
|
#
|
12
35
|
# email.should match(/^([^\s]+)((?:[-a-z0-9]+\.)+[a-z]{2,})$/i)
|
13
|
-
def match(
|
14
|
-
|
15
|
-
matcher.failure_message = "expected #{actual.inspect} to match #{regexp.inspect}", regexp, actual
|
16
|
-
matcher.negative_failure_message = "expected #{actual.inspect} not to match #{regexp.inspect}", regexp, actual
|
17
|
-
matcher.description = "match #{regexp.inspect}"
|
18
|
-
actual =~ regexp
|
19
|
-
end
|
36
|
+
def match(expected)
|
37
|
+
Match.new(expected)
|
20
38
|
end
|
21
39
|
end
|
22
40
|
end
|
@@ -11,10 +11,10 @@ module Spec
|
|
11
11
|
@actual = actual
|
12
12
|
@extra_items = difference_between_arrays(@actual, @expected)
|
13
13
|
@missing_items = difference_between_arrays(@expected, @actual)
|
14
|
-
@extra_items.empty?
|
14
|
+
@extra_items.empty? & @missing_items.empty?
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
17
|
+
def failure_message_for_should
|
18
18
|
message = "expected collection contained: #{@expected.sort.inspect}\n"
|
19
19
|
message += "actual collection contained: #{@actual.sort.inspect}\n"
|
20
20
|
message += "the missing elements were: #{@missing_items.sort.inspect}\n" unless @missing_items.empty?
|
@@ -22,7 +22,7 @@ module Spec
|
|
22
22
|
message
|
23
23
|
end
|
24
24
|
|
25
|
-
def
|
25
|
+
def failure_message_for_should_not
|
26
26
|
"Matcher does not support should_not"
|
27
27
|
end
|
28
28
|
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Spec
|
2
|
+
module Matchers
|
3
|
+
class Matcher
|
4
|
+
def initialize(name, expected=nil, &block_passed_to_init)
|
5
|
+
@name = name
|
6
|
+
@expected = expected
|
7
|
+
@block = block_passed_to_init
|
8
|
+
@messages = {
|
9
|
+
:description => lambda {"#{name_to_sentence} #{expected}"},
|
10
|
+
:failure_message_for_should => lambda {|actual| "expected #{actual} to #{name_to_sentence} #{expected}"},
|
11
|
+
:failure_message_for_should_not => lambda {|actual| "expected #{actual} not to #{name_to_sentence} #{expected}"}
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
def matches?(actual)
|
16
|
+
@actual = actual
|
17
|
+
instance_exec @expected, &@block
|
18
|
+
instance_exec @actual, &@match_block
|
19
|
+
end
|
20
|
+
|
21
|
+
def description(&block)
|
22
|
+
cache_or_call_cached(:description, &block)
|
23
|
+
end
|
24
|
+
|
25
|
+
def failure_message_for_should(&block)
|
26
|
+
cache_or_call_cached(:failure_message_for_should, @actual, &block)
|
27
|
+
end
|
28
|
+
|
29
|
+
def failure_message_for_should_not(&block)
|
30
|
+
cache_or_call_cached(:failure_message_for_should_not, @actual, &block)
|
31
|
+
end
|
32
|
+
|
33
|
+
def match(&block)
|
34
|
+
@match_block = block
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def cache_or_call_cached(key, actual=nil, &block)
|
40
|
+
block ? @messages[key] = block :
|
41
|
+
actual.nil? ? @messages[key].call :
|
42
|
+
@messages[key].call(actual)
|
43
|
+
end
|
44
|
+
|
45
|
+
def name_to_sentence
|
46
|
+
@name_to_sentence ||= @name.to_s.gsub(/_/,' ')
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module Spec
|
2
2
|
module Matchers
|
3
3
|
def method_missing(sym, *args, &block) # :nodoc:
|
4
|
-
return Matchers::Be.new(sym, *args) if sym.
|
5
|
-
return
|
4
|
+
return Matchers::Be.new(sym, *args) if sym.to_s =~ /^be_/
|
5
|
+
return Matchers::Has.new(sym, *args) if sym.to_s =~ /^have_/
|
6
6
|
super
|
7
7
|
end
|
8
8
|
end
|
@@ -4,15 +4,16 @@ module Spec
|
|
4
4
|
class OperatorMatcher
|
5
5
|
class << self
|
6
6
|
def registry
|
7
|
-
@registry ||=
|
7
|
+
@registry ||= {}
|
8
8
|
end
|
9
9
|
|
10
10
|
def register(klass, operator, matcher)
|
11
|
+
registry[klass] ||= {}
|
11
12
|
registry[klass][operator] = matcher
|
12
13
|
end
|
13
14
|
|
14
15
|
def get(klass, operator)
|
15
|
-
registry[klass][operator]
|
16
|
+
registry[klass] && registry[klass][operator]
|
16
17
|
end
|
17
18
|
end
|
18
19
|
|
@@ -25,9 +26,7 @@ module Spec
|
|
25
26
|
if matcher = OperatorMatcher.get(@actual.class, operator)
|
26
27
|
@actual.send(::Spec::Matchers.last_should, matcher.new(expected))
|
27
28
|
else
|
28
|
-
|
29
|
-
@operator, @expected = operator, expected
|
30
|
-
__delegate_operator(@actual, operator, expected)
|
29
|
+
eval_match(@actual, operator, expected)
|
31
30
|
end
|
32
31
|
end
|
33
32
|
end
|
@@ -43,6 +42,14 @@ module Spec
|
|
43
42
|
def description
|
44
43
|
"#{@operator} #{@expected.inspect}"
|
45
44
|
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def eval_match(actual, operator, expected)
|
49
|
+
::Spec::Matchers.last_matcher = self
|
50
|
+
@operator, @expected = operator, expected
|
51
|
+
__delegate_operator(actual, operator, expected)
|
52
|
+
end
|
46
53
|
|
47
54
|
end
|
48
55
|
|
@@ -31,7 +31,7 @@ module Spec
|
|
31
31
|
eval_block if @raised_expected_error && @with_expected_message && @block
|
32
32
|
end
|
33
33
|
ensure
|
34
|
-
return (@raised_expected_error
|
34
|
+
return (@raised_expected_error & @with_expected_message) ? (@eval_block ? @eval_block_passed : true) : false
|
35
35
|
end
|
36
36
|
|
37
37
|
def eval_block
|
@@ -55,11 +55,11 @@ module Spec
|
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
-
def
|
58
|
+
def failure_message_for_should
|
59
59
|
@eval_block ? @given_error.message : "expected #{expected_error}#{given_error}"
|
60
60
|
end
|
61
61
|
|
62
|
-
def
|
62
|
+
def failure_message_for_should_not
|
63
63
|
"expected no #{expected_error}#{given_error}"
|
64
64
|
end
|
65
65
|
|
@@ -16,16 +16,15 @@ module Spec
|
|
16
16
|
return @names_not_responded_to.empty?
|
17
17
|
end
|
18
18
|
|
19
|
-
def
|
19
|
+
def failure_message_for_should
|
20
20
|
"expected #{@actual.inspect} to respond to #{@names_not_responded_to.collect {|name| name.inspect }.join(', ')}#{with_arity}"
|
21
21
|
end
|
22
22
|
|
23
|
-
def
|
23
|
+
def failure_message_for_should_not
|
24
24
|
"expected #{@actual.inspect} not to respond to #{@names.collect {|name| name.inspect }.join(', ')}"
|
25
25
|
end
|
26
26
|
|
27
27
|
def description
|
28
|
-
# Ruby 1.9 returns the same thing for array.to_s as array.inspect, so just use array.inspect here
|
29
28
|
"respond to #{pp_names}#{with_arity}"
|
30
29
|
end
|
31
30
|
|
@@ -51,6 +50,7 @@ module Spec
|
|
51
50
|
end
|
52
51
|
|
53
52
|
def pp_names
|
53
|
+
# Ruby 1.9 returns the same thing for array.to_s as array.inspect, so just use array.inspect here
|
54
54
|
@names.length == 1 ? "##{@names.first}" : @names.inspect
|
55
55
|
end
|
56
56
|
end
|
@@ -6,18 +6,18 @@ module Spec
|
|
6
6
|
@block = block
|
7
7
|
end
|
8
8
|
|
9
|
-
def matches?(
|
9
|
+
def matches?(actual, &block)
|
10
10
|
@block = block if block
|
11
|
-
@
|
12
|
-
@block.call(
|
11
|
+
@actual = actual
|
12
|
+
@block.call(actual)
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
16
|
-
"expected #{@
|
15
|
+
def failure_message_for_should
|
16
|
+
"expected #{@actual} to satisfy block"
|
17
17
|
end
|
18
18
|
|
19
|
-
def
|
20
|
-
"expected #{@
|
19
|
+
def failure_message_for_should_not
|
20
|
+
"expected #{@actual} not to satisfy block"
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -35,15 +35,13 @@ module Spec
|
|
35
35
|
if @expected_arg.nil?
|
36
36
|
return @caught_symbol == @expected_symbol
|
37
37
|
else
|
38
|
-
|
39
|
-
# puts [@caught_arg, @expected_arg].inspect
|
40
|
-
return @caught_symbol == @expected_symbol && @caught_arg == @expected_arg
|
38
|
+
return (@caught_symbol == @expected_symbol) & (@caught_arg == @expected_arg)
|
41
39
|
end
|
42
40
|
end
|
43
41
|
end
|
44
42
|
end
|
45
43
|
|
46
|
-
def
|
44
|
+
def failure_message_for_should
|
47
45
|
if @caught_symbol
|
48
46
|
"expected #{expected}, got #{@caught_symbol.inspect}"
|
49
47
|
else
|
@@ -51,7 +49,7 @@ module Spec
|
|
51
49
|
end
|
52
50
|
end
|
53
51
|
|
54
|
-
def
|
52
|
+
def failure_message_for_should_not
|
55
53
|
if @expected_symbol
|
56
54
|
"expected #{expected} not to be thrown"
|
57
55
|
else
|
data/lib/spec/mocks.rb
CHANGED
@@ -105,11 +105,11 @@ module Spec
|
|
105
105
|
# my_mock.should_receive(:sym).with(*args)
|
106
106
|
# my_mock.should_not_receive(:sym).with(*args)
|
107
107
|
#
|
108
|
-
# == Argument
|
108
|
+
# == Argument Matchers
|
109
109
|
#
|
110
110
|
# Arguments that are passed to #with are compared with actual arguments received
|
111
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
|
112
|
+
# rather than the arguments themselves, you can use any of RSpec's Expression Matchers.
|
113
113
|
# They don't all make syntactic sense (they were primarily designed for use with
|
114
114
|
# Spec::Expectations), but you are free to create your own custom Spec::Matchers.
|
115
115
|
#
|
@@ -120,7 +120,7 @@ module Spec
|
|
120
120
|
#
|
121
121
|
# my_mock.should_receive(:sym).with(no_args())
|
122
122
|
# my_mock.should_receive(:sym).with(any_args())
|
123
|
-
# my_mock.should_receive(:sym).with(1,
|
123
|
+
# my_mock.should_receive(:sym).with(1, kind_of(Numeric), "b") #2nd argument can any kind of Numeric
|
124
124
|
# my_mock.should_receive(:sym).with(1, boolean(), "b") #2nd argument can true or false
|
125
125
|
# my_mock.should_receive(:sym).with(1, /abc/, "b") #2nd argument can be any String matching the submitted Regexp
|
126
126
|
# my_mock.should_receive(:sym).with(1, anything(), "b") #2nd argument can be anything at all
|
@@ -6,37 +6,37 @@ module Spec
|
|
6
6
|
|
7
7
|
def initialize(args, &block)
|
8
8
|
@args = args
|
9
|
-
@
|
9
|
+
@matchers_block = block
|
10
10
|
|
11
|
-
if
|
11
|
+
if ArgumentMatchers::AnyArgsMatcher === args.first
|
12
12
|
@match_any_args = true
|
13
|
-
elsif
|
14
|
-
@
|
13
|
+
elsif ArgumentMatchers::NoArgsMatcher === args.first
|
14
|
+
@matchers = []
|
15
15
|
else
|
16
|
-
@
|
16
|
+
@matchers = args.collect {|arg| matcher_for(arg)}
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
def
|
21
|
-
return
|
22
|
-
return
|
23
|
-
return
|
20
|
+
def matcher_for(arg)
|
21
|
+
return ArgumentMatchers::MatcherMatcher.new(arg) if is_matcher?(arg)
|
22
|
+
return ArgumentMatchers::RegexpMatcher.new(arg) if arg.is_a?(Regexp)
|
23
|
+
return ArgumentMatchers::EqualityProxy.new(arg)
|
24
24
|
end
|
25
25
|
|
26
26
|
def is_matcher?(obj)
|
27
|
-
return obj.respond_to?(:matches?)
|
27
|
+
return obj.respond_to?(:matches?) & obj.respond_to?(:description)
|
28
28
|
end
|
29
29
|
|
30
30
|
def args_match?(given_args)
|
31
|
-
match_any_args? ||
|
31
|
+
match_any_args? || matchers_block_matches?(given_args) || matchers_match?(given_args)
|
32
32
|
end
|
33
33
|
|
34
|
-
def
|
35
|
-
@
|
34
|
+
def matchers_block_matches?(given_args)
|
35
|
+
@matchers_block ? @matchers_block.call(*given_args) : nil
|
36
36
|
end
|
37
37
|
|
38
|
-
def
|
39
|
-
@
|
38
|
+
def matchers_match?(given_args)
|
39
|
+
@matchers == given_args
|
40
40
|
end
|
41
41
|
|
42
42
|
def match_any_args?
|