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
@@ -59,11 +59,11 @@ module Spec
|
|
59
59
|
describe "Nested Example Groups" do
|
60
60
|
describe "description options", :other_options => "other options" do
|
61
61
|
it "should have a spec_path" do
|
62
|
-
self.class.
|
62
|
+
self.class.options[:spec_path].should match(/#{__FILE__}/)
|
63
63
|
end
|
64
64
|
|
65
65
|
it "should pass other options" do
|
66
|
-
self.class.
|
66
|
+
self.class.options[:other_options].should == "other options"
|
67
67
|
end
|
68
68
|
end
|
69
69
|
end
|
@@ -2,57 +2,82 @@ module Spec
|
|
2
2
|
module Example
|
3
3
|
describe Pending do
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
lambda {
|
21
|
-
pending "TODO" do
|
22
|
-
m = mock('thing')
|
23
|
-
m.should_receive(:foo)
|
24
|
-
m.rspec_verify
|
5
|
+
context "when no block is supplied" do
|
6
|
+
it "raises an ExamplePendingError if no block is supplied" do
|
7
|
+
lambda {
|
8
|
+
pending "TODO"
|
9
|
+
}.should raise_error(ExamplePendingError, /TODO/)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "reports the file and line number" do
|
13
|
+
file = __FILE__
|
14
|
+
line_number = __LINE__ + 2
|
15
|
+
begin
|
16
|
+
pending("TODO")
|
17
|
+
rescue => error
|
18
|
+
ensure
|
19
|
+
error.pending_caller.should =~ /^#{file}:#{line_number}/
|
25
20
|
end
|
26
|
-
|
21
|
+
end
|
27
22
|
end
|
28
23
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
24
|
+
context "when the supplied block fails" do
|
25
|
+
it "raises an ExamplePendingError if a supplied block fails as expected" do
|
26
|
+
lambda {
|
27
|
+
pending "TODO" do
|
28
|
+
raise "oops"
|
29
|
+
end
|
30
|
+
}.should raise_error(ExamplePendingError, /TODO/)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "reports the file and line number" do
|
34
|
+
file = __FILE__
|
35
|
+
line_number = __LINE__ + 2
|
36
|
+
begin
|
37
|
+
pending do
|
38
|
+
raise
|
39
|
+
end
|
40
|
+
rescue => error
|
41
|
+
ensure
|
42
|
+
error.pending_caller.should =~ /#{file}:#{line_number}/
|
33
43
|
end
|
34
|
-
|
44
|
+
end
|
35
45
|
end
|
36
46
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
47
|
+
context "when the supplied block fails with a mock" do
|
48
|
+
it "raises an ExamplePendingError if a supplied block fails as expected with a mock" do
|
49
|
+
lambda {
|
50
|
+
pending "TODO" do
|
51
|
+
m = mock("thing")
|
52
|
+
m.should_receive(:foo)
|
53
|
+
m.rspec_verify
|
54
|
+
end
|
55
|
+
}.should raise_error(ExamplePendingError, /TODO/)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "reports the file and line number" do
|
59
|
+
file = __FILE__
|
60
|
+
line_number = __LINE__ + 2
|
61
|
+
begin
|
62
|
+
pending do
|
63
|
+
m = mock("thing")
|
64
|
+
m.should_receive(:foo)
|
65
|
+
m.rspec_verify
|
66
|
+
end
|
67
|
+
rescue => error
|
68
|
+
ensure
|
69
|
+
error.pending_caller.should =~ /#{file}:#{line_number}/
|
43
70
|
end
|
44
|
-
rescue => error
|
45
|
-
error.pending_caller.should == "#{file}:#{line_number}"
|
46
71
|
end
|
47
72
|
end
|
48
73
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
74
|
+
context "when the supplied block passes" do
|
75
|
+
it "raises a PendingExampleFixedError" do
|
76
|
+
lambda {
|
77
|
+
pending "TODO" do
|
78
|
+
# success!
|
79
|
+
end
|
80
|
+
}.should raise_error(PendingExampleFixedError, /TODO/)
|
56
81
|
end
|
57
82
|
end
|
58
83
|
end
|
@@ -8,7 +8,7 @@ module Spec
|
|
8
8
|
before(:each) do
|
9
9
|
@formatter = Spec::Mocks::Mock.new("formatter", :null_object => true)
|
10
10
|
options.formatters << formatter
|
11
|
-
@example_group = Class.new(
|
11
|
+
@example_group = Class.new(ExampleGroupDouble).describe("example_group")
|
12
12
|
class << example_group
|
13
13
|
public :include
|
14
14
|
end
|
@@ -22,7 +22,7 @@ module Spec
|
|
22
22
|
|
23
23
|
describe "#register" do
|
24
24
|
it "creates a new shared example group with the submitted args" do
|
25
|
-
block = lambda {}
|
25
|
+
block = lambda {|a|}
|
26
26
|
group = SharedExampleGroup.new("shared group") do end
|
27
27
|
Spec::Example::SharedExampleGroup.should_receive(:new).with("share me", &block).and_return(group)
|
28
28
|
Spec::Example::SharedExampleGroup.register("share me", &block)
|
@@ -130,12 +130,12 @@ module Spec
|
|
130
130
|
end
|
131
131
|
|
132
132
|
it "adds examples to current example_group using it_should_behave_like with a module" do
|
133
|
-
AllThings = describe "all things", :shared => true do
|
133
|
+
::AllThings = describe "all things", :shared => true do
|
134
134
|
it "should do stuff" do end
|
135
135
|
end
|
136
136
|
|
137
137
|
example_group = describe "one thing" do
|
138
|
-
it_should_behave_like AllThings
|
138
|
+
it_should_behave_like ::AllThings
|
139
139
|
end
|
140
140
|
|
141
141
|
example_group.number_of_examples.should == 1
|
@@ -50,25 +50,52 @@ module Spec
|
|
50
50
|
module Expectations
|
51
51
|
describe ExpectationMatcherHandler do
|
52
52
|
describe "#handle_matcher" do
|
53
|
-
it "
|
53
|
+
it "asks the matcher if it matches" do
|
54
54
|
matcher = mock("matcher")
|
55
55
|
actual = Object.new
|
56
56
|
matcher.should_receive(:matches?).with(actual).and_return(true)
|
57
57
|
Spec::Expectations::ExpectationMatcherHandler.handle_matcher(actual, matcher)
|
58
58
|
end
|
59
59
|
|
60
|
-
it "
|
60
|
+
it "returns the match value" do
|
61
61
|
matcher = mock("matcher")
|
62
62
|
actual = Object.new
|
63
63
|
matcher.should_receive(:matches?).with(actual).and_return(:this_value)
|
64
64
|
Spec::Expectations::ExpectationMatcherHandler.handle_matcher(actual, matcher).should == :this_value
|
65
65
|
end
|
66
|
+
|
67
|
+
it "calls failure_message_for_should if the matcher implements it" do
|
68
|
+
matcher = mock("matcher", :failure_message_for_should => "message", :matches? => false)
|
69
|
+
actual = Object.new
|
70
|
+
|
71
|
+
::Spec::Expectations.should_receive(:fail_with).with("message")
|
72
|
+
|
73
|
+
Spec::Expectations::ExpectationMatcherHandler.handle_matcher(actual, matcher)
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
it "calls failure_message if the matcher does not implement failure_message_for_should" do
|
78
|
+
matcher = mock("matcher", :failure_message => "message", :matches? => false)
|
79
|
+
actual = Object.new
|
80
|
+
|
81
|
+
::Spec::Expectations.should_receive(:fail_with).with("message")
|
82
|
+
|
83
|
+
Spec::Expectations::ExpectationMatcherHandler.handle_matcher(actual, matcher)
|
84
|
+
|
85
|
+
end
|
66
86
|
end
|
67
87
|
end
|
68
88
|
|
69
89
|
describe NegativeExpectationMatcherHandler do
|
70
90
|
describe "#handle_matcher" do
|
71
|
-
it "
|
91
|
+
it "asks the matcher if it doesn't match when the matcher responds to #does_not_match?" do
|
92
|
+
matcher = mock("matcher", :does_not_match? => true, :negative_failure_message => nil)
|
93
|
+
actual = Object.new
|
94
|
+
matcher.should_receive(:does_not_match?).with(actual).and_return(true)
|
95
|
+
Spec::Expectations::NegativeExpectationMatcherHandler.handle_matcher(actual, matcher)
|
96
|
+
end
|
97
|
+
|
98
|
+
it "asks the matcher if it matches when the matcher doesn't respond to #does_not_match?" do
|
72
99
|
matcher = mock("matcher")
|
73
100
|
actual = Object.new
|
74
101
|
matcher.stub!(:negative_failure_message)
|
@@ -76,13 +103,34 @@ module Spec
|
|
76
103
|
Spec::Expectations::NegativeExpectationMatcherHandler.handle_matcher(actual, matcher)
|
77
104
|
end
|
78
105
|
|
79
|
-
it "
|
106
|
+
it "returns the match value" do
|
80
107
|
matcher = mock("matcher")
|
81
108
|
actual = Object.new
|
82
109
|
matcher.should_receive(:matches?).with(actual).and_return(false)
|
83
110
|
matcher.stub!(:negative_failure_message).and_return("ignore")
|
84
111
|
Spec::Expectations::NegativeExpectationMatcherHandler.handle_matcher(actual, matcher).should be_false
|
85
112
|
end
|
113
|
+
|
114
|
+
|
115
|
+
it "calls failure_message_for_should_not if the matcher implements it" do
|
116
|
+
matcher = mock("matcher", :failure_message_for_should_not => "message", :matches? => true)
|
117
|
+
actual = Object.new
|
118
|
+
|
119
|
+
::Spec::Expectations.should_receive(:fail_with).with("message")
|
120
|
+
|
121
|
+
Spec::Expectations::NegativeExpectationMatcherHandler.handle_matcher(actual, matcher)
|
122
|
+
|
123
|
+
end
|
124
|
+
|
125
|
+
it "calls negative_failure_message if the matcher does not implement failure_message_for_should_not" do
|
126
|
+
matcher = mock("matcher", :negative_failure_message => "message", :matches? => true)
|
127
|
+
actual = Object.new
|
128
|
+
|
129
|
+
::Spec::Expectations.should_receive(:fail_with).with("message")
|
130
|
+
|
131
|
+
Spec::Expectations::NegativeExpectationMatcherHandler.handle_matcher(actual, matcher)
|
132
|
+
|
133
|
+
end
|
86
134
|
end
|
87
135
|
end
|
88
136
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
rspec_lib = File.dirname(__FILE__) + "/../../../../../../lib"
|
2
2
|
$:.unshift rspec_lib unless $:.include?(rspec_lib)
|
3
|
-
require '
|
4
|
-
require 'spec'
|
3
|
+
require 'spec/autorun'
|
4
|
+
require 'spec/test/unit'
|
5
5
|
|
6
6
|
describe "example group with failures" do
|
7
7
|
it "should fail" do
|
@@ -1,7 +1,7 @@
|
|
1
1
|
rspec_lib = File.dirname(__FILE__) + "/../../../../../../lib"
|
2
2
|
$:.unshift rspec_lib unless $:.include?(rspec_lib)
|
3
|
-
require '
|
4
|
-
require 'spec'
|
3
|
+
require 'spec/autorun'
|
4
|
+
require 'spec/test/unit'
|
5
5
|
|
6
6
|
describe "example group with passing examples" do
|
7
7
|
it "should pass" do
|
@@ -1,7 +1,7 @@
|
|
1
1
|
rspec_lib = File.dirname(__FILE__) + "/../../../../../../lib"
|
2
2
|
$:.unshift rspec_lib unless $:.include?(rspec_lib)
|
3
|
-
require '
|
4
|
-
require 'spec'
|
3
|
+
require 'spec/autorun'
|
4
|
+
require 'spec/test/unit'
|
5
5
|
|
6
6
|
describe "example group with errors" do
|
7
7
|
it "should raise errors" do
|
@@ -1,7 +1,7 @@
|
|
1
1
|
rspec_lib = File.dirname(__FILE__) + "/../../../../../../lib"
|
2
2
|
$:.unshift rspec_lib unless $:.include?(rspec_lib)
|
3
|
-
require '
|
4
|
-
require 'spec'
|
3
|
+
require 'spec/autorun'
|
4
|
+
require 'spec/test/unit'
|
5
5
|
|
6
6
|
class TestCaseThatFails < Test::Unit::TestCase
|
7
7
|
def test_that_fails
|
@@ -1,7 +1,7 @@
|
|
1
1
|
rspec_lib = File.dirname(__FILE__) + "/../../../../../../lib"
|
2
2
|
$:.unshift rspec_lib unless $:.include?(rspec_lib)
|
3
|
-
require '
|
4
|
-
require 'spec'
|
3
|
+
require 'spec/autorun'
|
4
|
+
require 'spec/test/unit'
|
5
5
|
|
6
6
|
class TestCaseThatPasses < Test::Unit::TestCase
|
7
7
|
def test_that_passes
|
@@ -1,7 +1,7 @@
|
|
1
1
|
rspec_lib = File.dirname(__FILE__) + "/../../../../../../lib"
|
2
2
|
$:.unshift rspec_lib unless $:.include?(rspec_lib)
|
3
|
-
require '
|
4
|
-
require 'spec'
|
3
|
+
require 'spec/autorun'
|
4
|
+
require 'spec/test/unit'
|
5
5
|
|
6
6
|
class TestCaseWithErrors < Test::Unit::TestCase
|
7
7
|
def test_with_error
|
@@ -29,7 +29,7 @@ module Spec
|
|
29
29
|
#when
|
30
30
|
matcher.matches?(5.51)
|
31
31
|
#then
|
32
|
-
matcher.
|
32
|
+
matcher.failure_message_for_should.should == "expected 5.0 +/- (< 0.5), got 5.51"
|
33
33
|
end
|
34
34
|
it "should describe itself" do
|
35
35
|
matcher = be_close(5.0, 0.5)
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper.rb'
|
2
|
+
|
3
|
+
module Spec
|
4
|
+
module Matchers
|
5
|
+
[:be_instance_of, :be_an_instance_of].each do |method|
|
6
|
+
describe "#{method}" do
|
7
|
+
it "passes if object is instance of given class" do
|
8
|
+
5.should send(method, Fixnum)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "failse if object is instance of subclass of expected class" do
|
12
|
+
lambda { 5.should send(method, Numeric) }.should fail_with(%Q{expected instance of Numeric, got 5})
|
13
|
+
end
|
14
|
+
|
15
|
+
it "fails with failure message unless object is kind of given class" do
|
16
|
+
lambda { "foo".should send(method, Array) }.should fail_with(%Q{expected instance of Array, got "foo"})
|
17
|
+
end
|
18
|
+
|
19
|
+
it "fails with negative failure message if object is kind of given class" do
|
20
|
+
lambda { "foo".should_not send(method, String) }.should fail_with(%Q{expected "foo" not to be an instance of String})
|
21
|
+
end
|
22
|
+
|
23
|
+
it "provides a description" do
|
24
|
+
Spec::Matchers::BeInstanceOf.new(Class).description.should == "be an instance of Class"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper.rb'
|
2
|
+
|
3
|
+
module Spec
|
4
|
+
module Matchers
|
5
|
+
[:be_kind_of, :be_a_kind_of].each do |method|
|
6
|
+
describe "#{method}" do
|
7
|
+
it "passes if object is instance of given class" do
|
8
|
+
5.should send(method, Fixnum)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "passes if object is instance of subclass of expected class" do
|
12
|
+
5.should send(method, Numeric)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "fails with failure message unless object is kind of given class" do
|
16
|
+
lambda { "foo".should send(method, Array) }.should fail_with(%Q{expected kind of Array, got "foo"})
|
17
|
+
end
|
18
|
+
|
19
|
+
it "fails with negative failure message if object is kind of given class" do
|
20
|
+
lambda { "foo".should_not send(method, String) }.should fail_with(%Q{expected "foo" not to be a kind of String})
|
21
|
+
end
|
22
|
+
|
23
|
+
it "provides a description" do
|
24
|
+
Spec::Matchers::BeKindOf.new(Class).description.should == "be a kind of Class"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -20,6 +20,10 @@ describe "should change(actual, message)" do
|
|
20
20
|
lambda {}.should change(@instance, :some_value)
|
21
21
|
end.should fail_with("some_value should have changed, but is still 5")
|
22
22
|
end
|
23
|
+
|
24
|
+
it "provides a #description" do
|
25
|
+
change(@instance, :some_value).description.should == "change #some_value"
|
26
|
+
end
|
23
27
|
end
|
24
28
|
|
25
29
|
describe "should_not change(actual, message)" do
|
@@ -60,6 +64,10 @@ describe "should change { block }" do
|
|
60
64
|
lambda {}.should change do; end
|
61
65
|
end.should raise_error(Spec::Matchers::MatcherError, /block passed to should or should_not/)
|
62
66
|
end
|
67
|
+
|
68
|
+
it "provides a #description" do
|
69
|
+
change { @instance.some_value }.description.should == "change #result"
|
70
|
+
end
|
63
71
|
end
|
64
72
|
|
65
73
|
describe "should_not change { block }" do
|
@@ -299,6 +307,18 @@ describe "should change(actual, message).from(old).to(new)" do
|
|
299
307
|
it "should pass when #from comes before #to" do
|
300
308
|
lambda { @instance.some_value = "cat" }.should change(@instance, :some_value).from("string").to("cat")
|
301
309
|
end
|
310
|
+
|
311
|
+
it "should show the correct messaging when #after and #to are different" do
|
312
|
+
lambda do
|
313
|
+
lambda { @instance.some_value = "cat" }.should change(@instance, :some_value).from("string").to("dog")
|
314
|
+
end.should fail_with("some_value should have been changed to \"dog\", but is now \"cat\"")
|
315
|
+
end
|
316
|
+
|
317
|
+
it "should show the correct messaging when #before and #from are different" do
|
318
|
+
lambda do
|
319
|
+
lambda { @instance.some_value = "cat" }.should change(@instance, :some_value).from("not_string").to("cat")
|
320
|
+
end.should fail_with("some_value should have initially been \"not_string\", but was \"string\"")
|
321
|
+
end
|
302
322
|
end
|
303
323
|
|
304
324
|
describe "should change{ block }.from(old).to(new)" do
|