rspec 1.2.2 → 1.2.3
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/History.rdoc +31 -1
- data/Manifest.txt +14 -12
- data/Rakefile +1 -1
- data/Upgrade.rdoc +43 -3
- data/examples/failing/failing_implicit_docstrings_example.rb +5 -5
- data/examples/passing/implicit_docstrings_example.rb +3 -3
- data/features/before_and_after_blocks/before_and_after_blocks.feature +20 -21
- data/features/example_groups/example_group_with_should_methods.feature +20 -8
- data/features/example_groups/implicit_docstrings.feature +36 -20
- data/features/example_groups/nested_groups.feature +25 -10
- data/features/extensions/custom_example_group.feature +19 -0
- data/features/formatters/custom_formatter.feature +30 -0
- data/features/heckle/heckle.feature +7 -7
- data/features/interop/examples_and_tests_together.feature +63 -14
- data/features/interop/rspec_output.feature +25 -0
- data/features/interop/test_but_not_test_unit.feature +19 -7
- data/features/interop/test_case_with_should_methods.feature +37 -8
- data/features/matchers/{create_matcher.feature → define_matcher.feature} +54 -30
- data/features/matchers/{create_matcher_outside_rspec.feature → define_matcher_outside_rspec.feature} +7 -7
- data/features/mock_framework_integration/use_flexmock.feature +3 -3
- data/features/mock_framework_integration/use_mocha.feature +3 -3
- data/features/mock_framework_integration/use_rr.feature +3 -3
- data/features/mocks/mix_stubs_and_mocks.feature +4 -4
- data/features/pending/pending_examples.feature +18 -18
- data/features/runner/specify_line_number.feature +32 -0
- data/features/step_definitions/running_rspec_steps.rb +41 -0
- data/features/subject/explicit_subject.feature +4 -4
- data/features/subject/implicit_subject.feature +4 -4
- data/features/support/env.rb +64 -11
- data/features/support/matchers/smart_match.rb +10 -35
- data/lib/spec.rb +1 -0
- data/lib/spec/deprecation.rb +40 -0
- data/lib/spec/dsl/main.rb +10 -5
- data/lib/spec/example.rb +1 -27
- data/lib/spec/example/args_and_options.rb +27 -0
- data/lib/spec/example/before_and_after_hooks.rb +30 -21
- data/lib/spec/example/errors.rb +8 -18
- data/lib/spec/example/example_group_factory.rb +0 -4
- data/lib/spec/example/example_group_methods.rb +27 -41
- data/lib/spec/example/example_group_proxy.rb +12 -22
- data/lib/spec/example/example_methods.rb +8 -18
- data/lib/spec/example/example_proxy.rb +4 -4
- data/lib/spec/example/pending.rb +3 -4
- data/lib/spec/example/predicate_matchers.rb +1 -1
- data/lib/spec/example/subject.rb +2 -0
- data/lib/spec/expectations.rb +1 -26
- data/lib/spec/expectations/extensions.rb +1 -1
- data/lib/spec/expectations/extensions/kernel.rb +52 -0
- data/lib/spec/expectations/handler.rb +21 -10
- data/lib/spec/matchers/be.rb +3 -3
- data/lib/spec/matchers/be_close.rb +17 -21
- data/lib/spec/matchers/be_instance_of.rb +7 -26
- data/lib/spec/matchers/be_kind_of.rb +7 -26
- data/lib/spec/matchers/dsl.rb +9 -4
- data/lib/spec/matchers/eql.rb +24 -25
- data/lib/spec/matchers/equal.rb +25 -25
- data/lib/spec/matchers/exist.rb +5 -21
- data/lib/spec/matchers/include.rb +22 -44
- data/lib/spec/matchers/match.rb +5 -25
- data/lib/spec/matchers/match_array.rb +8 -4
- data/lib/spec/matchers/matcher.rb +13 -2
- data/lib/spec/matchers/pretty.rb +1 -0
- data/lib/spec/matchers/simple_matcher.rb +2 -2
- data/lib/spec/mocks/mock.rb +10 -10
- data/lib/spec/mocks/spec_methods.rb +1 -1
- data/lib/spec/runner/configuration.rb +53 -42
- data/lib/spec/{expectations → runner}/differs/default.rb +0 -0
- data/lib/spec/{expectations → runner}/differs/load-diff-lcs.rb +0 -0
- data/lib/spec/runner/drb_command_line.rb +1 -1
- data/lib/spec/runner/example_group_runner.rb +0 -12
- data/lib/spec/runner/formatter/base_formatter.rb +77 -30
- data/lib/spec/runner/formatter/base_text_formatter.rb +19 -24
- data/lib/spec/runner/formatter/failing_example_groups_formatter.rb +1 -1
- data/lib/spec/runner/formatter/html_formatter.rb +4 -6
- data/lib/spec/runner/formatter/nested_text_formatter.rb +2 -2
- data/lib/spec/runner/formatter/no_op_method_missing.rb +21 -0
- data/lib/spec/runner/formatter/profile_formatter.rb +0 -4
- data/lib/spec/runner/formatter/progress_bar_formatter.rb +4 -5
- data/lib/spec/runner/formatter/silent_formatter.rb +10 -0
- data/lib/spec/runner/formatter/specdoc_formatter.rb +2 -2
- data/lib/spec/runner/option_parser.rb +14 -7
- data/lib/spec/runner/options.rb +17 -7
- data/lib/spec/runner/reporter.rb +69 -64
- data/lib/spec/version.rb +1 -1
- data/spec/spec/dsl/main_spec.rb +7 -0
- data/spec/spec/example/example_group_methods_spec.rb +16 -32
- data/spec/spec/example/example_group_proxy_spec.rb +25 -5
- data/spec/spec/example/example_group_spec.rb +2 -2
- data/spec/spec/example/example_methods_spec.rb +19 -24
- data/spec/spec/example/example_proxy_spec.rb +11 -1
- data/spec/spec/example/pending_module_spec.rb +2 -108
- data/spec/spec/example/predicate_matcher_spec.rb +23 -3
- data/spec/spec/expectations/extensions/object_spec.rb +9 -9
- data/spec/spec/expectations/fail_with_spec.rb +13 -13
- data/spec/spec/expectations/handler_spec.rb +44 -15
- data/spec/spec/matchers/be_close_spec.rb +9 -0
- data/spec/spec/matchers/be_instance_of_spec.rb +6 -4
- data/spec/spec/matchers/be_kind_of_spec.rb +5 -3
- data/spec/spec/matchers/be_spec.rb +1 -5
- data/spec/spec/matchers/compatibility_spec.rb +1 -1
- data/spec/spec/matchers/dsl_spec.rb +10 -1
- data/spec/spec/matchers/eql_spec.rb +8 -4
- data/spec/spec/matchers/equal_spec.rb +8 -4
- data/spec/spec/matchers/exist_spec.rb +1 -1
- data/spec/spec/matchers/include_spec.rb +1 -1
- data/spec/spec/matchers/match_array_spec.rb +26 -1
- data/spec/spec/matchers/match_spec.rb +2 -2
- data/spec/spec/matchers/matcher_methods_spec.rb +0 -3
- data/spec/spec/matchers/matcher_spec.rb +53 -0
- data/spec/spec/matchers/operator_matcher_spec.rb +1 -1
- data/spec/spec/mocks/mock_spec.rb +6 -0
- data/spec/spec/runner/configuration_spec.rb +11 -1
- data/spec/spec/runner/drb_command_line_spec.rb +13 -1
- data/spec/spec/runner/example_group_runner_spec.rb +0 -7
- data/spec/spec/runner/formatter/base_formatter_spec.rb +19 -12
- data/spec/spec/runner/formatter/base_text_formatter_spec.rb +2 -2
- data/spec/spec/runner/formatter/failing_example_groups_formatter_spec.rb +4 -4
- data/spec/spec/runner/formatter/failing_examples_formatter_spec.rb +2 -2
- data/spec/spec/runner/formatter/html_formatted-1.8.6.html +31 -34
- data/spec/spec/runner/formatter/html_formatter_spec.rb +20 -0
- data/spec/spec/runner/formatter/nested_text_formatter_spec.rb +20 -20
- data/spec/spec/runner/formatter/profile_formatter_spec.rb +22 -3
- data/spec/spec/runner/formatter/progress_bar_formatter_spec.rb +24 -3
- data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +6 -6
- data/spec/spec/runner/formatter/text_mate_formatted-1.8.6.html +25 -28
- data/spec/spec/runner/formatter/text_mate_formatter_spec.rb +2 -2
- data/spec/spec/runner/option_parser_spec.rb +108 -40
- data/spec/spec/runner/reporter_spec.rb +16 -17
- data/spec/spec_helper.rb +4 -1
- metadata +20 -18
- data/features/example_groups/output.feature +0 -20
- data/features/step_definitions/running_rspec.rb +0 -69
- data/lib/spec/expectations/extensions/object.rb +0 -63
- data/resources/spec/example_group_with_should_methods.rb +0 -12
- data/resources/spec/simple_spec.rb +0 -8
- data/resources/test/spec_and_test_together.rb +0 -56
- data/resources/test/spec_including_test_but_not_unit.rb +0 -11
- data/resources/test/test_case_with_should_methods.rb +0 -29
@@ -4,14 +4,29 @@ Feature: Nested example groups
|
|
4
4
|
I want to nest examples groups
|
5
5
|
So that I can better organize my examples
|
6
6
|
|
7
|
-
Scenario:
|
8
|
-
Given
|
9
|
-
|
10
|
-
|
11
|
-
And the stdout should match /Stack \(full\)/
|
7
|
+
Scenario Outline: Nested example groups
|
8
|
+
Given a file named "nested_example_groups.rb" with:
|
9
|
+
"""
|
10
|
+
require 'spec/autorun'
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
12
|
+
describe "Some Object" do
|
13
|
+
describe "with some more context" do
|
14
|
+
it "should do this" do
|
15
|
+
true.should be_true
|
16
|
+
end
|
17
|
+
end
|
18
|
+
describe "with some other context" do
|
19
|
+
it "should do that" do
|
20
|
+
false.should be_false
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
"""
|
25
|
+
When I run "<Command> nested_example_groups.rb -fs"
|
26
|
+
Then the stdout should match /Some Object with some more context/
|
27
|
+
And the stdout should match /Some Object with some other context/
|
28
|
+
|
29
|
+
Scenarios: Run with ruby and spec
|
30
|
+
| Command |
|
31
|
+
| ruby |
|
32
|
+
| spec |
|
@@ -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"
|
@@ -5,7 +5,7 @@ Feature: heckle a class
|
|
5
5
|
I want to heckle a class
|
6
6
|
|
7
7
|
Scenario: Heckle finds problems
|
8
|
-
Given
|
8
|
+
Given a file named "heckle_fail_spec.rb" with:
|
9
9
|
"""
|
10
10
|
class Thing
|
11
11
|
def a_or_b
|
@@ -16,19 +16,19 @@ Feature: heckle a class
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
describe Thing do
|
21
21
|
it "returns a for true" do
|
22
22
|
Thing.new.a_or_b.should == "a"
|
23
23
|
end
|
24
24
|
end
|
25
25
|
"""
|
26
|
-
When I run
|
26
|
+
When I run "spec heckle_fail_spec.rb --heckle Thing"
|
27
27
|
Then the stdout should match "The following mutations didn't cause test failures:"
|
28
28
|
But the stdout should not match "FAILED"
|
29
|
-
|
29
|
+
|
30
30
|
Scenario: Heckle does not find a problem
|
31
|
-
Given
|
31
|
+
Given a file named "heckle_success_spec.rb" with:
|
32
32
|
"""
|
33
33
|
class Thing
|
34
34
|
def a_or_b(key)
|
@@ -50,7 +50,7 @@ Feature: heckle a class
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
"""
|
53
|
-
When I run
|
53
|
+
When I run "spec heckle_success_spec.rb --heckle Thing"
|
54
54
|
Then the stdout should match "No mutants survived"
|
55
55
|
But the stdout should not match "FAILED"
|
56
|
-
|
56
|
+
|
@@ -4,23 +4,67 @@ Feature: Spec and test together
|
|
4
4
|
I want to run a few specs alongside my existing Test::Unit tests
|
5
5
|
So that I can experience a smooth, gradual migration path
|
6
6
|
|
7
|
-
Scenario: Run
|
8
|
-
Given
|
7
|
+
Scenario Outline: Run specs and tests together
|
8
|
+
Given a file named "spec_and_test_together.rb" with:
|
9
|
+
"""
|
10
|
+
require 'spec/autorun'
|
11
|
+
require 'spec/test/unit'
|
9
12
|
|
10
|
-
|
13
|
+
describe "An Example" do
|
14
|
+
it "should pass with assert" do
|
15
|
+
assert true
|
16
|
+
end
|
11
17
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
22
30
|
|
23
|
-
|
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"
|
24
68
|
|
25
69
|
Then the exit code should be 256
|
26
70
|
And the stdout should match "ATest"
|
@@ -29,3 +73,8 @@ Feature: Spec and test together
|
|
29
73
|
And the stdout should match "10 examples, 6 failures"
|
30
74
|
And the stdout should match /expected: 40,\s*got: 4/m
|
31
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 'spec/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 CommandLine object
|
23
|
+
| Command |
|
24
|
+
| ruby |
|
25
|
+
| cmdline.rb |
|
@@ -3,12 +3,24 @@ Story: Test is defined, but not Test::Unit
|
|
3
3
|
As an RSpec user who has my own library named Test (but not Test::Unit)
|
4
4
|
I want to run examples without getting Test::Unit NameErrors
|
5
5
|
|
6
|
-
Scenario:
|
7
|
-
Given
|
8
|
-
|
9
|
-
|
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 'spec/autorun'
|
10
|
+
|
11
|
+
module Test
|
12
|
+
end
|
10
13
|
|
11
|
-
|
12
|
-
|
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"
|
14
21
|
Then the stderr should not match "Test::Unit"
|
22
|
+
|
23
|
+
Scenarios: Run with ruby and spec
|
24
|
+
| Command |
|
25
|
+
| ruby |
|
26
|
+
| spec |
|
@@ -4,14 +4,43 @@ Story: Test::Unit::TestCase extended by rspec with should methods
|
|
4
4
|
I want to use should_* methods in a Test::Unit::TestCase
|
5
5
|
So that I use RSpec with classes and methods that look more like RSpec examples
|
6
6
|
|
7
|
-
Scenario:
|
8
|
-
Given
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
Scenario Outline: TestCase with should methods
|
8
|
+
Given a file named "test_case_with_should_methods.rb" with:
|
9
|
+
"""
|
10
|
+
require 'spec/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
|
12
21
|
|
13
|
-
|
14
|
-
|
15
|
-
|
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"
|
16
40
|
Then the exit code should be 256
|
17
41
|
And the stdout should match "5 examples, 3 failures"
|
42
|
+
|
43
|
+
Scenarios: Run with ruby and spec
|
44
|
+
| Command |
|
45
|
+
| ruby |
|
46
|
+
| spec |
|
@@ -1,13 +1,13 @@
|
|
1
|
-
Feature:
|
1
|
+
Feature: define matcher
|
2
2
|
|
3
3
|
In order to express my domain clearly in my code examples
|
4
4
|
As an RSpec user
|
5
|
-
I want a shortcut
|
5
|
+
I want a shortcut to define custom matchers
|
6
6
|
|
7
|
-
Scenario:
|
8
|
-
Given
|
7
|
+
Scenario: define a matcher with default messages
|
8
|
+
Given a file named "matcher_with_default_message_spec.rb" with:
|
9
9
|
"""
|
10
|
-
Spec::Matchers.
|
10
|
+
Spec::Matchers.define :be_a_multiple_of do |expected|
|
11
11
|
match do |actual|
|
12
12
|
actual % expected == 0
|
13
13
|
end
|
@@ -32,7 +32,7 @@ Feature: custom matcher shortcut
|
|
32
32
|
end
|
33
33
|
|
34
34
|
"""
|
35
|
-
When I run
|
35
|
+
When I run "spec matcher_with_default_message_spec.rb --format specdoc"
|
36
36
|
Then the exit code should be 256
|
37
37
|
|
38
38
|
And the stdout should match "should be a multiple of 3"
|
@@ -43,11 +43,11 @@ Feature: custom matcher shortcut
|
|
43
43
|
And the stdout should match "4 examples, 2 failures"
|
44
44
|
And the stdout should match "expected 9 to be a multiple of 4"
|
45
45
|
And the stdout should match "expected 9 not to be a multiple of 3"
|
46
|
-
|
46
|
+
|
47
47
|
Scenario: overriding the failure_message_for_should
|
48
|
-
Given
|
48
|
+
Given a file named "matcher_with_failure_message_spec.rb" with:
|
49
49
|
"""
|
50
|
-
Spec::Matchers.
|
50
|
+
Spec::Matchers.define :be_a_multiple_of do |expected|
|
51
51
|
match do |actual|
|
52
52
|
actual % expected == 0
|
53
53
|
end
|
@@ -55,21 +55,21 @@ Feature: custom matcher shortcut
|
|
55
55
|
"expected that #{actual} would be a multiple of #{expected}"
|
56
56
|
end
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
59
|
# fail intentionally to generate expected output
|
60
60
|
describe 9 do
|
61
61
|
it {should be_a_multiple_of(4)}
|
62
62
|
end
|
63
63
|
"""
|
64
|
-
When I run
|
64
|
+
When I run "spec matcher_with_failure_message_spec.rb"
|
65
65
|
Then the exit code should be 256
|
66
66
|
And the stdout should match "1 example, 1 failure"
|
67
67
|
And the stdout should match "expected that 9 would be a multiple of 4"
|
68
|
-
|
68
|
+
|
69
69
|
Scenario: overriding the failure_message_for_should_not
|
70
|
-
Given
|
70
|
+
Given a file named "matcher_with_failure_for_message_spec.rb" with:
|
71
71
|
"""
|
72
|
-
Spec::Matchers.
|
72
|
+
Spec::Matchers.define :be_a_multiple_of do |expected|
|
73
73
|
match do |actual|
|
74
74
|
actual % expected == 0
|
75
75
|
end
|
@@ -77,21 +77,21 @@ Feature: custom matcher shortcut
|
|
77
77
|
"expected that #{actual} would not be a multiple of #{expected}"
|
78
78
|
end
|
79
79
|
end
|
80
|
-
|
80
|
+
|
81
81
|
# fail intentionally to generate expected output
|
82
82
|
describe 9 do
|
83
83
|
it {should_not be_a_multiple_of(3)}
|
84
84
|
end
|
85
85
|
"""
|
86
|
-
When I run
|
86
|
+
When I run "spec matcher_with_failure_for_message_spec.rb"
|
87
87
|
Then the exit code should be 256
|
88
88
|
And the stdout should match "1 example, 1 failure"
|
89
89
|
And the stdout should match "expected that 9 would not be a multiple of 3"
|
90
|
-
|
90
|
+
|
91
91
|
Scenario: overriding the description
|
92
|
-
Given
|
92
|
+
Given a file named "matcher_overriding_description_spec.rb" with:
|
93
93
|
"""
|
94
|
-
Spec::Matchers.
|
94
|
+
Spec::Matchers.define :be_a_multiple_of do |expected|
|
95
95
|
match do |actual|
|
96
96
|
actual % expected == 0
|
97
97
|
end
|
@@ -99,30 +99,30 @@ Feature: custom matcher shortcut
|
|
99
99
|
"be multiple of #{expected}"
|
100
100
|
end
|
101
101
|
end
|
102
|
-
|
102
|
+
|
103
103
|
describe 9 do
|
104
104
|
it {should be_a_multiple_of(3)}
|
105
105
|
end
|
106
|
-
|
106
|
+
|
107
107
|
describe 9 do
|
108
108
|
it {should_not be_a_multiple_of(4)}
|
109
109
|
end
|
110
110
|
"""
|
111
|
-
When I run
|
111
|
+
When I run "spec matcher_overriding_description_spec.rb --format specdoc"
|
112
112
|
Then the exit code should be 0
|
113
113
|
And the stdout should match "2 examples, 0 failures"
|
114
114
|
And the stdout should match "should be multiple of 3"
|
115
115
|
And the stdout should match "should not be multiple of 4"
|
116
116
|
|
117
117
|
Scenario: with no args
|
118
|
-
Given
|
118
|
+
Given a file named "matcher_with_no_args_spec.rb" with:
|
119
119
|
"""
|
120
|
-
Spec::Matchers.
|
120
|
+
Spec::Matchers.define :have_7_fingers do
|
121
121
|
match do |thing|
|
122
122
|
thing.fingers.length == 7
|
123
123
|
end
|
124
124
|
end
|
125
|
-
|
125
|
+
|
126
126
|
class Thing
|
127
127
|
def fingers; (1..7).collect {"finger"}; end
|
128
128
|
end
|
@@ -131,15 +131,15 @@ Feature: custom matcher shortcut
|
|
131
131
|
it {should have_7_fingers}
|
132
132
|
end
|
133
133
|
"""
|
134
|
-
When I run
|
134
|
+
When I run "spec matcher_with_no_args_spec.rb --format specdoc"
|
135
135
|
Then the exit code should be 0
|
136
136
|
And the stdout should match "1 example, 0 failures"
|
137
137
|
And the stdout should match "should have 7 fingers"
|
138
|
-
|
138
|
+
|
139
139
|
Scenario: with multiple args
|
140
|
-
Given
|
140
|
+
Given a file named "matcher_with_multiple_args_spec.rb" with:
|
141
141
|
"""
|
142
|
-
Spec::Matchers.
|
142
|
+
Spec::Matchers.define :be_the_sum_of do |a,b,c,d|
|
143
143
|
match do |sum|
|
144
144
|
a + b + c + d == sum
|
145
145
|
end
|
@@ -149,7 +149,31 @@ Feature: custom matcher shortcut
|
|
149
149
|
it {should be_the_sum_of(1,2,3,4)}
|
150
150
|
end
|
151
151
|
"""
|
152
|
-
When I run
|
152
|
+
When I run "spec matcher_with_multiple_args_spec.rb --format specdoc"
|
153
153
|
Then the exit code should be 0
|
154
154
|
And the stdout should match "1 example, 0 failures"
|
155
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
|
+
Spec::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
|
+
|