rspec 1.1.11 → 1.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.autotest +4 -0
- data/History.txt +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
@@ -0,0 +1,48 @@
|
|
1
|
+
module Spec
|
2
|
+
module Matchers
|
3
|
+
def self.last_matcher
|
4
|
+
@last_matcher
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.last_matcher=(last_matcher)
|
8
|
+
@last_matcher = last_matcher
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.last_should
|
12
|
+
@last_should
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.last_should=(last_should)
|
16
|
+
@last_should = last_should
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.clear_generated_description
|
20
|
+
self.last_matcher = nil
|
21
|
+
self.last_should = nil
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.generated_description
|
25
|
+
return nil if last_should.nil?
|
26
|
+
"#{last_should.to_s.gsub('_',' ')} #{last_description}"
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def self.last_description
|
32
|
+
last_matcher.respond_to?(:description) ? last_matcher.description : <<-MESSAGE
|
33
|
+
When you call a matcher in an example without a String, like this:
|
34
|
+
|
35
|
+
specify { object.should matcher }
|
36
|
+
|
37
|
+
or this:
|
38
|
+
|
39
|
+
it { should matcher }
|
40
|
+
|
41
|
+
the runner expects the matcher to have a #describe method. You should either
|
42
|
+
add a String to the example this matcher is being used in, or give it a
|
43
|
+
description method. Then you won't have to suffer this lengthy warning again.
|
44
|
+
MESSAGE
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
data/lib/spec/matchers/has.rb
CHANGED
@@ -1,34 +1,18 @@
|
|
1
1
|
module Spec
|
2
2
|
module Matchers
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
def matches?(given)
|
11
|
-
given.__send__(predicate, *@args)
|
12
|
-
end
|
13
|
-
|
14
|
-
def failure_message
|
15
|
-
"expected ##{predicate}(#{@args[0].inspect}) to return true, got false"
|
16
|
-
end
|
17
|
-
|
18
|
-
def negative_failure_message
|
19
|
-
"expected ##{predicate}(#{@args[0].inspect}) to return false, got true"
|
3
|
+
def has(sym, *args) # :nodoc:
|
4
|
+
simple_matcher do |actual, matcher|
|
5
|
+
matcher.failure_message = "expected ##{predicate(sym)}(#{args[0].inspect}) to return true, got false"
|
6
|
+
matcher.negative_failure_message = "expected ##{predicate(sym)}(#{args[0].inspect}) to return false, got true"
|
7
|
+
matcher.description = "have key #{args[0].inspect}"
|
8
|
+
actual.__send__(predicate(sym), *args)
|
20
9
|
end
|
21
|
-
|
22
|
-
def description
|
23
|
-
"have key #{@args[0].inspect}"
|
24
|
-
end
|
25
|
-
|
26
|
-
private
|
27
|
-
def predicate
|
28
|
-
"#{@sym.to_s.sub("have_","has_")}?".to_sym
|
29
|
-
end
|
30
|
-
|
31
10
|
end
|
32
|
-
|
11
|
+
|
12
|
+
private
|
13
|
+
def predicate(sym)
|
14
|
+
"#{sym.to_s.sub("have_","has_")}?".to_sym
|
15
|
+
end
|
16
|
+
|
33
17
|
end
|
34
18
|
end
|
@@ -7,16 +7,19 @@ module Spec
|
|
7
7
|
@expecteds = expecteds
|
8
8
|
end
|
9
9
|
|
10
|
-
def matches?(
|
11
|
-
@
|
10
|
+
def matches?(actual)
|
11
|
+
@actual = actual
|
12
12
|
@expecteds.each do |expected|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
if actual.is_a?(Hash)
|
14
|
+
if expected.is_a?(Hash)
|
15
|
+
expected.each_pair do |k,v|
|
16
|
+
return false unless actual[k] == v
|
17
|
+
end
|
18
|
+
else
|
19
|
+
return false unless actual.has_key?(expected)
|
17
20
|
end
|
18
21
|
else
|
19
|
-
return false unless
|
22
|
+
return false unless actual.include?(expected)
|
20
23
|
end
|
21
24
|
end
|
22
25
|
true
|
@@ -36,7 +39,7 @@ module Spec
|
|
36
39
|
|
37
40
|
private
|
38
41
|
def _message(maybe_not="")
|
39
|
-
"expected #{@
|
42
|
+
"expected #{@actual.inspect} #{maybe_not}to include #{_pretty_print(@expecteds)}"
|
40
43
|
end
|
41
44
|
|
42
45
|
def _pretty_print(array)
|
@@ -58,7 +61,7 @@ module Spec
|
|
58
61
|
# should include(expected)
|
59
62
|
# should_not include(expected)
|
60
63
|
#
|
61
|
-
# Passes if
|
64
|
+
# Passes if actual includes expected. This works for
|
62
65
|
# collections and Strings. You can also pass in multiple args
|
63
66
|
# and it will only pass if all args are found in collection.
|
64
67
|
#
|
data/lib/spec/matchers/match.rb
CHANGED
@@ -1,41 +1,22 @@
|
|
1
1
|
module Spec
|
2
2
|
module Matchers
|
3
3
|
|
4
|
-
class Match #:nodoc:
|
5
|
-
def initialize(regexp)
|
6
|
-
@regexp = regexp
|
7
|
-
end
|
8
|
-
|
9
|
-
def matches?(given)
|
10
|
-
@given = given
|
11
|
-
return true if given =~ @regexp
|
12
|
-
return false
|
13
|
-
end
|
14
|
-
|
15
|
-
def failure_message
|
16
|
-
return "expected #{@given.inspect} to match #{@regexp.inspect}", @regexp, @given
|
17
|
-
end
|
18
|
-
|
19
|
-
def negative_failure_message
|
20
|
-
return "expected #{@given.inspect} not to match #{@regexp.inspect}", @regexp, @given
|
21
|
-
end
|
22
|
-
|
23
|
-
def description
|
24
|
-
"match #{@regexp.inspect}"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
4
|
# :call-seq:
|
29
5
|
# should match(regexp)
|
30
6
|
# should_not match(regexp)
|
31
7
|
#
|
32
|
-
# Given a Regexp, passes if
|
8
|
+
# Given a Regexp, passes if actual =~ regexp
|
33
9
|
#
|
34
10
|
# == Examples
|
35
11
|
#
|
36
|
-
# email.should match(/^([
|
12
|
+
# email.should match(/^([^\s]+)((?:[-a-z0-9]+\.)+[a-z]{2,})$/i)
|
37
13
|
def match(regexp)
|
38
|
-
|
14
|
+
simple_matcher do |actual, matcher|
|
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
|
39
20
|
end
|
40
21
|
end
|
41
22
|
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module Spec
|
2
|
+
module Matchers
|
3
|
+
|
4
|
+
class MatchArray #:nodoc:
|
5
|
+
|
6
|
+
def initialize(expected)
|
7
|
+
@expected = expected
|
8
|
+
end
|
9
|
+
|
10
|
+
def matches?(actual)
|
11
|
+
@actual = actual
|
12
|
+
@extra_items = difference_between_arrays(@actual, @expected)
|
13
|
+
@missing_items = difference_between_arrays(@expected, @actual)
|
14
|
+
@extra_items.empty? && @missing_items.empty?
|
15
|
+
end
|
16
|
+
|
17
|
+
def failure_message
|
18
|
+
message = "expected collection contained: #{@expected.sort.inspect}\n"
|
19
|
+
message += "actual collection contained: #{@actual.sort.inspect}\n"
|
20
|
+
message += "the missing elements were: #{@missing_items.sort.inspect}\n" unless @missing_items.empty?
|
21
|
+
message += "the extra elements were: #{@extra_items.sort.inspect}\n" unless @extra_items.empty?
|
22
|
+
message
|
23
|
+
end
|
24
|
+
|
25
|
+
def negative_failure_message
|
26
|
+
"Matcher does not support should_not"
|
27
|
+
end
|
28
|
+
|
29
|
+
def description
|
30
|
+
"contain exactly #{_pretty_print(@expected)}"
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def difference_between_arrays(array_1, array_2)
|
36
|
+
difference = array_1.dup
|
37
|
+
array_2.each do |element|
|
38
|
+
if index = difference.index(element)
|
39
|
+
difference.delete_at(index)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
difference
|
43
|
+
end
|
44
|
+
|
45
|
+
def _pretty_print(array)
|
46
|
+
result = ""
|
47
|
+
array.each_with_index do |item, index|
|
48
|
+
if index < (array.length - 2)
|
49
|
+
result << "#{item.inspect}, "
|
50
|
+
elsif index < (array.length - 1)
|
51
|
+
result << "#{item.inspect} and "
|
52
|
+
else
|
53
|
+
result << "#{item.inspect}"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
result
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
# :call-seq:
|
62
|
+
# should =~ expected
|
63
|
+
#
|
64
|
+
# Passes if actual contains all of the expected regardless of order.
|
65
|
+
# This works for collections. Pass in multiple args and it will only
|
66
|
+
# pass if all args are found in collection.
|
67
|
+
#
|
68
|
+
# NOTE: there is no should_not version of array.should =~ other_array
|
69
|
+
#
|
70
|
+
# == Examples
|
71
|
+
#
|
72
|
+
# [1,2,3].should =~ [1,2,3] # => would pass
|
73
|
+
# [1,2,3].should =~ [2,3,1] # => would pass
|
74
|
+
# [1,2,3,4].should =~ [1,2,3] # => would fail
|
75
|
+
# [1,2,2,3].should =~ [1,2,3] # => would fail
|
76
|
+
# [1,2,3].should =~ [1,2,3,4] # => would fail
|
77
|
+
OperatorMatcher.register(Array, '=~', Spec::Matchers::MatchArray)
|
78
|
+
end
|
79
|
+
end
|
@@ -1,76 +1,67 @@
|
|
1
1
|
module Spec
|
2
2
|
module Matchers
|
3
|
-
class BaseOperatorMatcher
|
4
|
-
attr_reader :generated_description
|
5
|
-
|
6
|
-
def initialize(given)
|
7
|
-
@given = given
|
8
|
-
end
|
9
|
-
|
10
|
-
def ==(expected)
|
11
|
-
@expected = expected
|
12
|
-
__delegate_method_missing_to_given("==", expected)
|
13
|
-
end
|
14
3
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
4
|
+
class OperatorMatcher
|
5
|
+
class << self
|
6
|
+
def registry
|
7
|
+
@registry ||= Hash.new {|h,k| h[k] = {}}
|
8
|
+
end
|
19
9
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
10
|
+
def register(klass, operator, matcher)
|
11
|
+
registry[klass][operator] = matcher
|
12
|
+
end
|
24
13
|
|
25
|
-
|
26
|
-
|
27
|
-
|
14
|
+
def get(klass, operator)
|
15
|
+
registry[klass][operator]
|
16
|
+
end
|
28
17
|
end
|
29
18
|
|
30
|
-
def
|
31
|
-
@
|
32
|
-
__delegate_method_missing_to_given(">=", expected)
|
19
|
+
def initialize(actual)
|
20
|
+
@actual = actual
|
33
21
|
end
|
34
22
|
|
35
|
-
def
|
36
|
-
|
37
|
-
|
23
|
+
def self.use_custom_matcher_or_delegate(operator)
|
24
|
+
define_method(operator) do |expected|
|
25
|
+
if matcher = OperatorMatcher.get(@actual.class, operator)
|
26
|
+
@actual.send(::Spec::Matchers.last_should, matcher.new(expected))
|
27
|
+
else
|
28
|
+
::Spec::Matchers.last_matcher = self
|
29
|
+
@operator, @expected = operator, expected
|
30
|
+
__delegate_operator(@actual, operator, expected)
|
31
|
+
end
|
32
|
+
end
|
38
33
|
end
|
39
34
|
|
40
|
-
|
41
|
-
|
42
|
-
__delegate_method_missing_to_given("<=", expected)
|
35
|
+
['==', '===', '=~', '>', '>=', '<', '<='].each do |operator|
|
36
|
+
use_custom_matcher_or_delegate operator
|
43
37
|
end
|
44
38
|
|
45
39
|
def fail_with_message(message)
|
46
|
-
Spec::Expectations.fail_with(message, @expected, @
|
40
|
+
Spec::Expectations.fail_with(message, @expected, @actual)
|
47
41
|
end
|
48
|
-
|
42
|
+
|
49
43
|
def description
|
50
44
|
"#{@operator} #{@expected.inspect}"
|
51
45
|
end
|
52
46
|
|
53
47
|
end
|
54
48
|
|
55
|
-
class PositiveOperatorMatcher <
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
49
|
+
class PositiveOperatorMatcher < OperatorMatcher #:nodoc:
|
50
|
+
def __delegate_operator(actual, operator, expected)
|
51
|
+
return true if actual.__send__(operator, expected)
|
52
|
+
if ['==','===', '=~'].include?(operator)
|
53
|
+
fail_with_message("expected: #{expected.inspect},\n got: #{actual.inspect} (using #{operator})")
|
54
|
+
else
|
55
|
+
fail_with_message("expected: #{operator} #{expected.inspect},\n got: #{operator.gsub(/./, ' ')} #{actual.inspect}")
|
56
|
+
end
|
63
57
|
end
|
64
58
|
|
65
59
|
end
|
66
60
|
|
67
|
-
class NegativeOperatorMatcher <
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
::Spec::Matchers.last_matcher = self
|
72
|
-
return true unless @given.__send__(operator, expected)
|
73
|
-
return fail_with_message("expected not: #{operator} #{expected.inspect},\n got: #{operator.gsub(/./, ' ')} #{@given.inspect}")
|
61
|
+
class NegativeOperatorMatcher < OperatorMatcher #:nodoc:
|
62
|
+
def __delegate_operator(actual, operator, expected)
|
63
|
+
return true unless actual.__send__(operator, expected)
|
64
|
+
return fail_with_message("expected not: #{operator} #{expected.inspect},\n got: #{operator.gsub(/./, ' ')} #{actual.inspect}")
|
74
65
|
end
|
75
66
|
|
76
67
|
end
|
@@ -47,20 +47,16 @@ module Spec
|
|
47
47
|
def verify_message
|
48
48
|
case @expected_message
|
49
49
|
when nil
|
50
|
-
|
50
|
+
true
|
51
51
|
when Regexp
|
52
|
-
|
52
|
+
@expected_message =~ @given_error.message
|
53
53
|
else
|
54
|
-
|
54
|
+
@expected_message == @given_error.message
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
58
|
def failure_message
|
59
|
-
|
60
|
-
return @given_error.message
|
61
|
-
else
|
62
|
-
return "expected #{expected_error}#{given_error}"
|
63
|
-
end
|
59
|
+
@eval_block ? @given_error.message : "expected #{expected_error}#{given_error}"
|
64
60
|
end
|
65
61
|
|
66
62
|
def negative_failure_message
|
@@ -4,29 +4,54 @@ module Spec
|
|
4
4
|
class RespondTo #:nodoc:
|
5
5
|
def initialize(*names)
|
6
6
|
@names = names
|
7
|
+
@expected_arity = nil
|
7
8
|
@names_not_responded_to = []
|
8
9
|
end
|
9
10
|
|
10
|
-
def matches?(
|
11
|
-
@
|
11
|
+
def matches?(actual)
|
12
|
+
@actual = actual
|
12
13
|
@names.each do |name|
|
13
|
-
unless
|
14
|
-
@names_not_responded_to << name
|
15
|
-
end
|
14
|
+
@names_not_responded_to << name unless actual.respond_to?(name) && matches_arity?(actual, name)
|
16
15
|
end
|
17
16
|
return @names_not_responded_to.empty?
|
18
17
|
end
|
19
18
|
|
20
19
|
def failure_message
|
21
|
-
"expected #{@
|
20
|
+
"expected #{@actual.inspect} to respond to #{@names_not_responded_to.collect {|name| name.inspect }.join(', ')}#{with_arity}"
|
22
21
|
end
|
23
22
|
|
24
23
|
def negative_failure_message
|
25
|
-
"expected #{@
|
24
|
+
"expected #{@actual.inspect} not to respond to #{@names.collect {|name| name.inspect }.join(', ')}"
|
26
25
|
end
|
27
26
|
|
28
27
|
def description
|
29
|
-
|
28
|
+
# Ruby 1.9 returns the same thing for array.to_s as array.inspect, so just use array.inspect here
|
29
|
+
"respond to #{pp_names}#{with_arity}"
|
30
|
+
end
|
31
|
+
|
32
|
+
def with(n)
|
33
|
+
@expected_arity = n
|
34
|
+
self
|
35
|
+
end
|
36
|
+
|
37
|
+
def argument
|
38
|
+
self
|
39
|
+
end
|
40
|
+
alias :arguments :argument
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def matches_arity?(actual, name)
|
45
|
+
@expected_arity.nil?? true : @expected_arity == actual.method(name).arity
|
46
|
+
end
|
47
|
+
|
48
|
+
def with_arity
|
49
|
+
@expected_arity.nil?? "" :
|
50
|
+
" with #{@expected_arity} argument#{@expected_arity == 1 ? '' : 's'}"
|
51
|
+
end
|
52
|
+
|
53
|
+
def pp_names
|
54
|
+
@names.length == 1 ? "##{@names.first}" : @names.inspect
|
30
55
|
end
|
31
56
|
end
|
32
57
|
|