rspec-expectations 3.0.0.beta2 → 3.0.0.rc1

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.
Files changed (135) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +2 -2
  4. data/.yardopts +0 -1
  5. data/Changelog.md +115 -35
  6. data/README.md +2 -2
  7. data/lib/rspec/expectations.rb +13 -8
  8. data/lib/rspec/{matchers → expectations}/configuration.rb +38 -13
  9. data/lib/rspec/expectations/expectation_target.rb +72 -8
  10. data/lib/rspec/expectations/fail_with.rb +10 -52
  11. data/lib/rspec/expectations/handler.rb +9 -11
  12. data/lib/rspec/expectations/syntax.rb +37 -35
  13. data/lib/rspec/expectations/version.rb +1 -1
  14. data/lib/rspec/matchers.rb +60 -9
  15. data/lib/rspec/matchers/aliased_matcher.rb +6 -0
  16. data/lib/rspec/matchers/built_in.rb +9 -1
  17. data/lib/rspec/matchers/built_in/all.rb +78 -0
  18. data/lib/rspec/matchers/built_in/base_matcher.rb +39 -1
  19. data/lib/rspec/matchers/built_in/be.rb +117 -42
  20. data/lib/rspec/matchers/built_in/be_between.rb +22 -0
  21. data/lib/rspec/matchers/built_in/be_instance_of.rb +11 -3
  22. data/lib/rspec/matchers/built_in/be_kind_of.rb +5 -0
  23. data/lib/rspec/matchers/built_in/be_within.rb +26 -6
  24. data/lib/rspec/matchers/built_in/change.rb +89 -13
  25. data/lib/rspec/matchers/built_in/compound.rb +19 -3
  26. data/lib/rspec/matchers/built_in/contain_exactly.rb +17 -6
  27. data/lib/rspec/matchers/built_in/cover.rb +3 -0
  28. data/lib/rspec/matchers/built_in/eq.rb +20 -5
  29. data/lib/rspec/matchers/built_in/eql.rb +15 -3
  30. data/lib/rspec/matchers/built_in/equal.rb +23 -6
  31. data/lib/rspec/matchers/built_in/exist.rb +74 -10
  32. data/lib/rspec/matchers/built_in/has.rb +58 -3
  33. data/lib/rspec/matchers/built_in/include.rb +16 -1
  34. data/lib/rspec/matchers/built_in/match.rb +14 -4
  35. data/lib/rspec/matchers/built_in/operators.rb +16 -0
  36. data/lib/rspec/matchers/built_in/output.rb +47 -5
  37. data/lib/rspec/matchers/built_in/raise_error.rb +40 -23
  38. data/lib/rspec/matchers/built_in/respond_to.rb +37 -16
  39. data/lib/rspec/matchers/built_in/satisfy.rb +15 -0
  40. data/lib/rspec/matchers/built_in/start_and_end_with.rb +29 -14
  41. data/lib/rspec/matchers/built_in/throw_symbol.rb +32 -3
  42. data/lib/rspec/matchers/built_in/yield.rb +148 -44
  43. data/lib/rspec/matchers/composable.rb +48 -7
  44. data/lib/rspec/matchers/dsl.rb +45 -17
  45. data/lib/rspec/matchers/generated_descriptions.rb +7 -0
  46. data/lib/rspec/matchers/matcher_delegator.rb +6 -2
  47. data/lib/rspec/matchers/pretty.rb +15 -19
  48. metadata +33 -236
  49. metadata.gz.sig +0 -0
  50. data/features/README.md +0 -48
  51. data/features/Upgrade.md +0 -53
  52. data/features/built_in_matchers/README.md +0 -96
  53. data/features/built_in_matchers/be.feature +0 -175
  54. data/features/built_in_matchers/be_within.feature +0 -48
  55. data/features/built_in_matchers/comparisons.feature +0 -97
  56. data/features/built_in_matchers/contain_exactly.feature +0 -46
  57. data/features/built_in_matchers/cover.feature +0 -47
  58. data/features/built_in_matchers/end_with.feature +0 -48
  59. data/features/built_in_matchers/equality.feature +0 -136
  60. data/features/built_in_matchers/exist.feature +0 -45
  61. data/features/built_in_matchers/expect_change.feature +0 -59
  62. data/features/built_in_matchers/expect_error.feature +0 -144
  63. data/features/built_in_matchers/include.feature +0 -126
  64. data/features/built_in_matchers/match.feature +0 -51
  65. data/features/built_in_matchers/output.feature +0 -70
  66. data/features/built_in_matchers/predicates.feature +0 -161
  67. data/features/built_in_matchers/respond_to.feature +0 -84
  68. data/features/built_in_matchers/satisfy.feature +0 -33
  69. data/features/built_in_matchers/start_with.feature +0 -48
  70. data/features/built_in_matchers/throw_symbol.feature +0 -91
  71. data/features/built_in_matchers/types.feature +0 -116
  72. data/features/built_in_matchers/yield.feature +0 -161
  73. data/features/composing_matchers.feature +0 -250
  74. data/features/compound_expectations.feature +0 -45
  75. data/features/custom_matchers/access_running_example.feature +0 -53
  76. data/features/custom_matchers/define_diffable_matcher.feature +0 -27
  77. data/features/custom_matchers/define_matcher.feature +0 -340
  78. data/features/custom_matchers/define_matcher_outside_rspec.feature +0 -34
  79. data/features/custom_matchers/define_matcher_with_fluent_interface.feature +0 -24
  80. data/features/customized_message.feature +0 -39
  81. data/features/diffing.feature +0 -85
  82. data/features/implicit_docstrings.feature +0 -52
  83. data/features/step_definitions/additional_cli_steps.rb +0 -22
  84. data/features/support/env.rb +0 -21
  85. data/features/support/rubinius.rb +0 -6
  86. data/features/syntax_configuration.feature +0 -71
  87. data/features/test_frameworks/minitest.feature +0 -44
  88. data/lib/rspec-expectations.rb +0 -1
  89. data/lib/rspec/expectations/diff_presenter.rb +0 -141
  90. data/lib/rspec/expectations/differ.rb +0 -44
  91. data/lib/rspec/expectations/encoded_string.rb +0 -56
  92. data/spec/rspec/expectations/diff_presenter_spec.rb +0 -249
  93. data/spec/rspec/expectations/encoded_string_spec.rb +0 -74
  94. data/spec/rspec/expectations/expectation_target_spec.rb +0 -82
  95. data/spec/rspec/expectations/extensions/kernel_spec.rb +0 -67
  96. data/spec/rspec/expectations/fail_with_spec.rb +0 -114
  97. data/spec/rspec/expectations/handler_spec.rb +0 -205
  98. data/spec/rspec/expectations/minitest_integration_spec.rb +0 -27
  99. data/spec/rspec/expectations/syntax_spec.rb +0 -89
  100. data/spec/rspec/expectations_spec.rb +0 -12
  101. data/spec/rspec/matchers/aliased_matcher_spec.rb +0 -48
  102. data/spec/rspec/matchers/aliases_spec.rb +0 -449
  103. data/spec/rspec/matchers/built_in/base_matcher_spec.rb +0 -83
  104. data/spec/rspec/matchers/built_in/be_between_spec.rb +0 -159
  105. data/spec/rspec/matchers/built_in/be_instance_of_spec.rb +0 -63
  106. data/spec/rspec/matchers/built_in/be_kind_of_spec.rb +0 -41
  107. data/spec/rspec/matchers/built_in/be_spec.rb +0 -592
  108. data/spec/rspec/matchers/built_in/be_within_spec.rb +0 -141
  109. data/spec/rspec/matchers/built_in/change_spec.rb +0 -808
  110. data/spec/rspec/matchers/built_in/compound_spec.rb +0 -292
  111. data/spec/rspec/matchers/built_in/contain_exactly_spec.rb +0 -441
  112. data/spec/rspec/matchers/built_in/cover_spec.rb +0 -69
  113. data/spec/rspec/matchers/built_in/eq_spec.rb +0 -156
  114. data/spec/rspec/matchers/built_in/eql_spec.rb +0 -41
  115. data/spec/rspec/matchers/built_in/equal_spec.rb +0 -106
  116. data/spec/rspec/matchers/built_in/exist_spec.rb +0 -124
  117. data/spec/rspec/matchers/built_in/has_spec.rb +0 -161
  118. data/spec/rspec/matchers/built_in/include_spec.rb +0 -540
  119. data/spec/rspec/matchers/built_in/match_spec.rb +0 -102
  120. data/spec/rspec/matchers/built_in/operators_spec.rb +0 -252
  121. data/spec/rspec/matchers/built_in/output_spec.rb +0 -165
  122. data/spec/rspec/matchers/built_in/raise_error_spec.rb +0 -461
  123. data/spec/rspec/matchers/built_in/respond_to_spec.rb +0 -292
  124. data/spec/rspec/matchers/built_in/satisfy_spec.rb +0 -44
  125. data/spec/rspec/matchers/built_in/start_and_end_with_spec.rb +0 -253
  126. data/spec/rspec/matchers/built_in/throw_symbol_spec.rb +0 -135
  127. data/spec/rspec/matchers/built_in/yield_spec.rb +0 -627
  128. data/spec/rspec/matchers/configuration_spec.rb +0 -213
  129. data/spec/rspec/matchers/description_generation_spec.rb +0 -191
  130. data/spec/rspec/matchers/dsl_spec.rb +0 -895
  131. data/spec/rspec/matchers/legacy_spec.rb +0 -101
  132. data/spec/rspec/matchers_spec.rb +0 -74
  133. data/spec/spec_helper.rb +0 -85
  134. data/spec/support/matchers.rb +0 -22
  135. data/spec/support/shared_examples.rb +0 -35
@@ -1,126 +0,0 @@
1
- Feature: include matcher
2
-
3
- Use the include matcher to specify that a collection includes one or more
4
- expected objects. This works on any object that responds to #include? (such
5
- as a string or array):
6
-
7
- ```ruby
8
- expect("a string").to include("a")
9
- expect("a string").to include("str")
10
- expect("a string").to include("str", "g")
11
- expect("a string").not_to include("foo")
12
-
13
- expect([1, 2]).to include(1)
14
- expect([1, 2]).to include(1, 2)
15
- expect([1, 2]).not_to include(17)
16
- ```
17
-
18
- The matcher also provides flexible handling for hashes:
19
-
20
- ```ruby
21
- expect(:a => 1, :b => 2).to include(:a)
22
- expect(:a => 1, :b => 2).to include(:a, :b)
23
- expect(:a => 1, :b => 2).to include(:a => 1)
24
- expect(:a => 1, :b => 2).to include(:b => 2, :a => 1)
25
- expect(:a => 1, :b => 2).not_to include(:c)
26
- expect(:a => 1, :b => 2).not_to include(:a => 2)
27
- expect(:a => 1, :b => 2).not_to include(:c => 3)
28
- ```
29
-
30
- Scenario: array usage
31
- Given a file named "array_include_matcher_spec.rb" with:
32
- """ruby
33
- describe [1, 3, 7] do
34
- it { should include(1) }
35
- it { should include(3) }
36
- it { should include(7) }
37
- it { should include(1, 7) }
38
- it { should include(1, 3, 7) }
39
- it { should_not include(17) }
40
- it { should_not include(43, 100) }
41
-
42
- # deliberate failures
43
- it { should include(4) }
44
- it { should_not include(1) }
45
- it { should_not include(3) }
46
- it { should_not include(7) }
47
- it { should_not include(1, 3, 7) }
48
-
49
- # both of these should fail since it includes 1 but not 9
50
- it { should include(1, 9) }
51
- it { should_not include(1, 9) }
52
- end
53
- """
54
- When I run `rspec array_include_matcher_spec.rb`
55
- Then the output should contain all of these:
56
- | 14 examples, 7 failures |
57
- | expected [1, 3, 7] to include 4 |
58
- | expected [1, 3, 7] not to include 1 |
59
- | expected [1, 3, 7] not to include 3 |
60
- | expected [1, 3, 7] not to include 7 |
61
- | expected [1, 3, 7] not to include 1, 3, and 7 |
62
- | expected [1, 3, 7] to include 1 and 9 |
63
- | expected [1, 3, 7] not to include 1 and 9 |
64
-
65
- Scenario: string usage
66
- Given a file named "string_include_matcher_spec.rb" with:
67
- """ruby
68
- describe "a string" do
69
- it { should include("str") }
70
- it { should include("a", "str", "ng") }
71
- it { should_not include("foo") }
72
- it { should_not include("foo", "bar") }
73
-
74
- # deliberate failures
75
- it { should include("foo") }
76
- it { should_not include("str") }
77
- it { should include("str", "foo") }
78
- it { should_not include("str", "foo") }
79
- end
80
- """
81
- When I run `rspec string_include_matcher_spec.rb`
82
- Then the output should contain all of these:
83
- | 8 examples, 4 failures |
84
- | expected "a string" to include "foo" |
85
- | expected "a string" not to include "str" |
86
- | expected "a string" to include "str" and "foo" |
87
- | expected "a string" not to include "str" and "foo" |
88
-
89
- Scenario: hash usage
90
- Given a file named "hash_include_matcher_spec.rb" with:
91
- """ruby
92
- describe Hash do
93
- subject { { :a => 7, :b => 5 } }
94
-
95
- it { should include(:a) }
96
- it { should include(:b, :a) }
97
- it { should include(:a => 7) }
98
- it { should include(:b => 5, :a => 7) }
99
- it { should_not include(:c) }
100
- it { should_not include(:c, :d) }
101
- it { should_not include(:d => 2) }
102
- it { should_not include(:a => 5) }
103
- it { should_not include(:b => 7, :a => 5) }
104
-
105
- # deliberate failures
106
- it { should_not include(:a) }
107
- it { should_not include(:b, :a) }
108
- it { should_not include(:a => 7) }
109
- it { should_not include(:a => 7, :b => 5) }
110
- it { should include(:c) }
111
- it { should include(:c, :d) }
112
- it { should include(:d => 2) }
113
- it { should include(:a => 5) }
114
- it { should include(:a => 5, :b => 7) }
115
-
116
- # Mixed cases--the hash includes one but not the other.
117
- # All 4 of these cases should fail.
118
- it { should include(:a, :d) }
119
- it { should_not include(:a, :d) }
120
- it { should include(:a => 7, :d => 3) }
121
- it { should_not include(:a => 7, :d => 3) }
122
- end
123
- """
124
- When I run `rspec hash_include_matcher_spec.rb`
125
- Then the output should contain "13 failure"
126
-
@@ -1,51 +0,0 @@
1
- Feature: match matcher
2
-
3
- The match matcher calls #match on the object, passing if #match returns a
4
- truthy (not false or nil) value. Regexp and String both provide a #match
5
- method.
6
-
7
- ```ruby
8
- expect("a string").to match(/str/) # passes
9
- expect("a string").to match(/foo/) # fails
10
- expect(/foo/).to match("food") # passes
11
- expect(/foo/).to match("drinks") # fails
12
- ```
13
-
14
- This is equivalent to using the =~ matcher (see the operator matchers
15
- feature for more details).
16
-
17
- Scenario: string usage
18
- Given a file named "string_match_spec.rb" with:
19
- """ruby
20
- describe "a string" do
21
- it { should match(/str/) }
22
- it { should_not match(/foo/) }
23
-
24
- # deliberate failures
25
- it { should_not match(/str/) }
26
- it { should match(/foo/) }
27
- end
28
- """
29
- When I run `rspec string_match_spec.rb`
30
- Then the output should contain all of these:
31
- | 4 examples, 2 failures |
32
- | expected "a string" not to match /str/ |
33
- | expected "a string" to match /foo/ |
34
-
35
- Scenario: regular expression usage
36
- Given a file named "regexp_match_spec.rb" with:
37
- """ruby
38
- describe /foo/ do
39
- it { should match("food") }
40
- it { should_not match("drinks") }
41
-
42
- # deliberate failures
43
- it { should_not match("food") }
44
- it { should match("drinks") }
45
- end
46
- """
47
- When I run `rspec regexp_match_spec.rb`
48
- Then the output should contain all of these:
49
- | 4 examples, 2 failures |
50
- | expected /foo/ not to match "food" |
51
- | expected /foo/ to match "drinks" |
@@ -1,70 +0,0 @@
1
- Feature: output matcher
2
-
3
- The `output` matcher provides a way to assert that the
4
- has emitted content to either `$stdout` or `$stderr`.
5
-
6
- With no arg, passes if the block outputs `to_stdout` or `to_stderr`.
7
- With a string, passes if the blocks outputs that specific string
8
- `to_stdout` or `to_stderr`. With a regexp or matcher, passes if the
9
- blocks outputs a string `to_stdout` or `to_stderr` that matches.
10
-
11
- Note: This matcher works by temporarily replacing `$stdout` or `$stderr`,
12
- so it's not able to intercept stream output that explicitly uses `STDOUT`/`STDERR`
13
- or that uses a reference to `$stdout`/`$stderr` that was stored before the
14
- matcher is used.
15
-
16
- Scenario: output_to_stdout matcher
17
- Given a file named "output_to_stdout_spec.rb" with:
18
- """ruby
19
- describe "output.to_stdout matcher" do
20
- specify { expect { print('foo') }.to output.to_stdout }
21
- specify { expect { print('foo') }.to output('foo').to_stdout }
22
- specify { expect { print('foo') }.to output(/foo/).to_stdout }
23
- specify { expect { }.to_not output.to_stdout }
24
- specify { expect { print('foo') }.to_not output('bar').to_stdout }
25
- specify { expect { print('foo') }.to_not output(/bar/).to_stdout }
26
-
27
- # deliberate failures
28
- specify { expect { }.to output.to_stdout }
29
- specify { expect { }.to output('foo').to_stdout }
30
- specify { expect { print('foo') }.to_not output.to_stdout }
31
- specify { expect { print('foo') }.to output('bar').to_stdout }
32
- specify { expect { print('foo') }.to output(/bar/).to_stdout }
33
- end
34
- """
35
- When I run `rspec output_to_stdout_spec.rb`
36
- Then the output should contain all of these:
37
- | 11 examples, 5 failures |
38
- | expected block to output to stdout, but did not |
39
- | expected block to not output to stdout, but did |
40
- | expected block to output "bar" to stdout, but output "foo" |
41
- | expected block to output "foo" to stdout, but output nothing |
42
- | expected block to output /bar/ to stdout, but output "foo" |
43
-
44
- Scenario: output_to_stderr matcher
45
- Given a file named "output_to_stderr.rb" with:
46
- """ruby
47
- describe "output_to_stderr matcher" do
48
- specify { expect { warn('foo') }.to output.to_stderr }
49
- specify { expect { warn('foo') }.to output("foo\n").to_stderr }
50
- specify { expect { warn('foo') }.to output(/foo/).to_stderr }
51
- specify { expect { }.to_not output.to_stderr }
52
- specify { expect { warn('foo') }.to_not output('bar').to_stderr }
53
- specify { expect { warn('foo') }.to_not output(/bar/).to_stderr }
54
-
55
- # deliberate failures
56
- specify { expect { }.to output.to_stderr }
57
- specify { expect { }.to output('foo').to_stderr }
58
- specify { expect { warn('foo') }.to_not output.to_stderr }
59
- specify { expect { warn('foo') }.to output('bar').to_stderr }
60
- specify { expect { warn('foo') }.to output(/bar/).to_stderr }
61
- end
62
- """
63
- When I run `rspec output_to_stderr.rb`
64
- Then the output should contain all of these:
65
- | 11 examples, 5 failures |
66
- | expected block to output to stderr, but did not |
67
- | expected block to not output to stderr, but did |
68
- | expected block to output "bar" to stderr, but output "foo\n" |
69
- | expected block to output "foo" to stderr, but output nothing |
70
- | expected block to output /bar/ to stderr, but output "foo\n" |
@@ -1,161 +0,0 @@
1
- Feature: predicate matchers
2
-
3
- Ruby objects commonly provide predicate methods:
4
-
5
- ```ruby
6
- 7.zero? # => false
7
- 0.zero? # => true
8
- [1].empty? # => false
9
- [].empty? # => true
10
- { :a => 5 }.has_key?(:b) # => false
11
- { :b => 5 }.has_key?(:b) # => true
12
- ```
13
-
14
- You could use a basic equality matcher to set expectations on these:
15
-
16
- ```ruby
17
- expect(7.zero?).to eq true # fails with "expected true, got false (using ==)"
18
- ```
19
-
20
- ...but RSpec provides dynamic predicate matchers that are more readable and
21
- provide better failure output.
22
-
23
- For any predicate method, RSpec gives you a corresponding matcher. Simply
24
- prefix the method with `be_` and remove the question mark. Examples:
25
-
26
- ```ruby
27
- expect(7).not_to be_zero # calls 7.zero?
28
- expect([]).to be_empty # calls [].empty?
29
- expect(x).to be_multiple_of(3) # calls x.multiple_of?(3)
30
- ```
31
-
32
- Alternately, for a predicate method that begins with `has_` like
33
- `Hash#has_key?`, RSpec allows you to use an alternate form since `be_has_key`
34
- makes no sense.
35
-
36
- ```ruby
37
- expect(hash).to have_key(:foo) # calls hash.has_key?(:foo)
38
- expect(array).not_to have_odd_values # calls array.has_odd_values?
39
- ```
40
-
41
- In either case, RSpec provides nice, clear error messages, such as:
42
-
43
- `expected zero? to return true, got false`
44
-
45
- Calling private methods will also fail:
46
-
47
- `expected private_method? to return true but it's a private method`
48
-
49
- Any arguments passed to the matcher will be passed on to the predicate method.
50
-
51
- Scenario: should be_zero (based on Fixnum#zero?)
52
- Given a file named "should_be_zero_spec.rb" with:
53
- """ruby
54
- describe 0 do
55
- it { should be_zero }
56
- end
57
-
58
- describe 7 do
59
- it { should be_zero } # deliberate failure
60
- end
61
- """
62
- When I run `rspec should_be_zero_spec.rb`
63
- Then the output should contain "2 examples, 1 failure"
64
- And the output should contain "expected zero? to return true, got false"
65
-
66
- Scenario: should_not be_empty (based on Array#empty?)
67
- Given a file named "should_not_be_empty_spec.rb" with:
68
- """ruby
69
- describe [1, 2, 3] do
70
- it { should_not be_empty }
71
- end
72
-
73
- describe [] do
74
- it { should_not be_empty } # deliberate failure
75
- end
76
- """
77
- When I run `rspec should_not_be_empty_spec.rb`
78
- Then the output should contain "2 examples, 1 failure"
79
- And the output should contain "expected empty? to return false, got true"
80
-
81
- Scenario: should have_key (based on Hash#has_key?)
82
- Given a file named "should_have_key_spec.rb" with:
83
- """ruby
84
- describe Hash do
85
- subject { { :foo => 7 } }
86
- it { should have_key(:foo) }
87
- it { should have_key(:bar) } # deliberate failure
88
- end
89
- """
90
- When I run `rspec should_have_key_spec.rb`
91
- Then the output should contain "2 examples, 1 failure"
92
- And the output should contain "expected #has_key?(:bar) to return true, got false"
93
-
94
- Scenario: should_not have_all_string_keys (based on custom #has_all_string_keys? method)
95
- Given a file named "should_not_have_all_string_keys_spec.rb" with:
96
- """ruby
97
- class Hash
98
- def has_all_string_keys?
99
- keys.all? { |k| String === k }
100
- end
101
- end
102
-
103
- describe Hash do
104
- context 'with symbol keys' do
105
- subject { { :foo => 7, :bar => 5 } }
106
- it { should_not have_all_string_keys }
107
- end
108
-
109
- context 'with string keys' do
110
- subject { { 'foo' => 7, 'bar' => 5 } }
111
- it { should_not have_all_string_keys } # deliberate failure
112
- end
113
- end
114
- """
115
- When I run `rspec should_not_have_all_string_keys_spec.rb`
116
- Then the output should contain "2 examples, 1 failure"
117
- And the output should contain "expected #has_all_string_keys? to return false, got true"
118
-
119
- Scenario: matcher arguments are passed on to the predicate method
120
- Given a file named "predicate_matcher_argument_spec.rb" with:
121
- """ruby
122
- class Fixnum
123
- def multiple_of?(x)
124
- (self % x).zero?
125
- end
126
- end
127
-
128
- describe 12 do
129
- it { should be_multiple_of(3) }
130
- it { should_not be_multiple_of(7) }
131
-
132
- # deliberate failures
133
- it { should_not be_multiple_of(4) }
134
- it { should be_multiple_of(5) }
135
- end
136
- """
137
- When I run `rspec predicate_matcher_argument_spec.rb`
138
- Then the output should contain "4 examples, 2 failures"
139
- And the output should contain "expected multiple_of?(4) to return false, got true"
140
- And the output should contain "expected multiple_of?(5) to return true, got false"
141
-
142
- Scenario: calling private method causes error
143
- Given a file named "attempting_to_match_private_method_spec.rb" with:
144
- """ruby
145
- class WithPrivateMethods
146
- def secret?
147
- true
148
- end
149
- private :secret?
150
- end
151
-
152
- describe 'private methods' do
153
- subject { WithPrivateMethods.new }
154
-
155
- # deliberate failure
156
- it { should be_secret }
157
- end
158
- """
159
- When I run `rspec attempting_to_match_private_method_spec.rb`
160
- Then the output should contain "1 example, 1 failure"
161
- And the output should contain "expectation set on private method `secret?`"
@@ -1,84 +0,0 @@
1
- Feature: respond_to matcher
2
-
3
- Use the respond_to matcher to specify details of an object's interface. In
4
- its most basic form:
5
-
6
- ```ruby
7
- expect(obj).to respond_to(:foo) # pass if obj.respond_to?(:foo)
8
- ```
9
-
10
- You can specify that an object responds to multiple messages in a single
11
- statement with multiple arguments passed to the matcher:
12
-
13
- ```ruby
14
- expect(obj).to respond_to(:foo, :bar) # passes if obj.respond_to?(:foo) && obj.respond_to?(:bar)
15
- ```
16
-
17
- If the number of arguments accepted by the method is important to you,
18
- you can specify that as well:
19
-
20
- ```ruby
21
- expect(obj).to respond_to(:foo).with(1).argument
22
- expect(obj).to respond_to(:bar).with(2).arguments
23
- ```
24
-
25
- Note that this matcher relies entirely upon #respond_to?. If an object
26
- dynamically responds to a message via #method_missing, but does not indicate
27
- this via #respond_to?, then this matcher will give you false results.
28
-
29
- Scenario: basic usage
30
- Given a file named "respond_to_matcher_spec.rb" with:
31
- """ruby
32
- describe "a string" do
33
- it { should respond_to(:length) }
34
- it { should respond_to(:hash, :class, :to_s) }
35
- it { should_not respond_to(:to_model) }
36
- it { should_not respond_to(:compact, :flatten) }
37
-
38
- # deliberate failures
39
- it { should respond_to(:to_model) }
40
- it { should respond_to(:compact, :flatten) }
41
- it { should_not respond_to(:length) }
42
- it { should_not respond_to(:hash, :class, :to_s) }
43
-
44
- # mixed examples--String responds to :length but not :flatten
45
- # both specs should fail
46
- it { should respond_to(:length, :flatten) }
47
- it { should_not respond_to(:length, :flatten) }
48
- end
49
- """
50
- When I run `rspec respond_to_matcher_spec.rb`
51
- Then the output should contain all of these:
52
- | 10 examples, 6 failures |
53
- | expected "a string" to respond to :to_model |
54
- | expected "a string" to respond to :compact, :flatten |
55
- | expected "a string" not to respond to :length |
56
- | expected "a string" not to respond to :hash, :class, :to_s |
57
- | expected "a string" to respond to :flatten |
58
- | expected "a string" not to respond to :length |
59
-
60
- Scenario: specify arguments
61
- Given a file named "respond_to_matcher_argument_checking_spec.rb" with:
62
- """ruby
63
- describe 7 do
64
- it { should respond_to(:zero?).with(0).arguments }
65
- it { should_not respond_to(:zero?).with(1).argument }
66
-
67
- it { should respond_to(:between?).with(2).arguments }
68
- it { should_not respond_to(:between?).with(7).arguments }
69
-
70
- # deliberate failures
71
- it { should respond_to(:zero?).with(1).argument }
72
- it { should_not respond_to(:zero?).with(0).arguments }
73
-
74
- it { should respond_to(:between?).with(7).arguments }
75
- it { should_not respond_to(:between?).with(2).arguments }
76
- end
77
- """
78
- When I run `rspec respond_to_matcher_argument_checking_spec.rb`
79
- Then the output should contain all of these:
80
- | 8 examples, 4 failures |
81
- | expected 7 to respond to :zero? with 1 argument |
82
- | expected 7 not to respond to :zero? with 0 arguments |
83
- | expected 7 to respond to :between? with 7 arguments |
84
- | expected 7 not to respond to :between? with 2 arguments |