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
data/lib/spec/interop/test.rb
CHANGED
@@ -5,8 +5,7 @@ module Test
|
|
5
5
|
# This extension of the standard Test::Unit::TestCase makes RSpec
|
6
6
|
# available from within, so that you can do things like:
|
7
7
|
#
|
8
|
-
# require 'test/unit'
|
9
|
-
# require 'spec'
|
8
|
+
# require 'spec/test/unit'
|
10
9
|
#
|
11
10
|
# class MyTest < Test::Unit::TestCase
|
12
11
|
# it "should work with Test::Unit assertions" do
|
@@ -41,33 +40,17 @@ module Test
|
|
41
40
|
before(:each) {setup}
|
42
41
|
after(:each) {teardown}
|
43
42
|
|
44
|
-
def initialize(
|
45
|
-
|
46
|
-
|
47
|
-
# TODO - examples fail in rspec-rails if we remove "|| pending_implementation"
|
48
|
-
# - find a way to fail without it in rspec's code examples
|
49
|
-
@_implementation = implementation || pending_implementation
|
50
|
-
|
51
|
-
@_result = ::Test::Unit::TestResult.new
|
52
|
-
# @method_name is important to set here because it complies with Test::Unit's interface.
|
43
|
+
def initialize(description, options={}, &implementation)
|
44
|
+
super
|
53
45
|
# Some Test::Unit extensions depend on @method_name being present.
|
54
|
-
@method_name =
|
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
|
46
|
+
@method_name = description
|
47
|
+
@_result = ::Test::Unit::TestResult.new
|
59
48
|
end
|
60
49
|
|
61
50
|
def run(ignore_this_argument=nil)
|
62
51
|
super()
|
63
52
|
end
|
64
53
|
|
65
|
-
private
|
66
|
-
|
67
|
-
def pending_implementation
|
68
|
-
error = Spec::Example::NotYetImplementedError.new(caller)
|
69
|
-
lambda { raise(error) }
|
70
|
-
end
|
71
54
|
end
|
72
55
|
end
|
73
56
|
end
|
data/lib/spec/matchers.rb
CHANGED
@@ -1,24 +1,29 @@
|
|
1
|
+
require 'spec/matchers/extensions/instance_exec'
|
2
|
+
require 'spec/matchers/matcher'
|
1
3
|
require 'spec/matchers/operator_matcher'
|
2
|
-
require 'spec/matchers/generated_descriptions'
|
3
|
-
require 'spec/matchers/errors'
|
4
|
-
require 'spec/matchers/method_missing'
|
5
|
-
require 'spec/matchers/simple_matcher'
|
6
4
|
require 'spec/matchers/be'
|
7
5
|
require 'spec/matchers/be_close'
|
6
|
+
require 'spec/matchers/be_instance_of'
|
7
|
+
require 'spec/matchers/be_kind_of'
|
8
8
|
require 'spec/matchers/change'
|
9
|
-
require 'spec/matchers/match_array'
|
10
9
|
require 'spec/matchers/eql'
|
11
10
|
require 'spec/matchers/equal'
|
11
|
+
require 'spec/matchers/errors'
|
12
12
|
require 'spec/matchers/exist'
|
13
|
+
require 'spec/matchers/generated_descriptions'
|
13
14
|
require 'spec/matchers/has'
|
14
15
|
require 'spec/matchers/have'
|
15
16
|
require 'spec/matchers/include'
|
16
17
|
require 'spec/matchers/match'
|
18
|
+
require 'spec/matchers/match_array'
|
19
|
+
require 'spec/matchers/method_missing'
|
17
20
|
require 'spec/matchers/raise_error'
|
18
21
|
require 'spec/matchers/respond_to'
|
19
22
|
require 'spec/matchers/satisfy'
|
23
|
+
require 'spec/matchers/simple_matcher'
|
20
24
|
require 'spec/matchers/throw_symbol'
|
21
25
|
require 'spec/matchers/wrap_expectation'
|
26
|
+
require 'spec/matchers/compatibility'
|
22
27
|
|
23
28
|
module Spec
|
24
29
|
|
@@ -26,12 +31,21 @@ module Spec
|
|
26
31
|
# is any object that responds to the following methods:
|
27
32
|
#
|
28
33
|
# matches?(actual)
|
29
|
-
#
|
30
|
-
#
|
34
|
+
# failure_message_for_should
|
35
|
+
#
|
36
|
+
# These methods are also part of the matcher protocol, but are optional:
|
37
|
+
#
|
38
|
+
# does_not_match?(actual)
|
39
|
+
# failure_message_for_should_not
|
31
40
|
# description #optional
|
32
41
|
#
|
42
|
+
# These methods are from older versions of the protocol. They are still supported,
|
43
|
+
# but are not recommended:
|
44
|
+
#
|
45
|
+
# failure_message (use failure_message_for_should instead)
|
46
|
+
# negative_failure_message (use failure_message_for_should_not instead)
|
47
|
+
#
|
33
48
|
# See Spec::Expectations to learn how to use these as Expectation Matchers.
|
34
|
-
# See Spec::Mocks to learn how to use them as Mock Argument Constraints.
|
35
49
|
#
|
36
50
|
# == Predicates
|
37
51
|
#
|
data/lib/spec/matchers/be.rb
CHANGED
@@ -26,13 +26,13 @@ module Spec
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
def
|
29
|
+
def failure_message_for_should
|
30
30
|
handling_predicate? ?
|
31
31
|
"expected #{predicate}#{args_to_s} to return true, got #{@result.inspect}" :
|
32
32
|
"expected #{@comparison_method} #{expected}, got #{@actual.inspect}".gsub(' ',' ')
|
33
33
|
end
|
34
34
|
|
35
|
-
def
|
35
|
+
def failure_message_for_should_not
|
36
36
|
if handling_predicate?
|
37
37
|
"expected #{predicate}#{args_to_s} to return false, got #{@result.inspect}"
|
38
38
|
else
|
@@ -60,12 +60,7 @@ it reads really poorly.
|
|
60
60
|
|
61
61
|
private
|
62
62
|
def match_or_compare(actual)
|
63
|
-
|
64
|
-
when TrueClass
|
65
|
-
@actual
|
66
|
-
else
|
67
|
-
@actual.__send__(comparison_method, @expected)
|
68
|
-
end
|
63
|
+
TrueClass === @expected ? @actual : @actual.__send__(comparison_method, @expected)
|
69
64
|
end
|
70
65
|
|
71
66
|
def comparison_method
|
@@ -87,7 +82,7 @@ it reads really poorly.
|
|
87
82
|
def parse_expected(expected)
|
88
83
|
["be_an_","be_a_","be_"].each do |prefix|
|
89
84
|
handling_predicate!
|
90
|
-
if expected.
|
85
|
+
if expected.to_s =~ /^#{prefix}/
|
91
86
|
set_prefix(prefix)
|
92
87
|
expected = expected.to_s.sub(prefix,"")
|
93
88
|
[true, false, nil].each do |val|
|
@@ -1,5 +1,24 @@
|
|
1
1
|
module Spec
|
2
2
|
module Matchers
|
3
|
+
|
4
|
+
class BeClose
|
5
|
+
def initialize(expected, delta)
|
6
|
+
@expected, @delta = expected, delta
|
7
|
+
end
|
8
|
+
|
9
|
+
def matches?(actual)
|
10
|
+
@actual = actual
|
11
|
+
(@actual - @expected).abs < @delta
|
12
|
+
end
|
13
|
+
|
14
|
+
def failure_message_for_should
|
15
|
+
"expected #{@expected} +/- (< #{@delta}), got #{@actual}"
|
16
|
+
end
|
17
|
+
|
18
|
+
def description
|
19
|
+
"be close to #{@expected} (within +- #{@delta})"
|
20
|
+
end
|
21
|
+
end
|
3
22
|
|
4
23
|
# :call-seq:
|
5
24
|
# should be_close(expected, delta)
|
@@ -11,11 +30,7 @@ module Spec
|
|
11
30
|
#
|
12
31
|
# result.should be_close(3.0, 0.5)
|
13
32
|
def be_close(expected, delta)
|
14
|
-
|
15
|
-
matcher.failure_message = "expected #{expected} +/- (< #{delta}), got #{actual}"
|
16
|
-
matcher.description = "be close to #{expected} (within +- #{delta})"
|
17
|
-
(actual - expected).abs < delta
|
18
|
-
end
|
33
|
+
BeClose.new(expected, delta)
|
19
34
|
end
|
20
35
|
end
|
21
36
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Spec
|
2
|
+
module Matchers
|
3
|
+
class BeInstanceOf
|
4
|
+
def initialize(expected)
|
5
|
+
@expected = expected
|
6
|
+
end
|
7
|
+
|
8
|
+
def matches?(actual)
|
9
|
+
@actual = actual
|
10
|
+
@actual.instance_of?(@expected)
|
11
|
+
end
|
12
|
+
|
13
|
+
def description
|
14
|
+
"be an instance of #{@expected}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def failure_message_for_should
|
18
|
+
"expected instance of #{@expected}, got #{@actual.inspect}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def failure_message_for_should_not
|
22
|
+
"expected #{@actual.inspect} not to be an instance of #{@expected}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# :call-seq:
|
27
|
+
# should be_instance_of(expected)
|
28
|
+
# should be_an_instance_of(expected)
|
29
|
+
# should_not be_instance_of(expected)
|
30
|
+
# should_not be_an_instance_of(expected)
|
31
|
+
#
|
32
|
+
# Passes if actual.instance_of?(expected)
|
33
|
+
#
|
34
|
+
# == Examples
|
35
|
+
#
|
36
|
+
# 5.should be_instance_of(Fixnum)
|
37
|
+
# 5.should_not be_instance_of(Numeric)
|
38
|
+
# 5.should_not be_instance_of(Float)
|
39
|
+
def be_instance_of(expected)
|
40
|
+
BeInstanceOf.new(expected)
|
41
|
+
end
|
42
|
+
|
43
|
+
alias_method :be_an_instance_of, :be_instance_of
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Spec
|
2
|
+
module Matchers
|
3
|
+
class BeKindOf
|
4
|
+
def initialize(expected)
|
5
|
+
@expected = expected
|
6
|
+
end
|
7
|
+
|
8
|
+
def matches?(actual)
|
9
|
+
@actual = actual
|
10
|
+
@actual.kind_of?(@expected)
|
11
|
+
end
|
12
|
+
|
13
|
+
def description
|
14
|
+
"be a kind of #{@expected}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def failure_message_for_should
|
18
|
+
"expected kind of #{@expected}, got #{@actual.inspect}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def failure_message_for_should_not
|
22
|
+
"expected #{@actual.inspect} not to be a kind of #{@expected}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# :call-seq:
|
27
|
+
# should be_kind_of(expected)
|
28
|
+
# should be_a_kind_of(expected)
|
29
|
+
# should_not be_kind_of(expected)
|
30
|
+
# should_not be_a_kind_of(expected)
|
31
|
+
#
|
32
|
+
# Passes if actual.kind_of?(expected)
|
33
|
+
#
|
34
|
+
# == Examples
|
35
|
+
#
|
36
|
+
# 5.should be_kind_of(Fixnum)
|
37
|
+
# 5.should be_kind_of(Numeric)
|
38
|
+
# 5.should_not be_kind_of(Float)
|
39
|
+
def be_kind_of(expected)
|
40
|
+
BeKindOf.new(expected)
|
41
|
+
end
|
42
|
+
|
43
|
+
alias_method :be_a_kind_of, :be_kind_of
|
44
|
+
end
|
45
|
+
end
|
data/lib/spec/matchers/change.rb
CHANGED
@@ -5,9 +5,7 @@ module Spec
|
|
5
5
|
class Change #:nodoc:
|
6
6
|
def initialize(receiver=nil, message=nil, &block)
|
7
7
|
@message = message || "result"
|
8
|
-
@value_proc = block || lambda {
|
9
|
-
receiver.__send__(message)
|
10
|
-
}
|
8
|
+
@value_proc = block || lambda {receiver.__send__(message)}
|
11
9
|
end
|
12
10
|
|
13
11
|
def matches?(event_proc)
|
@@ -17,7 +15,7 @@ module Spec
|
|
17
15
|
event_proc.call
|
18
16
|
@after = evaluate_value_proc
|
19
17
|
|
20
|
-
return false if @from unless @from == @before
|
18
|
+
return (@to = false) if @from unless @from == @before
|
21
19
|
return false if @to unless @to == @after
|
22
20
|
return (@before + @amount == @after) if @amount
|
23
21
|
return ((@after - @before) >= @minimum) if @minimum
|
@@ -36,7 +34,7 @@ MESSAGE
|
|
36
34
|
@value_proc.call
|
37
35
|
end
|
38
36
|
|
39
|
-
def
|
37
|
+
def failure_message_for_should
|
40
38
|
if @to
|
41
39
|
"#{@message} should have been changed to #{@to.inspect}, but is now #{@after.inspect}"
|
42
40
|
elsif @from
|
@@ -56,7 +54,7 @@ MESSAGE
|
|
56
54
|
@after - @before
|
57
55
|
end
|
58
56
|
|
59
|
-
def
|
57
|
+
def failure_message_for_should_not
|
60
58
|
"#{@message} should not have changed, but did change from #{@before.inspect} to #{@after.inspect}"
|
61
59
|
end
|
62
60
|
|
@@ -84,6 +82,10 @@ MESSAGE
|
|
84
82
|
@from = from
|
85
83
|
self
|
86
84
|
end
|
85
|
+
|
86
|
+
def description
|
87
|
+
"change ##{@message}"
|
88
|
+
end
|
87
89
|
end
|
88
90
|
|
89
91
|
# :call-seq:
|
@@ -0,0 +1,14 @@
|
|
1
|
+
Spec::Matchers.constants.each do |c|
|
2
|
+
if Class === (klass = Spec::Matchers.const_get(c))
|
3
|
+
if klass.public_instance_methods.include?('failure_message_for_should')
|
4
|
+
klass.class_eval do
|
5
|
+
alias_method :failure_message, :failure_message_for_should
|
6
|
+
end
|
7
|
+
end
|
8
|
+
if klass.public_instance_methods.include?('failure_message_for_should_not')
|
9
|
+
klass.class_eval do
|
10
|
+
alias_method :negative_failure_message, :failure_message_for_should_not
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/spec/matchers/eql.rb
CHANGED
@@ -1,5 +1,28 @@
|
|
1
1
|
module Spec
|
2
2
|
module Matchers
|
3
|
+
class Eql
|
4
|
+
def initialize(expected)
|
5
|
+
@expected = expected
|
6
|
+
end
|
7
|
+
|
8
|
+
def matches?(actual)
|
9
|
+
@actual = actual
|
10
|
+
@actual.eql?(@expected)
|
11
|
+
end
|
12
|
+
|
13
|
+
def failure_message_for_should
|
14
|
+
return "expected #{@expected.inspect}, got #{@actual.inspect} (using .eql?)", @expected, @actual
|
15
|
+
end
|
16
|
+
|
17
|
+
def failure_message_for_should_not
|
18
|
+
return "expected #{@actual.inspect} not to equal #{@expected.inspect} (using .eql?)", @expected, @actual
|
19
|
+
end
|
20
|
+
|
21
|
+
def description
|
22
|
+
"eql #{@expected.inspect}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
3
26
|
|
4
27
|
# :call-seq:
|
5
28
|
# should eql(expected)
|
@@ -14,12 +37,7 @@ module Spec
|
|
14
37
|
# 5.should eql(5)
|
15
38
|
# 5.should_not eql(3)
|
16
39
|
def eql(expected)
|
17
|
-
|
18
|
-
matcher.failure_message = "expected #{expected.inspect}, got #{actual.inspect} (using .eql?)", expected, actual
|
19
|
-
matcher.negative_failure_message = "expected #{actual.inspect} not to equal #{expected.inspect} (using .eql?)", expected, actual
|
20
|
-
matcher.description = "eql #{expected.inspect}"
|
21
|
-
actual.eql?(expected)
|
22
|
-
end
|
40
|
+
Eql.new(expected)
|
23
41
|
end
|
24
42
|
end
|
25
43
|
end
|
data/lib/spec/matchers/equal.rb
CHANGED
@@ -1,5 +1,28 @@
|
|
1
1
|
module Spec
|
2
2
|
module Matchers
|
3
|
+
|
4
|
+
class Equal
|
5
|
+
def initialize(expected)
|
6
|
+
@expected = expected
|
7
|
+
end
|
8
|
+
|
9
|
+
def matches?(actual)
|
10
|
+
@actual = actual
|
11
|
+
@actual.equal?(@expected)
|
12
|
+
end
|
13
|
+
|
14
|
+
def failure_message_for_should
|
15
|
+
return "expected #{@expected.inspect}, got #{@actual.inspect} (using .equal?)", @expected, @actual
|
16
|
+
end
|
17
|
+
|
18
|
+
def failure_message_for_should_not
|
19
|
+
return "expected #{@actual.inspect} not to equal #{@expected.inspect} (using .equal?)", @expected, @actual
|
20
|
+
end
|
21
|
+
|
22
|
+
def description
|
23
|
+
"equal #{@expected.inspect}"
|
24
|
+
end
|
25
|
+
end
|
3
26
|
|
4
27
|
# :call-seq:
|
5
28
|
# should equal(expected)
|
@@ -14,12 +37,7 @@ module Spec
|
|
14
37
|
# 5.should equal(5) #Fixnums are equal
|
15
38
|
# "5".should_not equal("5") #Strings that look the same are not the same object
|
16
39
|
def equal(expected)
|
17
|
-
|
18
|
-
matcher.failure_message = "expected #{expected.inspect}, got #{actual.inspect} (using .equal?)", expected, actual
|
19
|
-
matcher.negative_failure_message = "expected #{actual.inspect} not to equal #{expected.inspect} (using .equal?)", expected, actual
|
20
|
-
matcher.description = "equal #{expected.inspect}"
|
21
|
-
actual.equal?(expected)
|
22
|
-
end
|
40
|
+
Equal.new(expected)
|
23
41
|
end
|
24
42
|
end
|
25
43
|
end
|
data/lib/spec/matchers/exist.rb
CHANGED
@@ -1,16 +1,32 @@
|
|
1
1
|
module Spec
|
2
2
|
module Matchers
|
3
|
+
|
4
|
+
class Exist
|
5
|
+
def matches?(actual)
|
6
|
+
@actual = actual
|
7
|
+
actual.exist?
|
8
|
+
end
|
9
|
+
|
10
|
+
def failure_message_for_should
|
11
|
+
"expected #{@actual.inspect} to exist, but it doesn't."
|
12
|
+
end
|
13
|
+
|
14
|
+
def failure_message_for_should_not
|
15
|
+
"expected #{@actual.inspect} to not exist, but it does."
|
16
|
+
end
|
17
|
+
|
18
|
+
def description
|
19
|
+
"exists"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
3
23
|
# :call-seq:
|
4
24
|
# should exist
|
5
25
|
# should_not exist
|
6
26
|
#
|
7
27
|
# Passes if actual.exist?
|
8
28
|
def exist
|
9
|
-
|
10
|
-
matcher.failure_message = "expected #{actual.inspect} to exist, but it doesn't."
|
11
|
-
matcher.negative_failure_message = "expected #{actual.inspect} to not exist, but it does."
|
12
|
-
actual.exist?
|
13
|
-
end
|
29
|
+
Exist.new
|
14
30
|
end
|
15
31
|
end
|
16
32
|
end
|