rspec-expectations 2.11.3 → 3.11.0

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 (152) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data/.document +1 -1
  4. data/.yardopts +1 -1
  5. data/Changelog.md +1026 -21
  6. data/{License.txt → LICENSE.md} +5 -3
  7. data/README.md +174 -78
  8. data/lib/rspec/expectations/block_snippet_extractor.rb +253 -0
  9. data/lib/rspec/expectations/configuration.rb +230 -0
  10. data/lib/rspec/expectations/expectation_target.rb +130 -55
  11. data/lib/rspec/expectations/fail_with.rb +17 -33
  12. data/lib/rspec/expectations/failure_aggregator.rb +212 -0
  13. data/lib/rspec/expectations/handler.rb +163 -29
  14. data/lib/rspec/expectations/minitest_integration.rb +58 -0
  15. data/lib/rspec/expectations/syntax.rb +68 -54
  16. data/lib/rspec/expectations/version.rb +1 -1
  17. data/lib/rspec/expectations.rb +59 -24
  18. data/lib/rspec/matchers/aliased_matcher.rb +116 -0
  19. data/lib/rspec/matchers/built_in/all.rb +86 -0
  20. data/lib/rspec/matchers/built_in/base_matcher.rb +150 -20
  21. data/lib/rspec/matchers/built_in/be.rb +115 -109
  22. data/lib/rspec/matchers/built_in/be_between.rb +77 -0
  23. data/lib/rspec/matchers/built_in/be_instance_of.rb +16 -1
  24. data/lib/rspec/matchers/built_in/be_kind_of.rb +10 -1
  25. data/lib/rspec/matchers/built_in/be_within.rb +43 -17
  26. data/lib/rspec/matchers/built_in/change.rb +392 -75
  27. data/lib/rspec/matchers/built_in/compound.rb +290 -0
  28. data/lib/rspec/matchers/built_in/contain_exactly.rb +302 -0
  29. data/lib/rspec/matchers/built_in/count_expectation.rb +169 -0
  30. data/lib/rspec/matchers/built_in/cover.rb +3 -0
  31. data/lib/rspec/matchers/built_in/eq.rb +26 -8
  32. data/lib/rspec/matchers/built_in/eql.rb +19 -8
  33. data/lib/rspec/matchers/built_in/equal.rb +56 -19
  34. data/lib/rspec/matchers/built_in/exist.rb +74 -10
  35. data/lib/rspec/matchers/built_in/has.rb +141 -22
  36. data/lib/rspec/matchers/built_in/have_attributes.rb +114 -0
  37. data/lib/rspec/matchers/built_in/include.rb +175 -20
  38. data/lib/rspec/matchers/built_in/match.rb +95 -1
  39. data/lib/rspec/matchers/built_in/operators.rb +128 -0
  40. data/lib/rspec/matchers/built_in/output.rb +207 -0
  41. data/lib/rspec/matchers/built_in/raise_error.rb +212 -38
  42. data/lib/rspec/matchers/built_in/respond_to.rb +155 -29
  43. data/lib/rspec/matchers/built_in/satisfy.rb +39 -9
  44. data/lib/rspec/matchers/built_in/start_or_end_with.rb +94 -0
  45. data/lib/rspec/matchers/built_in/throw_symbol.rb +58 -14
  46. data/lib/rspec/matchers/built_in/yield.rb +252 -98
  47. data/lib/rspec/matchers/built_in.rb +47 -33
  48. data/lib/rspec/matchers/composable.rb +171 -0
  49. data/lib/rspec/matchers/dsl.rb +530 -10
  50. data/lib/rspec/matchers/english_phrasing.rb +58 -0
  51. data/lib/rspec/matchers/expecteds_for_multiple_diffs.rb +82 -0
  52. data/lib/rspec/matchers/fail_matchers.rb +42 -0
  53. data/lib/rspec/matchers/generated_descriptions.rb +15 -10
  54. data/lib/rspec/matchers/matcher_delegator.rb +35 -0
  55. data/lib/rspec/matchers/matcher_protocol.rb +105 -0
  56. data/lib/rspec/matchers.rb +604 -252
  57. data.tar.gz.sig +0 -0
  58. metadata +178 -278
  59. metadata.gz.sig +0 -0
  60. data/features/README.md +0 -49
  61. data/features/Upgrade.md +0 -53
  62. data/features/built_in_matchers/README.md +0 -90
  63. data/features/built_in_matchers/be.feature +0 -173
  64. data/features/built_in_matchers/be_within.feature +0 -46
  65. data/features/built_in_matchers/cover.feature +0 -45
  66. data/features/built_in_matchers/end_with.feature +0 -46
  67. data/features/built_in_matchers/equality.feature +0 -145
  68. data/features/built_in_matchers/exist.feature +0 -43
  69. data/features/built_in_matchers/expect_change.feature +0 -59
  70. data/features/built_in_matchers/expect_error.feature +0 -138
  71. data/features/built_in_matchers/have.feature +0 -103
  72. data/features/built_in_matchers/include.feature +0 -121
  73. data/features/built_in_matchers/match.feature +0 -50
  74. data/features/built_in_matchers/operators.feature +0 -221
  75. data/features/built_in_matchers/predicates.feature +0 -128
  76. data/features/built_in_matchers/respond_to.feature +0 -78
  77. data/features/built_in_matchers/satisfy.feature +0 -31
  78. data/features/built_in_matchers/start_with.feature +0 -46
  79. data/features/built_in_matchers/throw_symbol.feature +0 -85
  80. data/features/built_in_matchers/types.feature +0 -114
  81. data/features/built_in_matchers/yield.feature +0 -146
  82. data/features/custom_matchers/access_running_example.feature +0 -53
  83. data/features/custom_matchers/define_diffable_matcher.feature +0 -27
  84. data/features/custom_matchers/define_matcher.feature +0 -340
  85. data/features/custom_matchers/define_matcher_outside_rspec.feature +0 -38
  86. data/features/custom_matchers/define_matcher_with_fluent_interface.feature +0 -24
  87. data/features/customized_message.feature +0 -22
  88. data/features/diffing.feature +0 -85
  89. data/features/implicit_docstrings.feature +0 -52
  90. data/features/step_definitions/additional_cli_steps.rb +0 -22
  91. data/features/support/env.rb +0 -5
  92. data/features/syntax_configuration.feature +0 -68
  93. data/features/test_frameworks/test_unit.feature +0 -46
  94. data/lib/rspec/expectations/deprecation.rb +0 -38
  95. data/lib/rspec/expectations/differ.rb +0 -81
  96. data/lib/rspec/expectations/errors.rb +0 -9
  97. data/lib/rspec/expectations/extensions/array.rb +0 -9
  98. data/lib/rspec/expectations/extensions/object.rb +0 -39
  99. data/lib/rspec/expectations/extensions.rb +0 -2
  100. data/lib/rspec/matchers/be_close.rb +0 -9
  101. data/lib/rspec/matchers/built_in/have.rb +0 -108
  102. data/lib/rspec/matchers/built_in/match_array.rb +0 -45
  103. data/lib/rspec/matchers/built_in/start_and_end_with.rb +0 -48
  104. data/lib/rspec/matchers/compatibility.rb +0 -14
  105. data/lib/rspec/matchers/configuration.rb +0 -66
  106. data/lib/rspec/matchers/extensions/instance_eval_with_args.rb +0 -39
  107. data/lib/rspec/matchers/matcher.rb +0 -299
  108. data/lib/rspec/matchers/method_missing.rb +0 -12
  109. data/lib/rspec/matchers/operator_matcher.rb +0 -84
  110. data/lib/rspec/matchers/pretty.rb +0 -60
  111. data/lib/rspec-expectations.rb +0 -1
  112. data/spec/rspec/expectations/differ_spec.rb +0 -153
  113. data/spec/rspec/expectations/expectation_target_spec.rb +0 -65
  114. data/spec/rspec/expectations/extensions/kernel_spec.rb +0 -67
  115. data/spec/rspec/expectations/fail_with_spec.rb +0 -70
  116. data/spec/rspec/expectations/handler_spec.rb +0 -206
  117. data/spec/rspec/matchers/base_matcher_spec.rb +0 -60
  118. data/spec/rspec/matchers/be_close_spec.rb +0 -22
  119. data/spec/rspec/matchers/be_instance_of_spec.rb +0 -40
  120. data/spec/rspec/matchers/be_kind_of_spec.rb +0 -37
  121. data/spec/rspec/matchers/be_spec.rb +0 -452
  122. data/spec/rspec/matchers/be_within_spec.rb +0 -80
  123. data/spec/rspec/matchers/change_spec.rb +0 -528
  124. data/spec/rspec/matchers/configuration_spec.rb +0 -202
  125. data/spec/rspec/matchers/cover_spec.rb +0 -69
  126. data/spec/rspec/matchers/description_generation_spec.rb +0 -176
  127. data/spec/rspec/matchers/dsl_spec.rb +0 -57
  128. data/spec/rspec/matchers/eq_spec.rb +0 -54
  129. data/spec/rspec/matchers/eql_spec.rb +0 -41
  130. data/spec/rspec/matchers/equal_spec.rb +0 -60
  131. data/spec/rspec/matchers/exist_spec.rb +0 -110
  132. data/spec/rspec/matchers/has_spec.rb +0 -118
  133. data/spec/rspec/matchers/have_spec.rb +0 -461
  134. data/spec/rspec/matchers/include_spec.rb +0 -367
  135. data/spec/rspec/matchers/match_array_spec.rb +0 -124
  136. data/spec/rspec/matchers/match_spec.rb +0 -61
  137. data/spec/rspec/matchers/matcher_spec.rb +0 -434
  138. data/spec/rspec/matchers/matchers_spec.rb +0 -31
  139. data/spec/rspec/matchers/method_missing_spec.rb +0 -24
  140. data/spec/rspec/matchers/operator_matcher_spec.rb +0 -221
  141. data/spec/rspec/matchers/raise_error_spec.rb +0 -344
  142. data/spec/rspec/matchers/respond_to_spec.rb +0 -295
  143. data/spec/rspec/matchers/satisfy_spec.rb +0 -44
  144. data/spec/rspec/matchers/start_with_end_with_spec.rb +0 -182
  145. data/spec/rspec/matchers/throw_symbol_spec.rb +0 -116
  146. data/spec/rspec/matchers/yield_spec.rb +0 -402
  147. data/spec/spec_helper.rb +0 -27
  148. data/spec/support/classes.rb +0 -56
  149. data/spec/support/in_sub_process.rb +0 -31
  150. data/spec/support/matchers.rb +0 -22
  151. data/spec/support/ruby_version.rb +0 -10
  152. data/spec/support/shared_examples.rb +0 -13
@@ -1,182 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe "should start_with" do
4
- it_behaves_like "an RSpec matcher", :valid_value => "ab", :invalid_value => "bc" do
5
- let(:matcher) { start_with("a") }
6
- end
7
-
8
- context "with a string" do
9
- it "passes if it matches the start of the actual string" do
10
- "this string".should start_with "this str"
11
- end
12
-
13
- it "fails if it does not match the start of the actual string" do
14
- expect {
15
- "this string".should start_with "that str"
16
- }.to fail_with("expected \"this string\" to start with \"that str\"")
17
- end
18
- end
19
-
20
- context "with an array" do
21
- it "passes if it is the first element of the array" do
22
- [0, 1, 2].should start_with 0
23
- end
24
-
25
- it "passes if the first elements of the array match" do
26
- [0, 1, 2].should start_with 0, 1
27
- end
28
-
29
- it "fails if it does not match the first element of the array" do
30
- expect {
31
- [0, 1, 2].should start_with 2
32
- }.to fail_with("expected [0, 1, 2] to start with 2")
33
- end
34
-
35
- it "fails if it the first elements of the array do not match" do
36
- expect {
37
- [0, 1, 2].should start_with 1, 2
38
- }.to fail_with("expected [0, 1, 2] to start with [1, 2]")
39
- end
40
- end
41
-
42
- context "with an object that does not respond to :[]" do
43
- it "raises an ArgumentError" do
44
- expect { Object.new.should start_with 0 }.to raise_error(ArgumentError, /does not respond to :\[\]/)
45
- end
46
- end
47
-
48
- context "with a hash" do
49
- it "raises an ArgumentError if trying to match more than one element" do
50
- expect{
51
- {:a => 'b', :b => 'b', :c => 'c'}.should start_with({:a => 'b', :b => 'b'})
52
- }.to raise_error(ArgumentError, /does not have ordered elements/)
53
- end
54
- end
55
- end
56
-
57
- describe "should_not start_with" do
58
- context "with a string" do
59
- it "passes if it does not match the start of the actual string" do
60
- "this string".should_not start_with "that str"
61
- end
62
-
63
- it "fails if it does match the start of the actual string" do
64
- expect {
65
- "this string".should_not start_with "this str"
66
- }.to fail_with("expected \"this string\" not to start with \"this str\"")
67
- end
68
- end
69
-
70
- context "with an array" do
71
- it "passes if it is not the first element of the array" do
72
- [0, 1, 2].should_not start_with 2
73
- end
74
-
75
- it "passes if the first elements of the array do not match" do
76
- [0, 1, 2].should_not start_with 1, 2
77
- end
78
-
79
- it "fails if it matches the first element of the array" do
80
- expect {
81
- [0, 1, 2].should_not start_with 0
82
- }.to fail_with("expected [0, 1, 2] not to start with 0")
83
- end
84
-
85
- it "fails if it the first elements of the array match" do
86
- expect {
87
- [0, 1, 2].should_not start_with 0, 1
88
- }.to fail_with("expected [0, 1, 2] not to start with [0, 1]")
89
- end
90
- end
91
- end
92
-
93
- describe "should end_with" do
94
- it_behaves_like "an RSpec matcher", :valid_value => "ab", :invalid_value => "bc" do
95
- let(:matcher) { end_with("b") }
96
- end
97
-
98
- context "with a string" do
99
- it "passes if it matches the end of the actual string" do
100
- "this string".should end_with "is string"
101
- end
102
-
103
- it "fails if it does not match the end of the actual string" do
104
- expect {
105
- "this string".should end_with "is stringy"
106
- }.to fail_with("expected \"this string\" to end with \"is stringy\"")
107
- end
108
- end
109
-
110
- context "with an array" do
111
- it "passes if it is the last element of the array" do
112
- [0, 1, 2].should end_with 2
113
- end
114
-
115
- it "passes if the last elements of the array match" do
116
- [0, 1, 2].should end_with [1, 2]
117
- end
118
-
119
- it "fails if it does not match the last element of the array" do
120
- expect {
121
- [0, 1, 2].should end_with 1
122
- }.to fail_with("expected [0, 1, 2] to end with 1")
123
- end
124
-
125
- it "fails if it the last elements of the array do not match" do
126
- expect {
127
- [0, 1, 2].should end_with [0, 1]
128
- }.to fail_with("expected [0, 1, 2] to end with [0, 1]")
129
- end
130
- end
131
-
132
- context "with an object that does not respond to :[]" do
133
- it "should raise an error if expected value can't be indexed'" do
134
- expect { Object.new.should end_with 0 }.to raise_error(ArgumentError, /does not respond to :\[\]/)
135
- end
136
- end
137
-
138
- context "with a hash" do
139
- it "raises an ArgumentError if trying to match more than one element" do
140
- expect{
141
- {:a => 'b', :b => 'b', :c => 'c'}.should end_with({:a => 'b', :b =>'b'})
142
- }.to raise_error(ArgumentError, /does not have ordered elements/)
143
- end
144
- end
145
-
146
- end
147
-
148
- describe "should_not end_with" do
149
- context "with a sting" do
150
- it "passes if it does not match the end of the actual string" do
151
- "this string".should_not end_with "stringy"
152
- end
153
-
154
- it "fails if it matches the end of the actual string" do
155
- expect {
156
- "this string".should_not end_with "string"
157
- }.to fail_with("expected \"this string\" not to end with \"string\"")
158
- end
159
- end
160
-
161
- context "an array" do
162
- it "passes if it is not the last element of the array" do
163
- [0, 1, 2].should_not end_with 1
164
- end
165
-
166
- it "passes if the last elements of the array do not match" do
167
- [0, 1, 2].should_not end_with [0, 1]
168
- end
169
-
170
- it "fails if it matches the last element of the array" do
171
- expect {
172
- [0, 1, 2].should_not end_with 2
173
- }.to fail_with("expected [0, 1, 2] not to end with 2")
174
- end
175
-
176
- it "fails if it the last elements of the array match" do
177
- expect {
178
- [0, 1, 2].should_not end_with [1, 2]
179
- }.to fail_with("expected [0, 1, 2] not to end with [1, 2]")
180
- end
181
- end
182
- end
@@ -1,116 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module RSpec::Matchers::BuiltIn
4
- describe ThrowSymbol do
5
- it_behaves_like("an RSpec matcher", :valid_value => lambda { throw :foo },
6
- :invalid_value => lambda { }) do
7
- let(:matcher) { throw_symbol(:foo) }
8
- end
9
-
10
- describe "with no args" do
11
- before(:each) { @matcher = throw_symbol }
12
-
13
- it "matches if any Symbol is thrown" do
14
- @matcher.matches?(lambda{ throw :sym }).should be_true
15
- end
16
- it "matches if any Symbol is thrown with an arg" do
17
- @matcher.matches?(lambda{ throw :sym, "argument" }).should be_true
18
- end
19
- it "does not match if no Symbol is thrown" do
20
- @matcher.matches?(lambda{ }).should be_false
21
- end
22
- it "provides a failure message" do
23
- @matcher.matches?(lambda{})
24
- @matcher.failure_message_for_should.should == "expected a Symbol to be thrown, got nothing"
25
- end
26
- it "provides a negative failure message" do
27
- @matcher.matches?(lambda{ throw :sym})
28
- @matcher.failure_message_for_should_not.should == "expected no Symbol to be thrown, got :sym"
29
- end
30
- end
31
-
32
- describe "with a symbol" do
33
- before(:each) { @matcher = throw_symbol(:sym) }
34
-
35
- it "matches if correct Symbol is thrown" do
36
- @matcher.matches?(lambda{ throw :sym }).should be_true
37
- end
38
- it "matches if correct Symbol is thrown with an arg" do
39
- @matcher.matches?(lambda{ throw :sym, "argument" }).should be_true
40
- end
41
- it "does not match if no Symbol is thrown" do
42
- @matcher.matches?(lambda{ }).should be_false
43
- end
44
- it "does not match if correct Symbol is thrown" do
45
- @matcher.matches?(lambda{ throw :other_sym }).should be_false
46
- end
47
- it "provides a failure message when no Symbol is thrown" do
48
- @matcher.matches?(lambda{})
49
- @matcher.failure_message_for_should.should == "expected :sym to be thrown, got nothing"
50
- end
51
- it "provides a failure message when wrong Symbol is thrown" do
52
- @matcher.matches?(lambda{ throw :other_sym })
53
- @matcher.failure_message_for_should.should == "expected :sym to be thrown, got :other_sym"
54
- end
55
- it "provides a negative failure message" do
56
- @matcher.matches?(lambda{ throw :sym })
57
- @matcher.failure_message_for_should_not.should == "expected :sym not to be thrown, got :sym"
58
- end
59
- it "only matches NameErrors raised by uncaught throws" do
60
- expect {
61
- @matcher.matches?(lambda{ sym }).should be_false
62
- }.to raise_error(NameError)
63
- end
64
- end
65
-
66
- describe "with a symbol and an arg" do
67
- before(:each) { @matcher = throw_symbol(:sym, "a") }
68
-
69
- it "matches if correct Symbol and args are thrown" do
70
- @matcher.matches?(lambda{ throw :sym, "a" }).should be_true
71
- end
72
- it "does not match if nothing is thrown" do
73
- @matcher.matches?(lambda{ }).should be_false
74
- end
75
- it "does not match if other Symbol is thrown" do
76
- @matcher.matches?(lambda{ throw :other_sym, "a" }).should be_false
77
- end
78
- it "does not match if no arg is thrown" do
79
- @matcher.matches?(lambda{ throw :sym }).should be_false
80
- end
81
- it "does not match if wrong arg is thrown" do
82
- @matcher.matches?(lambda{ throw :sym, "b" }).should be_false
83
- end
84
- it "provides a failure message when no Symbol is thrown" do
85
- @matcher.matches?(lambda{})
86
- @matcher.failure_message_for_should.should == %q[expected :sym with "a" to be thrown, got nothing]
87
- end
88
- it "provides a failure message when wrong Symbol is thrown" do
89
- @matcher.matches?(lambda{ throw :other_sym })
90
- @matcher.failure_message_for_should.should == %q[expected :sym with "a" to be thrown, got :other_sym]
91
- end
92
- it "provides a failure message when wrong arg is thrown" do
93
- @matcher.matches?(lambda{ throw :sym, "b" })
94
- @matcher.failure_message_for_should.should == %q[expected :sym with "a" to be thrown, got :sym with "b"]
95
- end
96
- it "provides a failure message when no arg is thrown" do
97
- @matcher.matches?(lambda{ throw :sym })
98
- @matcher.failure_message_for_should.should == %q[expected :sym with "a" to be thrown, got :sym with no argument]
99
- end
100
- it "provides a negative failure message" do
101
- @matcher.matches?(lambda{ throw :sym })
102
- @matcher.failure_message_for_should_not.should == %q[expected :sym with "a" not to be thrown, got :sym with no argument]
103
- end
104
- it "only matches NameErrors raised by uncaught throws" do
105
- expect {
106
- @matcher.matches?(lambda{ sym }).should be_false
107
- }.to raise_error(NameError)
108
- end
109
- it "raises other errors" do
110
- expect {
111
- @matcher.matches?(lambda { raise "Boom" })
112
- }.to raise_error(/Boom/)
113
- end
114
- end
115
- end
116
- end
@@ -1,402 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module YieldHelpers
4
- # these helpers are prefixed with an underscore to prevent
5
- # collisions with the matchers (some of which have the same names)
6
- def _dont_yield
7
- end
8
-
9
- def _yield_with_no_args
10
- yield
11
- end
12
-
13
- def _yield_with_args(*args)
14
- yield(*args)
15
- end
16
- end
17
-
18
- class InstanceEvaler
19
- include RSpec::Matchers::Extensions::InstanceEvalWithArgs
20
-
21
- def yield_with_no_args(&block)
22
- instance_eval_with_args(&block)
23
- end
24
-
25
- def yield_with_args(*args, &block)
26
- instance_eval_with_args(*args, &block)
27
- end
28
-
29
- def each_arg(*args, &block)
30
- args.each do |arg|
31
- instance_eval_with_args(arg, &block)
32
- end
33
- end
34
- end
35
-
36
- describe "yield_control matcher" do
37
- include YieldHelpers
38
- extend YieldHelpers
39
-
40
- it_behaves_like "an RSpec matcher",
41
- :valid_value => lambda { |b| _yield_with_no_args(&b) },
42
- :invalid_value => lambda { |b| _dont_yield(&b) } do
43
- let(:matcher) { yield_control }
44
- end
45
-
46
- it 'has a description' do
47
- yield_control.description.should eq("yield control")
48
- end
49
-
50
- describe "expect {...}.to yield_control" do
51
- it 'passes if the block yields, regardless of the number of yielded arguments' do
52
- expect { |b| _yield_with_no_args(&b) }.to yield_control
53
- expect { |b| _yield_with_args(1, 2, &b) }.to yield_control
54
- end
55
-
56
- it 'passes if the block yields using instance_eval' do
57
- expect { |b| InstanceEvaler.new.yield_with_no_args(&b) }.to yield_control
58
- end
59
-
60
- it 'fails if the block does not yield' do
61
- expect {
62
- expect { |b| _dont_yield(&b) }.to yield_control
63
- }.to fail_with(/expected given block to yield control/)
64
- end
65
-
66
- it 'raises an error if it yields multiple times' do
67
- expect {
68
- expect { |b| [1, 2].each(&b) }.to yield_control
69
- }.to raise_error(/not designed.*yields multiple times/)
70
- end
71
- end
72
-
73
- describe "expect {...}.not_to yield_control" do
74
- it 'passes if the block does not yield' do
75
- expect { |b| _dont_yield(&b) }.not_to yield_control
76
- end
77
-
78
- it 'fails if the block does yield' do
79
- expect {
80
- expect { |b| _yield_with_no_args(&b) }.not_to yield_control
81
- }.to fail_with(/expected given block not to yield control/)
82
- end
83
-
84
- it 'fails if the expect block does not accept an argument' do
85
- expect {
86
- expect { }.not_to yield_control
87
- }.to raise_error(/expect block must accept an argument/)
88
- end
89
-
90
- it 'raises an error if the expect block arg is not passed to a method as a block' do
91
- expect {
92
- expect { |b| }.not_to yield_control
93
- }.to raise_error(/must pass the argument.*as a block/)
94
- end
95
- end
96
- end
97
-
98
- describe "yield_with_no_args matcher" do
99
- include YieldHelpers
100
- extend YieldHelpers
101
-
102
- it_behaves_like "an RSpec matcher",
103
- :valid_value => lambda { |b| _yield_with_no_args(&b) },
104
- :invalid_value => lambda { |b| _dont_yield(&b) } do
105
- let(:matcher) { yield_with_no_args }
106
- end
107
-
108
- it 'has a description' do
109
- yield_with_no_args.description.should eq("yield with no args")
110
- end
111
-
112
- describe "expect {...}.to yield_with_no_args" do
113
- it 'passes if the block yields with no args' do
114
- expect { |b| _yield_with_no_args(&b) }.to yield_with_no_args
115
- end
116
-
117
- it 'passes if the block yields with no args using instance_eval' do
118
- expect { |b| InstanceEvaler.new.yield_with_no_args(&b) }.to yield_with_no_args
119
- end
120
-
121
- it 'fails if the block does not yield' do
122
- expect {
123
- expect { |b| _dont_yield(&b) }.to yield_with_no_args
124
- }.to fail_with(/expected given block to yield with no arguments, but did not yield/)
125
- end
126
-
127
- it 'fails if the block yields with args' do
128
- expect {
129
- expect { |b| _yield_with_args(1, &b) }.to yield_with_no_args
130
- }.to fail_with(/expected given block to yield with no arguments, but yielded with arguments/)
131
- end
132
-
133
- it 'raises an error if it yields multiple times' do
134
- expect {
135
- expect { |b| [1, 2].each(&b) }.to yield_with_no_args
136
- }.to raise_error(/not designed.*yields multiple times/)
137
- end
138
- end
139
-
140
- describe "expect {...}.not_to yield_with_no_args" do
141
- it "passes if the block does not yield" do
142
- expect { |b| _dont_yield(&b) }.not_to yield_with_no_args
143
- end
144
-
145
- it "passes if the block yields with args" do
146
- expect { |b| _yield_with_args(1, &b) }.not_to yield_with_no_args
147
- end
148
-
149
- it "fails if the block yields with no args" do
150
- expect {
151
- expect { |b| _yield_with_no_args(&b) }.not_to yield_with_no_args
152
- }.to fail_with(/expected given block not to yield with no arguments, but did/)
153
- end
154
-
155
- it 'fails if the expect block does not accept an argument' do
156
- expect {
157
- expect { }.not_to yield_with_no_args
158
- }.to raise_error(/expect block must accept an argument/)
159
- end
160
-
161
- it 'raises an error if the expect block arg is not passed to a method as a block' do
162
- expect {
163
- expect { |b| }.not_to yield_with_no_args
164
- }.to raise_error(/must pass the argument.*as a block/)
165
- end
166
- end
167
- end
168
-
169
- describe "yield_with_args matcher" do
170
- include YieldHelpers
171
- extend YieldHelpers
172
-
173
- it_behaves_like "an RSpec matcher",
174
- :valid_value => lambda { |b| _yield_with_args(1, &b) },
175
- :invalid_value => lambda { |b| _dont_yield(&b) } do
176
- let(:matcher) { yield_with_args }
177
- end
178
-
179
- it 'has a description' do
180
- yield_with_args.description.should eq("yield with args")
181
- yield_with_args(1, 3).description.should eq("yield with args(1, 3)")
182
- end
183
-
184
- describe "expect {...}.to yield_with_args" do
185
- it 'passes if the block yields with arguments' do
186
- expect { |b| _yield_with_args(1, &b) }.to yield_with_args
187
- end
188
-
189
- it 'fails if the block does not yield' do
190
- expect {
191
- expect { |b| _dont_yield(&b) }.to yield_with_args
192
- }.to fail_with(/expected given block to yield with arguments, but did not yield/)
193
- end
194
-
195
- it 'fails if the block yields with no arguments' do
196
- expect {
197
- expect { |b| _yield_with_no_args(&b) }.to yield_with_args
198
- }.to fail_with(/expected given block to yield with arguments, but yielded with no arguments/)
199
- end
200
-
201
- it 'raises an error if it yields multiple times' do
202
- expect {
203
- expect { |b| [1, 2].each(&b) }.to yield_with_args
204
- }.to raise_error(/not designed.*yields multiple times/)
205
- end
206
- end
207
-
208
- describe "expect {...}.not_to yield_with_args" do
209
- it 'fails if the block yields with arguments' do
210
- expect {
211
- expect { |b| _yield_with_args(1, &b) }.not_to yield_with_args
212
- }.to fail_with(/expected given block not to yield with arguments, but did/)
213
- end
214
-
215
- it 'passes if the block does not yield' do
216
- expect { |b| _dont_yield(&b) }.not_to yield_with_args
217
- end
218
-
219
- it 'passes if the block yields with no arguments' do
220
- expect { |b| _yield_with_no_args(&b) }.not_to yield_with_args
221
- end
222
-
223
- it 'fails if the expect block does not accept an argument' do
224
- expect {
225
- expect { }.not_to yield_with_args
226
- }.to raise_error(/expect block must accept an argument/)
227
- end
228
-
229
- it 'raises an error if the expect block arg is not passed to a method as a block' do
230
- expect {
231
- expect { |b| }.not_to yield_with_args
232
- }.to raise_error(/must pass the argument.*as a block/)
233
- end
234
- end
235
-
236
- describe "expect {...}.to yield_with_args(3, 17)" do
237
- it 'passes if the block yields with the given arguments' do
238
- expect { |b| _yield_with_args(3, 17, &b) }.to yield_with_args(3, 17)
239
- end
240
-
241
- it 'passes if the block yields with the given arguments using instance_eval' do
242
- expect { |b| InstanceEvaler.new.yield_with_args(3, 17, &b) }.to yield_with_args(3, 17)
243
- end
244
-
245
- it 'fails if the block does not yield' do
246
- expect {
247
- expect { |b| _dont_yield(&b) }.to yield_with_args(3, 17)
248
- }.to fail_with(/expected given block to yield with arguments, but did not yield/)
249
- end
250
-
251
- it 'fails if the block yields with no arguments' do
252
- expect {
253
- expect { |b| _yield_with_no_args(&b) }.to yield_with_args(3, 17)
254
- }.to fail_with(/expected given block to yield with arguments, but yielded with unexpected arguments/)
255
- end
256
-
257
- it 'fails if the block yields with different arguments' do
258
- expect {
259
- expect { |b| _yield_with_args("a", "b", &b) }.to yield_with_args("a", "c")
260
- }.to fail_with(/expected given block to yield with arguments, but yielded with unexpected arguments/)
261
- end
262
- end
263
-
264
- describe "expect {...}.not_to yield_with_args(3, 17)" do
265
- it 'passes if the block yields with different arguments' do
266
- expect { |b| _yield_with_args("a", "b", &b) }.not_to yield_with_args("a", "c")
267
- end
268
-
269
- it 'fails if the block yields with the given arguments' do
270
- expect {
271
- expect { |b| _yield_with_args("a", "b", &b) }.not_to yield_with_args("a", "b")
272
- }.to fail_with(/expected given block not to yield with arguments, but yielded with expected arguments/)
273
- end
274
- end
275
-
276
- describe "expect {...}.to yield_with_args(/reg/, /ex/)" do
277
- it "passes if the block yields strings matching the regexes" do
278
- expect { |b| _yield_with_args("regular", "expression", &b) }.to yield_with_args(/reg/, /ex/)
279
- end
280
-
281
- it "fails if the block yields strings that do not match the regexes" do
282
- expect {
283
- expect { |b| _yield_with_args("no", "match", &b) }.to yield_with_args(/reg/, /ex/)
284
- }.to fail_with(/expected given block to yield with arguments, but yielded with unexpected arguments/)
285
- end
286
- end
287
-
288
- describe "expect {...}.to yield_with_args(String, Fixnum)" do
289
- it "passes if the block yields objects of the given types" do
290
- expect { |b| _yield_with_args("string", 15, &b) }.to yield_with_args(String, Fixnum)
291
- end
292
-
293
- it "passes if the block yields the given types" do
294
- expect { |b| _yield_with_args(String, Fixnum, &b) }.to yield_with_args(String, Fixnum)
295
- end
296
-
297
- it "fails if the block yields objects of different types" do
298
- expect {
299
- expect { |b| _yield_with_args(15, "string", &b) }.to yield_with_args(String, Fixnum)
300
- }.to fail_with(/expected given block to yield with arguments, but yielded with unexpected arguments/)
301
- end
302
- end
303
- end
304
-
305
- describe "yield_successive_args matcher" do
306
- include YieldHelpers
307
- extend YieldHelpers
308
-
309
- it_behaves_like "an RSpec matcher",
310
- :valid_value => lambda { |b| [1, 2].each(&b) },
311
- :invalid_value => lambda { |b| _dont_yield(&b) } do
312
- let(:matcher) { yield_successive_args(1, 2) }
313
- end
314
-
315
- it 'has a description' do
316
- yield_successive_args(1, 3).description.should eq("yield successive args(1, 3)")
317
- yield_successive_args([:a, 1], [:b, 2]).description.should eq("yield successive args([:a, 1], [:b, 2])")
318
- end
319
-
320
- describe "expect {...}.to yield_successive_args([:a, 1], [:b, 2])" do
321
- it 'passes when the block successively yields the given args' do
322
- expect { |b| [ [:a, 1], [:b, 2] ].each(&b) }.to yield_successive_args([:a, 1], [:b, 2])
323
- end
324
-
325
- it 'fails when the block does not yield that many times' do
326
- expect {
327
- expect { |b| [[:a, 1]].each(&b) }.to yield_successive_args([:a, 1], [:b, 2])
328
- }.to fail_with(/but yielded with unexpected arguments/)
329
- end
330
-
331
- it 'fails when the block yields the right number of times but with different arguments' do
332
- expect {
333
- expect { |b| [ [:a, 1], [:b, 3] ].each(&b) }.to yield_successive_args([:a, 1], [:b, 2])
334
- }.to fail_with(/but yielded with unexpected arguments/)
335
- end
336
- end
337
-
338
- describe "expect {...}.to yield_successive_args(1, 2, 3)" do
339
- it 'passes when the block successively yields the given args' do
340
- expect { |b| [1, 2, 3].each(&b) }.to yield_successive_args(1, 2, 3)
341
- end
342
-
343
- it 'passes when the block successively yields the given args using instance_eval' do
344
- expect { |b| InstanceEvaler.new.each_arg(1, 2, 3, &b) }.to yield_successive_args(1, 2, 3)
345
- end
346
-
347
- it 'fails when the block does not yield the expected args' do
348
- expect {
349
- expect { |b| [1, 2, 4].each(&b) }.to yield_successive_args([:a, 1], [:b, 2])
350
- }.to fail_with(/but yielded with unexpected arguments/)
351
- end
352
- end
353
-
354
- describe "expect {...}.not_to yield_successive_args(1, 2, 3)" do
355
- it 'passes when the block does not yield' do
356
- expect { |b| _dont_yield(&b) }.not_to yield_successive_args(1, 2, 3)
357
- end
358
-
359
- it 'passes when the block yields the wrong number of times' do
360
- expect { |b| [1, 2].each(&b) }.not_to yield_successive_args(1, 2, 3)
361
- end
362
-
363
- it 'passes when the block yields the wrong arguments' do
364
- expect { |b| [1, 2, 4].each(&b) }.not_to yield_successive_args(1, 2, 3)
365
- end
366
-
367
- it 'fails when the block yields the given arguments' do
368
- expect {
369
- expect { |b| [1, 2, 3].each(&b) }.not_to yield_successive_args(1, 2, 3)
370
- }.to fail_with(/expected given block not to yield successively/)
371
- end
372
-
373
- it 'fails if the expect block does not accept an argument' do
374
- expect {
375
- expect { }.not_to yield_successive_args(1, 2, 3)
376
- }.to raise_error(/expect block must accept an argument/)
377
- end
378
-
379
- it 'raises an error if the expect block arg is not passed to a method as a block' do
380
- expect {
381
- expect { |b| }.not_to yield_successive_args(1, 2, 3)
382
- }.to raise_error(/must pass the argument.*as a block/)
383
- end
384
- end
385
-
386
- describe "expect {...}.to yield_successive_args(String, Fixnum)" do
387
- it "passes if the block successively yields objects of the given types" do
388
- expect { |b| ["string", 15].each(&b) }.to yield_successive_args(String, Fixnum)
389
- end
390
-
391
- it "passes if the block yields the given types" do
392
- expect { |b| [String, Fixnum].each(&b) }.to yield_successive_args(String, Fixnum)
393
- end
394
-
395
- it "fails if the block yields objects of different types" do
396
- expect {
397
- expect { |b| [15, "string"].each(&b) }.to yield_successive_args(String, Fixnum)
398
- }.to fail_with(/expected given block to yield successively with arguments/)
399
- end
400
- end
401
- end
402
-