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
data/lib/spec/matchers/be.rb
CHANGED
@@ -3,137 +3,115 @@ module Spec
|
|
3
3
|
|
4
4
|
class Be #:nodoc:
|
5
5
|
def initialize(*args)
|
6
|
-
|
7
|
-
@expected = :satisfy_if
|
8
|
-
else
|
9
|
-
@expected = parse_expected(args.shift)
|
10
|
-
end
|
6
|
+
@expected = args.empty? ? true : set_expected(args.shift)
|
11
7
|
@args = args
|
12
|
-
@comparison = ""
|
13
8
|
end
|
14
9
|
|
15
|
-
def matches?(
|
16
|
-
@
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
10
|
+
def matches?(actual)
|
11
|
+
@actual = actual
|
12
|
+
handling_predicate? ? run_predicate_on(actual) : match_or_compare(actual)
|
13
|
+
end
|
14
|
+
|
15
|
+
def run_predicate_on(actual)
|
16
|
+
begin
|
17
|
+
return @result = actual.__send__(predicate, *@args)
|
18
|
+
rescue NameError => predicate_missing_error
|
19
|
+
"this needs to be here or rcov will not count this branch even though it's executed in a code example"
|
20
|
+
end
|
25
21
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
31
|
-
else
|
32
|
-
return match_or_compare
|
22
|
+
begin
|
23
|
+
return @result = actual.__send__(present_tense_predicate, *@args)
|
24
|
+
rescue NameError
|
25
|
+
raise predicate_missing_error
|
33
26
|
end
|
34
27
|
end
|
35
28
|
|
36
29
|
def failure_message
|
37
|
-
|
38
|
-
|
30
|
+
handling_predicate? ?
|
31
|
+
"expected #{predicate}#{args_to_s} to return true, got #{@result.inspect}" :
|
32
|
+
"expected #{@comparison_method} #{expected}, got #{@actual.inspect}".gsub(' ',' ')
|
39
33
|
end
|
40
34
|
|
41
35
|
def negative_failure_message
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
def match_or_compare
|
55
|
-
return @given ? true : false if @expected == :satisfy_if
|
56
|
-
return @given == true if @expected == :true
|
57
|
-
return @given == false if @expected == :false
|
58
|
-
return @given.nil? if @expected == :nil
|
59
|
-
return @given < @expected if @less_than
|
60
|
-
return @given <= @expected if @less_than_or_equal
|
61
|
-
return @given >= @expected if @greater_than_or_equal
|
62
|
-
return @given > @expected if @greater_than
|
63
|
-
return @given == @expected if @double_equal
|
64
|
-
return @given === @expected if @triple_equal
|
65
|
-
return @given.equal?(@expected)
|
36
|
+
if handling_predicate?
|
37
|
+
"expected #{predicate}#{args_to_s} to return false, got #{@result.inspect}"
|
38
|
+
else
|
39
|
+
message = <<-MESSAGE
|
40
|
+
'should_not be #{@comparison_method} #{expected}' not only FAILED,
|
41
|
+
it reads really poorly.
|
42
|
+
MESSAGE
|
43
|
+
|
44
|
+
raise message << ([:===,:==].include?(@comparison_method) ?
|
45
|
+
"Why don't you try expressing it without the \"be\"?" :
|
46
|
+
"Why don't you try expressing it in the positive?")
|
47
|
+
end
|
66
48
|
end
|
67
49
|
|
68
|
-
def
|
69
|
-
|
70
|
-
@double_equal = true
|
71
|
-
@comparison = "== "
|
72
|
-
@expected = expected
|
73
|
-
self
|
74
|
-
end
|
75
|
-
|
76
|
-
def ===(expected)
|
77
|
-
@prefix = "be "
|
78
|
-
@triple_equal = true
|
79
|
-
@comparison = "=== "
|
80
|
-
@expected = expected
|
81
|
-
self
|
82
|
-
end
|
83
|
-
|
84
|
-
def <(expected)
|
85
|
-
@prefix = "be "
|
86
|
-
@less_than = true
|
87
|
-
@comparison = "< "
|
88
|
-
@expected = expected
|
89
|
-
self
|
90
|
-
end
|
91
|
-
|
92
|
-
def <=(expected)
|
93
|
-
@prefix = "be "
|
94
|
-
@less_than_or_equal = true
|
95
|
-
@comparison = "<= "
|
96
|
-
@expected = expected
|
97
|
-
self
|
50
|
+
def description
|
51
|
+
"#{prefix_to_sentence}#{comparison} #{expected_to_sentence}#{args_to_sentence}".gsub(/\s+/,' ')
|
98
52
|
end
|
99
53
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
self
|
54
|
+
[:==, :<, :<=, :>=, :>, :===].each do |method|
|
55
|
+
define_method method do |expected|
|
56
|
+
compare_to(expected, :using => method)
|
57
|
+
self
|
58
|
+
end
|
106
59
|
end
|
107
60
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
61
|
+
private
|
62
|
+
def match_or_compare(actual)
|
63
|
+
case @expected
|
64
|
+
when TrueClass
|
65
|
+
@actual
|
66
|
+
else
|
67
|
+
@actual.__send__(comparison_method, @expected)
|
68
|
+
end
|
69
|
+
end
|
115
70
|
|
116
|
-
|
117
|
-
|
118
|
-
|
71
|
+
def comparison_method
|
72
|
+
@comparison_method || :equal?
|
73
|
+
end
|
74
|
+
|
75
|
+
def expected
|
76
|
+
@expected
|
77
|
+
end
|
119
78
|
|
120
|
-
|
79
|
+
def compare_to(expected, opts)
|
80
|
+
@expected, @comparison_method = expected, opts[:using]
|
81
|
+
end
|
82
|
+
|
83
|
+
def set_expected(expected)
|
84
|
+
Symbol === expected ? parse_expected(expected) : expected
|
85
|
+
end
|
86
|
+
|
121
87
|
def parse_expected(expected)
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
88
|
+
["be_an_","be_a_","be_"].each do |prefix|
|
89
|
+
handling_predicate!
|
90
|
+
if expected.starts_with?(prefix)
|
91
|
+
set_prefix(prefix)
|
92
|
+
expected = expected.to_s.sub(prefix,"")
|
93
|
+
[true, false, nil].each do |val|
|
94
|
+
return val if val.to_s == expected
|
128
95
|
end
|
96
|
+
return expected.to_sym
|
129
97
|
end
|
130
98
|
end
|
131
|
-
|
132
|
-
|
99
|
+
end
|
100
|
+
|
101
|
+
def set_prefix(prefix)
|
102
|
+
@prefix = prefix
|
103
|
+
end
|
104
|
+
|
105
|
+
def prefix
|
106
|
+
@prefix
|
107
|
+
end
|
108
|
+
|
109
|
+
def handling_predicate!
|
110
|
+
@handling_predicate = true
|
133
111
|
end
|
134
112
|
|
135
113
|
def handling_predicate?
|
136
|
-
return false if [
|
114
|
+
return false if [true, false, nil].include?(expected)
|
137
115
|
return @handling_predicate
|
138
116
|
end
|
139
117
|
|
@@ -146,21 +124,27 @@ module Spec
|
|
146
124
|
end
|
147
125
|
|
148
126
|
def args_to_s
|
149
|
-
|
150
|
-
|
151
|
-
|
127
|
+
@args.empty? ? "" : parenthesize(inspected_args.join(', '))
|
128
|
+
end
|
129
|
+
|
130
|
+
def parenthesize(string)
|
131
|
+
return "(#{string})"
|
132
|
+
end
|
133
|
+
|
134
|
+
def inspected_args
|
135
|
+
@args.collect{|a| a.inspect}
|
152
136
|
end
|
153
137
|
|
154
138
|
def comparison
|
155
|
-
@
|
139
|
+
@comparison_method.nil? ? " " : "be #{@comparison_method.to_s} "
|
156
140
|
end
|
157
141
|
|
158
142
|
def expected_to_sentence
|
159
|
-
split_words(
|
143
|
+
split_words(expected)
|
160
144
|
end
|
161
145
|
|
162
146
|
def prefix_to_sentence
|
163
|
-
split_words(
|
147
|
+
split_words(prefix)
|
164
148
|
end
|
165
149
|
|
166
150
|
def split_words(sym)
|
@@ -181,7 +165,6 @@ module Spec
|
|
181
165
|
end
|
182
166
|
|
183
167
|
# :call-seq:
|
184
|
-
# should be
|
185
168
|
# should be_true
|
186
169
|
# should be_false
|
187
170
|
# should be_nil
|
@@ -189,7 +172,7 @@ module Spec
|
|
189
172
|
# should_not be_nil
|
190
173
|
# should_not be_arbitrary_predicate(*args)
|
191
174
|
#
|
192
|
-
# Given true, false, or nil, will pass if
|
175
|
+
# Given true, false, or nil, will pass if actual value is
|
193
176
|
# true, false or nil (respectively). Given no args means
|
194
177
|
# the caller should satisfy an if condition (to be or not to be).
|
195
178
|
#
|
@@ -203,19 +186,23 @@ module Spec
|
|
203
186
|
#
|
204
187
|
# == Examples
|
205
188
|
#
|
206
|
-
# target.should be
|
207
189
|
# target.should be_true
|
208
190
|
# target.should be_false
|
209
191
|
# target.should be_nil
|
210
192
|
# target.should_not be_nil
|
211
193
|
#
|
212
194
|
# collection.should be_empty #passes if target.empty?
|
213
|
-
# "this string".should be_an_intance_of(String)
|
214
|
-
#
|
215
195
|
# target.should_not be_empty #passes unless target.empty?
|
216
196
|
# target.should_not be_old_enough(16) #passes unless target.old_enough?(16)
|
217
197
|
def be(*args)
|
218
198
|
Matchers::Be.new(*args)
|
219
199
|
end
|
200
|
+
|
201
|
+
# passes if target.kind_of?(klass)
|
202
|
+
def be_a(klass)
|
203
|
+
be_a_kind_of(klass)
|
204
|
+
end
|
205
|
+
|
206
|
+
alias_method :be_an, :be_a
|
220
207
|
end
|
221
208
|
end
|
@@ -1,37 +1,21 @@
|
|
1
1
|
module Spec
|
2
2
|
module Matchers
|
3
3
|
|
4
|
-
class BeClose #:nodoc:
|
5
|
-
def initialize(expected, delta)
|
6
|
-
@expected = expected
|
7
|
-
@delta = delta
|
8
|
-
end
|
9
|
-
|
10
|
-
def matches?(given)
|
11
|
-
@given = given
|
12
|
-
(@given - @expected).abs < @delta
|
13
|
-
end
|
14
|
-
|
15
|
-
def failure_message
|
16
|
-
"expected #{@expected} +/- (< #{@delta}), got #{@given}"
|
17
|
-
end
|
18
|
-
|
19
|
-
def description
|
20
|
-
"be close to #{@expected} (within +- #{@delta})"
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
4
|
# :call-seq:
|
25
5
|
# should be_close(expected, delta)
|
26
6
|
# should_not be_close(expected, delta)
|
27
7
|
#
|
28
|
-
# Passes if
|
8
|
+
# Passes if actual == expected +/- delta
|
29
9
|
#
|
30
10
|
# == Example
|
31
11
|
#
|
32
12
|
# result.should be_close(3.0, 0.5)
|
33
13
|
def be_close(expected, delta)
|
34
|
-
|
14
|
+
simple_matcher do |actual, matcher|
|
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
|
35
19
|
end
|
36
20
|
end
|
37
21
|
end
|
data/lib/spec/matchers/eql.rb
CHANGED
@@ -1,34 +1,11 @@
|
|
1
1
|
module Spec
|
2
2
|
module Matchers
|
3
3
|
|
4
|
-
class Eql #:nodoc:
|
5
|
-
def initialize(expected)
|
6
|
-
@expected = expected
|
7
|
-
end
|
8
|
-
|
9
|
-
def matches?(given)
|
10
|
-
@given = given
|
11
|
-
@given.eql?(@expected)
|
12
|
-
end
|
13
|
-
|
14
|
-
def failure_message
|
15
|
-
return "expected #{@expected.inspect}, got #{@given.inspect} (using .eql?)", @expected, @given
|
16
|
-
end
|
17
|
-
|
18
|
-
def negative_failure_message
|
19
|
-
return "expected #{@given.inspect} not to equal #{@expected.inspect} (using .eql?)", @expected, @given
|
20
|
-
end
|
21
|
-
|
22
|
-
def description
|
23
|
-
"eql #{@expected.inspect}"
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
4
|
# :call-seq:
|
28
5
|
# should eql(expected)
|
29
6
|
# should_not eql(expected)
|
30
7
|
#
|
31
|
-
# Passes if
|
8
|
+
# Passes if actual and expected are of equal value, but not necessarily the same object.
|
32
9
|
#
|
33
10
|
# See http://www.ruby-doc.org/core/classes/Object.html#M001057 for more information about equality in Ruby.
|
34
11
|
#
|
@@ -37,7 +14,12 @@ module Spec
|
|
37
14
|
# 5.should eql(5)
|
38
15
|
# 5.should_not eql(3)
|
39
16
|
def eql(expected)
|
40
|
-
|
17
|
+
simple_matcher do |actual, matcher|
|
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
|
41
23
|
end
|
42
24
|
end
|
43
25
|
end
|
data/lib/spec/matchers/equal.rb
CHANGED
@@ -1,34 +1,11 @@
|
|
1
1
|
module Spec
|
2
2
|
module Matchers
|
3
3
|
|
4
|
-
class Equal #:nodoc:
|
5
|
-
def initialize(expected)
|
6
|
-
@expected = expected
|
7
|
-
end
|
8
|
-
|
9
|
-
def matches?(given)
|
10
|
-
@given = given
|
11
|
-
@given.equal?(@expected)
|
12
|
-
end
|
13
|
-
|
14
|
-
def failure_message
|
15
|
-
return "expected #{@expected.inspect}, got #{@given.inspect} (using .equal?)", @expected, @given
|
16
|
-
end
|
17
|
-
|
18
|
-
def negative_failure_message
|
19
|
-
return "expected #{@given.inspect} not to equal #{@expected.inspect} (using .equal?)", @expected, @given
|
20
|
-
end
|
21
|
-
|
22
|
-
def description
|
23
|
-
"equal #{@expected.inspect}"
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
4
|
# :call-seq:
|
28
5
|
# should equal(expected)
|
29
6
|
# should_not equal(expected)
|
30
7
|
#
|
31
|
-
# Passes if
|
8
|
+
# Passes if actual and expected are the same object (object identity).
|
32
9
|
#
|
33
10
|
# See http://www.ruby-doc.org/core/classes/Object.html#M001057 for more information about equality in Ruby.
|
34
11
|
#
|
@@ -37,7 +14,12 @@ module Spec
|
|
37
14
|
# 5.should equal(5) #Fixnums are equal
|
38
15
|
# "5".should_not equal("5") #Strings that look the same are not the same object
|
39
16
|
def equal(expected)
|
40
|
-
|
17
|
+
simple_matcher do |actual, matcher|
|
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
|
41
23
|
end
|
42
24
|
end
|
43
25
|
end
|
data/lib/spec/matchers/exist.rb
CHANGED
@@ -1,22 +1,16 @@
|
|
1
1
|
module Spec
|
2
2
|
module Matchers
|
3
|
-
class Exist
|
4
|
-
def matches?(given)
|
5
|
-
@given = given
|
6
|
-
@given.exist?
|
7
|
-
end
|
8
|
-
def failure_message
|
9
|
-
"expected #{@given.inspect} to exist, but it doesn't."
|
10
|
-
end
|
11
|
-
def negative_failure_message
|
12
|
-
"expected #{@given.inspect} to not exist, but it does."
|
13
|
-
end
|
14
|
-
end
|
15
3
|
# :call-seq:
|
16
4
|
# should exist
|
17
5
|
# should_not exist
|
18
6
|
#
|
19
|
-
# Passes if
|
20
|
-
def exist
|
7
|
+
# Passes if actual.exist?
|
8
|
+
def exist
|
9
|
+
simple_matcher do |actual, matcher|
|
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
|
14
|
+
end
|
21
15
|
end
|
22
16
|
end
|