rspec-core 2.0.0.a1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (143) hide show
  1. data/.document +5 -0
  2. data/.gitignore +7 -0
  3. data/.treasure_map.rb +23 -0
  4. data/License.txt +22 -0
  5. data/README.markdown +9 -0
  6. data/Rakefile +76 -0
  7. data/TODO.markdown +16 -0
  8. data/VERSION +1 -0
  9. data/VERSION.yml +5 -0
  10. data/bin/rspec +12 -0
  11. data/cucumber.yml +2 -0
  12. data/example_specs/failing/README.txt +7 -0
  13. data/example_specs/failing/diffing_spec.rb +36 -0
  14. data/example_specs/failing/failing_implicit_docstrings_example.rb +19 -0
  15. data/example_specs/failing/failure_in_after.rb +10 -0
  16. data/example_specs/failing/failure_in_before.rb +10 -0
  17. data/example_specs/failing/mocking_example.rb +40 -0
  18. data/example_specs/failing/mocking_with_flexmock.rb +26 -0
  19. data/example_specs/failing/mocking_with_mocha.rb +25 -0
  20. data/example_specs/failing/mocking_with_rr.rb +27 -0
  21. data/example_specs/failing/partial_mock_example.rb +20 -0
  22. data/example_specs/failing/pending_example.rb +9 -0
  23. data/example_specs/failing/predicate_example.rb +34 -0
  24. data/example_specs/failing/raising_example.rb +47 -0
  25. data/example_specs/failing/spec_helper.rb +3 -0
  26. data/example_specs/failing/syntax_error_example.rb +7 -0
  27. data/example_specs/failing/team_spec.rb +44 -0
  28. data/example_specs/failing/timeout_behaviour.rb +7 -0
  29. data/example_specs/passing/custom_formatter.rb +12 -0
  30. data/example_specs/passing/custom_matchers.rb +54 -0
  31. data/example_specs/passing/dynamic_spec.rb +9 -0
  32. data/example_specs/passing/file_accessor.rb +19 -0
  33. data/example_specs/passing/file_accessor_spec.rb +38 -0
  34. data/example_specs/passing/filtered_formatter.rb +18 -0
  35. data/example_specs/passing/filtered_formatter_example.rb +31 -0
  36. data/example_specs/passing/greeter_spec.rb +31 -0
  37. data/example_specs/passing/helper_method_example.rb +14 -0
  38. data/example_specs/passing/implicit_docstrings_example.rb +18 -0
  39. data/example_specs/passing/io_processor.rb +8 -0
  40. data/example_specs/passing/io_processor_spec.rb +21 -0
  41. data/example_specs/passing/mocking_example.rb +27 -0
  42. data/example_specs/passing/multi_threaded_example_group_runner.rb +26 -0
  43. data/example_specs/passing/nested_classes_example.rb +36 -0
  44. data/example_specs/passing/options_example.rb +31 -0
  45. data/example_specs/passing/options_formatter.rb +20 -0
  46. data/example_specs/passing/partial_mock_example.rb +29 -0
  47. data/example_specs/passing/pending_example.rb +20 -0
  48. data/example_specs/passing/predicate_example.rb +27 -0
  49. data/example_specs/passing/shared_example_group_example.rb +81 -0
  50. data/example_specs/passing/shared_stack_examples.rb +36 -0
  51. data/example_specs/passing/simple_matcher_example.rb +31 -0
  52. data/example_specs/passing/spec_helper.rb +14 -0
  53. data/example_specs/passing/stack.rb +36 -0
  54. data/example_specs/passing/stack_spec.rb +64 -0
  55. data/example_specs/passing/stack_spec_with_nested_example_groups.rb +67 -0
  56. data/example_specs/passing/stubbing_example.rb +69 -0
  57. data/example_specs/passing/yielding_example.rb +33 -0
  58. data/example_specs/ruby1.9.compatibility/access_to_constants_spec.rb +85 -0
  59. data/features-pending/command_line/line_number_option.feature +56 -0
  60. data/features-pending/command_line/line_number_option_with_example_with_no_name.feature +22 -0
  61. data/features-pending/example_groups/example_group_with_should_methods.feature +29 -0
  62. data/features-pending/example_groups/implicit_docstrings.feature +59 -0
  63. data/features-pending/example_groups/nested_groups.feature +32 -0
  64. data/features-pending/expectations/expect_change.feature +65 -0
  65. data/features-pending/expectations/expect_error.feature +44 -0
  66. data/features-pending/extensions/custom_example_group.feature +19 -0
  67. data/features-pending/formatters/custom_formatter.feature +30 -0
  68. data/features-pending/heckle/heckle.feature +56 -0
  69. data/features-pending/interop/examples_and_tests_together.feature +80 -0
  70. data/features-pending/interop/rspec_output.feature +25 -0
  71. data/features-pending/interop/test_but_not_test_unit.feature +26 -0
  72. data/features-pending/interop/test_case_with_should_methods.feature +46 -0
  73. data/features-pending/matchers/define_diffable_matcher.feature +26 -0
  74. data/features-pending/matchers/define_matcher.feature +179 -0
  75. data/features-pending/matchers/define_matcher_with_fluent_interface.feature +27 -0
  76. data/features-pending/mocks/mix_stubs_and_mocks.feature +22 -0
  77. data/features-pending/mocks/stub_implementation.feature +26 -0
  78. data/features-pending/pending/pending_examples.feature +81 -0
  79. data/features-pending/runner/specify_line_number.feature +32 -0
  80. data/features/before_and_after_blocks/before_and_after_blocks.feature +169 -0
  81. data/features/expectations/customized_message.feature +54 -0
  82. data/features/matchers/define_matcher_outside_rspec.feature +39 -0
  83. data/features/mock_framework_integration/use_flexmock.feature +23 -0
  84. data/features/mock_framework_integration/use_mocha.feature +23 -0
  85. data/features/mock_framework_integration/use_rr.feature +23 -0
  86. data/features/mock_framework_integration/use_rspec.feature +23 -0
  87. data/features/step_definitions/running_rspec_steps.rb +35 -0
  88. data/features/subject/explicit_subject.feature +31 -0
  89. data/features/subject/implicit_subject.feature +31 -0
  90. data/features/support/env.rb +82 -0
  91. data/features/support/matchers/smart_match.rb +14 -0
  92. data/lib/rspec/autorun.rb +2 -0
  93. data/lib/rspec/core.rb +38 -0
  94. data/lib/rspec/core/backward_compatibility.rb +9 -0
  95. data/lib/rspec/core/command_line_options.rb +60 -0
  96. data/lib/rspec/core/configuration.rb +222 -0
  97. data/lib/rspec/core/deprecation.rb +47 -0
  98. data/lib/rspec/core/example.rb +113 -0
  99. data/lib/rspec/core/example_group.rb +239 -0
  100. data/lib/rspec/core/example_group_subject.rb +77 -0
  101. data/lib/rspec/core/formatters.rb +16 -0
  102. data/lib/rspec/core/formatters/base_formatter.rb +123 -0
  103. data/lib/rspec/core/formatters/base_text_formatter.rb +139 -0
  104. data/lib/rspec/core/formatters/documentation_formatter.rb +84 -0
  105. data/lib/rspec/core/formatters/progress_formatter.rb +36 -0
  106. data/lib/rspec/core/kernel_extensions.rb +15 -0
  107. data/lib/rspec/core/mocking/with_absolutely_nothing.rb +13 -0
  108. data/lib/rspec/core/mocking/with_flexmock.rb +25 -0
  109. data/lib/rspec/core/mocking/with_mocha.rb +22 -0
  110. data/lib/rspec/core/mocking/with_rr.rb +26 -0
  111. data/lib/rspec/core/mocking/with_rspec.rb +21 -0
  112. data/lib/rspec/core/rake_task.rb +88 -0
  113. data/lib/rspec/core/runner.rb +66 -0
  114. data/lib/rspec/core/shared_behaviour.rb +41 -0
  115. data/lib/rspec/core/shared_behaviour_kernel_extensions.rb +31 -0
  116. data/lib/rspec/core/version.rb +16 -0
  117. data/lib/rspec/core/world.rb +105 -0
  118. data/rspec-core.gemspec +204 -0
  119. data/script/console +8 -0
  120. data/spec/resources/example_classes.rb +67 -0
  121. data/spec/rspec/core/command_line_options_spec.rb +63 -0
  122. data/spec/rspec/core/configuration_spec.rb +171 -0
  123. data/spec/rspec/core/example_group_spec.rb +351 -0
  124. data/spec/rspec/core/example_group_subject_spec.rb +67 -0
  125. data/spec/rspec/core/example_spec.rb +67 -0
  126. data/spec/rspec/core/formatters/base_formatter_spec.rb +105 -0
  127. data/spec/rspec/core/formatters/documentation_formatter_spec.rb +5 -0
  128. data/spec/rspec/core/formatters/progress_formatter_spec.rb +29 -0
  129. data/spec/rspec/core/kernel_extensions_spec.rb +13 -0
  130. data/spec/rspec/core/mocha_spec.rb +29 -0
  131. data/spec/rspec/core/resources/a_bar.rb +0 -0
  132. data/spec/rspec/core/resources/a_foo.rb +0 -0
  133. data/spec/rspec/core/resources/a_spec.rb +1 -0
  134. data/spec/rspec/core/resources/custom_example_group_runner.rb +14 -0
  135. data/spec/rspec/core/resources/example_classes.rb +67 -0
  136. data/spec/rspec/core/resources/utf8_encoded.rb +8 -0
  137. data/spec/rspec/core/runner_spec.rb +34 -0
  138. data/spec/rspec/core/shared_behaviour_spec.rb +185 -0
  139. data/spec/rspec/core/world_spec.rb +167 -0
  140. data/spec/rspec/core_spec.rb +35 -0
  141. data/spec/ruby_forker.rb +13 -0
  142. data/spec/spec_helper.rb +72 -0
  143. metadata +219 -0
@@ -0,0 +1,44 @@
1
+ Feature: expect error
2
+
3
+ Expect a proc to change the state of some object.
4
+
5
+ Scenario: expect error
6
+ Given a file named "expect_error.rb" with:
7
+ """
8
+ describe Object, "#non_existent_message" do
9
+ it "should raise" do
10
+ expect{Object.non_existent_message}.to raise_error(NameError)
11
+ end
12
+ end
13
+
14
+ #deliberate failure
15
+ describe Object, "#public_instance_methods" do
16
+ it "should raise" do
17
+ expect{Object.public_instance_methods}.to raise_error(NameError)
18
+ end
19
+ end
20
+ """
21
+ When I run "spec expect_error.rb"
22
+ Then the stdout should match "2 examples, 1 failure"
23
+ Then the stdout should match "expected NameError but nothing was raised"
24
+
25
+ Scenario: expect no error
26
+ Given a file named "expect_no_error.rb" with:
27
+ """
28
+ describe Object, "#public_instance_methods" do
29
+ it "should not raise" do
30
+ expect{Object.public_instance_methods}.to_not raise_error(NameError)
31
+ end
32
+ end
33
+
34
+ #deliberate failure
35
+ describe Object, "#non_existent_message" do
36
+ it "should not raise" do
37
+ expect{Object.non_existent_message}.to_not raise_error(NameError)
38
+ end
39
+ end
40
+ """
41
+ When I run "spec expect_no_error.rb"
42
+ Then the stdout should match "2 examples, 1 failure"
43
+ Then the stdout should match "undefined method `non_existent_message'"
44
+
@@ -0,0 +1,19 @@
1
+ Feature: custom example group
2
+
3
+ Scenario: simple custom example group
4
+ Given a file named "custom_example_group_spec.rb" with:
5
+ """
6
+ class CustomGroup < Spec::ExampleGroup
7
+ end
8
+
9
+ Spec::Example::ExampleGroupFactory.default(CustomGroup)
10
+
11
+ describe "setting a default example group base class" do
12
+ it "should use that class by default" do
13
+ CustomGroup.should === self
14
+ end
15
+ end
16
+ """
17
+ When I run "spec custom_example_group_spec.rb"
18
+ Then the stdout should match "1 example, 0 failures"
19
+
@@ -0,0 +1,30 @@
1
+ Feature: custom formatters
2
+
3
+ In order to format output/reporting to my particular needs
4
+ As an RSpec user
5
+ I want to create my own custom output formatters
6
+
7
+ Scenario: specdoc format
8
+ Given a file named "custom_formatter.rb" with:
9
+ """
10
+ require 'spec/runner/formatter/base_formatter'
11
+ class CustomFormatter < Spec::Runner::Formatter::BaseFormatter
12
+ def initialize(options, output)
13
+ @output = output
14
+ end
15
+ def example_started(proxy)
16
+ @output << "example: " << proxy.description
17
+ end
18
+ end
19
+ """
20
+ And a file named "simple_example_spec.rb" with:
21
+ """
22
+ describe "my group" do
23
+ specify "my example" do
24
+ end
25
+ end
26
+ """
27
+
28
+ When I run "spec simple_example_spec.rb --require custom_formatter.rb --format CustomFormatter"
29
+ Then the exit code should be 0
30
+ And the stdout should match "example: my example"
@@ -0,0 +1,56 @@
1
+ Feature: heckle a class
2
+
3
+ As an RSpec user who wants to verify that
4
+ my specs cover what I think it covers
5
+ I want to heckle a class
6
+
7
+ Scenario: Heckle finds problems
8
+ Given a file named "heckle_fail_spec.rb" with:
9
+ """
10
+ class Thing
11
+ def a_or_b
12
+ if true
13
+ "a"
14
+ else
15
+ "b"
16
+ end
17
+ end
18
+ end
19
+
20
+ describe Thing do
21
+ it "returns a for true" do
22
+ Thing.new.a_or_b.should == "a"
23
+ end
24
+ end
25
+ """
26
+ When I run "spec heckle_fail_spec.rb --heckle Thing"
27
+ Then the stdout should match "The following mutations didn't cause test failures:"
28
+ But the stdout should not match "FAILED"
29
+
30
+ Scenario: Heckle does not find a problem
31
+ Given a file named "heckle_success_spec.rb" with:
32
+ """
33
+ class Thing
34
+ def a_or_b(key)
35
+ if key
36
+ "a"
37
+ else
38
+ "b"
39
+ end
40
+ end
41
+ end
42
+
43
+ describe Thing do
44
+ it "returns a for true" do
45
+ Thing.new.a_or_b(true).should == "a"
46
+ end
47
+
48
+ it "returns b for false" do
49
+ Thing.new.a_or_b(false).should == "b"
50
+ end
51
+ end
52
+ """
53
+ When I run "spec heckle_success_spec.rb --heckle Thing"
54
+ Then the stdout should match "No mutants survived"
55
+ But the stdout should not match "FAILED"
56
+
@@ -0,0 +1,80 @@
1
+ Feature: Spec and test together
2
+
3
+ As an RSpec adopter with existing Test::Unit tests
4
+ I want to run a few specs alongside my existing Test::Unit tests
5
+ So that I can experience a smooth, gradual migration path
6
+
7
+ Scenario Outline: Run specs and tests together
8
+ Given a file named "spec_and_test_together.rb" with:
9
+ """
10
+ require 'rspec/autorun'
11
+ require 'spec/test/unit'
12
+
13
+ describe "An Example" do
14
+ it "should pass with assert" do
15
+ assert true
16
+ end
17
+
18
+ it "should fail with assert" do
19
+ assert false
20
+ end
21
+
22
+ it "should pass with should" do
23
+ 1.should == 1
24
+ end
25
+
26
+ it "should fail with should" do
27
+ 1.should == 2
28
+ end
29
+ end
30
+
31
+ class ATest < Test::Unit::TestCase
32
+ def test_should_pass_with_assert
33
+ assert true
34
+ end
35
+
36
+ def test_should_fail_with_assert
37
+ assert false
38
+ end
39
+
40
+ def test_should_pass_with_should
41
+ 1.should == 1
42
+ end
43
+
44
+ def test_should_fail_with_should
45
+ 1.should == 2
46
+ end
47
+
48
+ def setup
49
+ @from_setup ||= 3
50
+ @from_setup += 1
51
+ end
52
+
53
+ def test_should_fail_with_setup_method_variable
54
+ @from_setup.should == 40
55
+ end
56
+
57
+ before do
58
+ @from_before = @from_setup + 1
59
+ end
60
+
61
+ def test_should_fail_with_before_block_variable
62
+ @from_before.should == 50
63
+ end
64
+ end
65
+ """
66
+
67
+ When I run "<Command> spec_and_test_together.rb -fs"
68
+
69
+ Then the exit code should be 256
70
+ And the stdout should match "ATest"
71
+ And the stdout should match "Test::Unit::AssertionFailedError in 'An Example should fail with assert'"
72
+ And the stdout should match "'An Example should fail with should' FAILED"
73
+ And the stdout should match "10 examples, 6 failures"
74
+ And the stdout should match /expected: 40,\s*got: 4/m
75
+ And the stdout should match /expected: 50,\s*got: 5/m
76
+
77
+ Scenarios: run with ruby and spec
78
+ | Command |
79
+ | ruby |
80
+ | spec |
@@ -0,0 +1,25 @@
1
+ Feature: spec output
2
+
3
+ When running in interop mode with test/unit, RSpec will output
4
+ the RSpec summary, but not the test/unit summary.
5
+
6
+ Scenario Outline: Interop mode with test/unit
7
+ Given a file named "simple_spec.rb" with:
8
+ """
9
+ require 'rspec/autorun'
10
+
11
+ describe "Running an Example" do
12
+ it "should not output twice" do
13
+ true.should be_true
14
+ end
15
+ end
16
+ """
17
+ When I run "<Command> simple_spec.rb"
18
+ Then the exit code should be 0
19
+ And the stdout should not match /\d+ tests, \d+ assertions, \d+ failures, \d+ errors/m
20
+ And the stdout should match "1 example, 0 failures"
21
+
22
+ Scenarios: Run with ruby and rspec/commands
23
+ | Command |
24
+ | ruby |
25
+ | cmdline.rb |
@@ -0,0 +1,26 @@
1
+ Story: Test is defined, but not Test::Unit
2
+
3
+ As an RSpec user who has my own library named Test (but not Test::Unit)
4
+ I want to run examples without getting Test::Unit NameErrors
5
+
6
+ Scenario Outline: Spec including Test const but not Test::Unit
7
+ Given a file named "spec_including_test_but_not_unit.rb" with:
8
+ """
9
+ require 'rspec/autorun'
10
+
11
+ module Test
12
+ end
13
+
14
+ describe "description" do
15
+ it "should description" do
16
+ 1.should == 1
17
+ end
18
+ end
19
+ """
20
+ When I run "<Command> spec_including_test_but_not_unit.rb"
21
+ Then the stderr should not match "Test::Unit"
22
+
23
+ Scenarios: Run with ruby and spec
24
+ | Command |
25
+ | ruby |
26
+ | spec |
@@ -0,0 +1,46 @@
1
+ Story: Test::Unit::TestCase extended by rspec with should methods
2
+
3
+ As an RSpec adopter with existing Test::Unit tests
4
+ I want to use should_* methods in a Test::Unit::TestCase
5
+ So that I use RSpec with classes and methods that look more like RSpec examples
6
+
7
+ Scenario Outline: TestCase with should methods
8
+ Given a file named "test_case_with_should_methods.rb" with:
9
+ """
10
+ require 'rspec/autorun'
11
+ require 'spec/test/unit'
12
+
13
+ class MyTest < Test::Unit::TestCase
14
+ def should_pass_with_should
15
+ 1.should == 1
16
+ end
17
+
18
+ def should_fail_with_should
19
+ 1.should == 2
20
+ end
21
+
22
+ def should_pass_with_assert
23
+ assert true
24
+ end
25
+
26
+ def should_fail_with_assert
27
+ assert false
28
+ end
29
+
30
+ def test
31
+ raise "This is not a real test"
32
+ end
33
+
34
+ def test_ify
35
+ raise "This is a real test"
36
+ end
37
+ end
38
+ """
39
+ When I run "<Command> test_case_with_should_methods.rb"
40
+ Then the exit code should be 256
41
+ And the stdout should match "5 examples, 3 failures"
42
+
43
+ Scenarios: Run with ruby and spec
44
+ | Command |
45
+ | ruby |
46
+ | spec |
@@ -0,0 +1,26 @@
1
+ Feature: define diffable matcher
2
+
3
+ When a matcher is defined as diffable, and the --diff
4
+ flag is set, the output will include a diff of the submitted
5
+ objects.
6
+
7
+ Scenario: define a diffable matcher
8
+ Given a file named "diffable_matcher_spec.rb" with:
9
+ """
10
+ Rspec::Matchers.define :be_just_like do |expected|
11
+ match do |actual|
12
+ actual == expected
13
+ end
14
+
15
+ diffable
16
+ end
17
+
18
+ describe "this" do
19
+ it {should be_just_like("that")}
20
+ end
21
+ """
22
+ When I run "spec diffable_matcher_spec.rb --diff"
23
+ Then the exit code should be 256
24
+
25
+ And the stdout should match "should be just like \"that\""
26
+ And the stdout should match "Diff:\n@@ -1,2 +1,2 @@\n-that\n+this"
@@ -0,0 +1,179 @@
1
+ Feature: define matcher
2
+
3
+ In order to express my domain clearly in my code examples
4
+ As an RSpec user
5
+ I want a shortcut to define custom matchers
6
+
7
+ Scenario: define a matcher with default messages
8
+ Given a file named "matcher_with_default_message_spec.rb" with:
9
+ """
10
+ Rspec::Matchers.define :be_a_multiple_of do |expected|
11
+ match do |actual|
12
+ actual % expected == 0
13
+ end
14
+ end
15
+
16
+ describe 9 do
17
+ it {should be_a_multiple_of(3)}
18
+ end
19
+
20
+ describe 9 do
21
+ it {should_not be_a_multiple_of(4)}
22
+ end
23
+
24
+ # fail intentionally to generate expected output
25
+ describe 9 do
26
+ it {should be_a_multiple_of(4)}
27
+ end
28
+
29
+ # fail intentionally to generate expected output
30
+ describe 9 do
31
+ it {should_not be_a_multiple_of(3)}
32
+ end
33
+
34
+ """
35
+ When I run "spec matcher_with_default_message_spec.rb --format specdoc"
36
+ Then the exit code should be 256
37
+
38
+ And the stdout should match "should be a multiple of 3"
39
+ And the stdout should match "should not be a multiple of 4"
40
+ And the stdout should match "should be a multiple of 4 (FAILED - 1)"
41
+ And the stdout should match "should not be a multiple of 3 (FAILED - 2)"
42
+
43
+ And the stdout should match "4 examples, 2 failures"
44
+ And the stdout should match "expected 9 to be a multiple of 4"
45
+ And the stdout should match "expected 9 not to be a multiple of 3"
46
+
47
+ Scenario: overriding the failure_message_for_should
48
+ Given a file named "matcher_with_failure_message_spec.rb" with:
49
+ """
50
+ Rspec::Matchers.define :be_a_multiple_of do |expected|
51
+ match do |actual|
52
+ actual % expected == 0
53
+ end
54
+ failure_message_for_should do |actual|
55
+ "expected that #{actual} would be a multiple of #{expected}"
56
+ end
57
+ end
58
+
59
+ # fail intentionally to generate expected output
60
+ describe 9 do
61
+ it {should be_a_multiple_of(4)}
62
+ end
63
+ """
64
+ When I run "spec matcher_with_failure_message_spec.rb"
65
+ Then the exit code should be 256
66
+ And the stdout should match "1 example, 1 failure"
67
+ And the stdout should match "expected that 9 would be a multiple of 4"
68
+
69
+ Scenario: overriding the failure_message_for_should_not
70
+ Given a file named "matcher_with_failure_for_message_spec.rb" with:
71
+ """
72
+ Rspec::Matchers.define :be_a_multiple_of do |expected|
73
+ match do |actual|
74
+ actual % expected == 0
75
+ end
76
+ failure_message_for_should_not do |actual|
77
+ "expected that #{actual} would not be a multiple of #{expected}"
78
+ end
79
+ end
80
+
81
+ # fail intentionally to generate expected output
82
+ describe 9 do
83
+ it {should_not be_a_multiple_of(3)}
84
+ end
85
+ """
86
+ When I run "spec matcher_with_failure_for_message_spec.rb"
87
+ Then the exit code should be 256
88
+ And the stdout should match "1 example, 1 failure"
89
+ And the stdout should match "expected that 9 would not be a multiple of 3"
90
+
91
+ Scenario: overriding the description
92
+ Given a file named "matcher_overriding_description_spec.rb" with:
93
+ """
94
+ Rspec::Matchers.define :be_a_multiple_of do |expected|
95
+ match do |actual|
96
+ actual % expected == 0
97
+ end
98
+ description do
99
+ "be multiple of #{expected}"
100
+ end
101
+ end
102
+
103
+ describe 9 do
104
+ it {should be_a_multiple_of(3)}
105
+ end
106
+
107
+ describe 9 do
108
+ it {should_not be_a_multiple_of(4)}
109
+ end
110
+ """
111
+ When I run "spec matcher_overriding_description_spec.rb --format specdoc"
112
+ Then the exit code should be 0
113
+ And the stdout should match "2 examples, 0 failures"
114
+ And the stdout should match "should be multiple of 3"
115
+ And the stdout should match "should not be multiple of 4"
116
+
117
+ Scenario: with no args
118
+ Given a file named "matcher_with_no_args_spec.rb" with:
119
+ """
120
+ Rspec::Matchers.define :have_7_fingers do
121
+ match do |thing|
122
+ thing.fingers.length == 7
123
+ end
124
+ end
125
+
126
+ class Thing
127
+ def fingers; (1..7).collect {"finger"}; end
128
+ end
129
+
130
+ describe Thing do
131
+ it {should have_7_fingers}
132
+ end
133
+ """
134
+ When I run "spec matcher_with_no_args_spec.rb --format specdoc"
135
+ Then the exit code should be 0
136
+ And the stdout should match "1 example, 0 failures"
137
+ And the stdout should match "should have 7 fingers"
138
+
139
+ Scenario: with multiple args
140
+ Given a file named "matcher_with_multiple_args_spec.rb" with:
141
+ """
142
+ Rspec::Matchers.define :be_the_sum_of do |a,b,c,d|
143
+ match do |sum|
144
+ a + b + c + d == sum
145
+ end
146
+ end
147
+
148
+ describe 10 do
149
+ it {should be_the_sum_of(1,2,3,4)}
150
+ end
151
+ """
152
+ When I run "spec matcher_with_multiple_args_spec.rb --format specdoc"
153
+ Then the exit code should be 0
154
+ And the stdout should match "1 example, 0 failures"
155
+ And the stdout should match "should be the sum of 1, 2, 3, and 4"
156
+
157
+ Scenario: with helper methods
158
+ Given a file named "matcher_with_internal_helper_spec.rb" with:
159
+ """
160
+ Rspec::Matchers.define :have_same_elements_as do |sample|
161
+ match do |actual|
162
+ similar?(sample, actual)
163
+ end
164
+
165
+ def similar?(a, b)
166
+ a.sort == b.sort
167
+ end
168
+ end
169
+
170
+ describe "these two arrays" do
171
+ specify "should be similar" do
172
+ [1,2,3].should have_same_elements_as([2,3,1])
173
+ end
174
+ end
175
+ """
176
+ When I run "spec matcher_with_internal_helper_spec.rb"
177
+ Then the exit code should be 0
178
+ And the stdout should match "1 example, 0 failures"
179
+