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,102 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "expect(...).to match(expected)" do
4
- it_behaves_like "an RSpec matcher", :valid_value => 'ab', :invalid_value => 'bc' do
5
- let(:matcher) { match(/a/) }
6
- end
7
-
8
- it "passes when target (String) matches expected (Regexp)" do
9
- expect("string").to match(/tri/)
10
- end
11
-
12
- it "passes when target (String) matches expected (String)" do
13
- expect("string").to match("tri")
14
- end
15
-
16
- it "fails when target (String) does not match expected (Regexp)" do
17
- expect {
18
- expect("string").to match(/rings/)
19
- }.to fail
20
- end
21
-
22
- it "fails when target (String) does not match expected (String)" do
23
- expect {
24
- expect("string").to match("rings")
25
- }.to fail
26
- end
27
-
28
- it "provides message, expected and actual on failure" do
29
- matcher = match(/rings/)
30
- matcher.matches?("string")
31
- expect(matcher.failure_message).to eq "expected \"string\" to match /rings/"
32
- end
33
-
34
- it "provides a diff on failure" do
35
- allow(RSpec::Matchers.configuration).to receive(:color?).and_return(false)
36
-
37
- failure_message_that_includes_diff = %r%
38
- \s*Diff:
39
- \s*@@ -1,2 \+1,2 @@
40
- \s*-/bar/
41
- \s*\+"foo"%
42
-
43
- expect { expect("foo").to match(/bar/) }.to fail_with(failure_message_that_includes_diff)
44
- end
45
-
46
- context "when passed a data structure with matchers" do
47
- it 'passes when the matchers match' do
48
- expect(["food", 1.1]).to match([ a_string_matching(/foo/), a_value_within(0.2).of(1) ])
49
- end
50
-
51
- it 'fails when the matchers do not match' do
52
- expect {
53
- expect(["fod", 1.1]).to match([ a_string_matching(/foo/), a_value_within(0.2).of(1) ])
54
- }.to fail_with('expected ["fod", 1.1] to match [(a string matching /foo/), (a value within 0.2 of 1)]')
55
- end
56
-
57
- it 'provides a description' do
58
- description = match([ a_string_matching(/foo/), a_value_within(0.2).of(1) ]).description
59
- expect(description).to eq("match [(a string matching /foo/), (a value within 0.2 of 1)]")
60
- end
61
- end
62
- end
63
-
64
- describe "expect(...).not_to match(expected)" do
65
- it "passes when target (String) matches does not match (Regexp)" do
66
- expect("string").not_to match(/rings/)
67
- end
68
-
69
- it "passes when target (String) matches does not match (String)" do
70
- expect("string").not_to match("rings")
71
- end
72
-
73
- it "fails when target (String) matches expected (Regexp)" do
74
- expect {
75
- expect("string").not_to match(/tri/)
76
- }.to fail
77
- end
78
-
79
- it "fails when target (String) matches expected (String)" do
80
- expect {
81
- expect("string").not_to match("tri")
82
- }.to fail
83
- end
84
-
85
- it "provides message, expected and actual on failure" do
86
- matcher = match(/tri/)
87
- matcher.matches?("string")
88
- expect(matcher.failure_message_when_negated).to eq "expected \"string\" not to match /tri/"
89
- end
90
-
91
- context "when passed a data structure with matchers" do
92
- it 'passes when the matchers match' do
93
- expect(["food", 1.1]).not_to match([ a_string_matching(/fod/), a_value_within(0.2).of(1) ])
94
- end
95
-
96
- it 'fails when the matchers do not match' do
97
- expect {
98
- expect(["fod", 1.1]).not_to match([ a_string_matching(/fod/), a_value_within(0.2).of(1) ])
99
- }.to fail_with('expected ["fod", 1.1] not to match [(a string matching /fod/), (a value within 0.2 of 1)]')
100
- end
101
- end
102
- end
@@ -1,252 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class MethodOverrideObject
4
- def method
5
- :foo
6
- end
7
- end
8
-
9
- class MethodMissingObject < Struct.new(:original)
10
- undef ==
11
-
12
- def method_missing(name, *args, &block)
13
- original.__send__ name, *args, &block
14
- end
15
- end
16
-
17
- describe "operator matchers", :uses_should do
18
- describe "should ==" do
19
- it "delegates message to target" do
20
- subject = "apple"
21
- expect(subject).to receive(:==).with("apple").and_return(true)
22
- subject.should == "apple"
23
- end
24
-
25
- it "returns true on success" do
26
- subject = "apple"
27
- (subject.should == "apple").should be_truthy
28
- end
29
-
30
- it "fails when target.==(actual) returns false" do
31
- subject = "apple"
32
- expect(RSpec::Expectations).to receive(:fail_with).with(%[expected: "orange"\n got: "apple" (using ==)], "orange", "apple")
33
- subject.should == "orange"
34
- end
35
-
36
- it "works when #method is overriden" do
37
- myobj = MethodOverrideObject.new
38
- expect {
39
- myobj.should == myobj
40
- }.to_not raise_error
41
- end
42
-
43
- it "works when implemented via method_missing" do
44
- obj = Object.new
45
-
46
- myobj = MethodMissingObject.new(obj)
47
- (myobj.should == obj).nil? # just to avoid `useless use of == in void context` warning
48
- myobj.should_not == Object.new
49
- end
50
- end
51
-
52
- describe "unsupported operators", :if => RUBY_VERSION.to_f == 1.9 do
53
- it "raises an appropriate error for should != expected" do
54
- expect {
55
- "apple".should != "pear"
56
- }.to raise_error(/does not support `should != expected`. Use `should_not == expected`/)
57
- end
58
-
59
- it "raises an appropriate error for should_not != expected" do
60
- expect {
61
- "apple".should_not != "pear"
62
- }.to raise_error(/does not support `should_not != expected`. Use `should == expected`/)
63
- end
64
-
65
- it "raises an appropriate error for should !~ expected" do
66
- expect {
67
- "apple".should !~ /regex/
68
- }.to raise_error(/does not support `should !~ expected`. Use `should_not =~ expected`/)
69
- end
70
-
71
- it "raises an appropriate error for should_not !~ expected" do
72
- expect {
73
- "apple".should_not !~ /regex/
74
- }.to raise_error(/does not support `should_not !~ expected`. Use `should =~ expected`/)
75
- end
76
- end
77
-
78
- describe "should_not ==" do
79
- it "delegates message to target" do
80
- subject = "orange"
81
- expect(subject).to receive(:==).with("apple").and_return(false)
82
- subject.should_not == "apple"
83
- end
84
-
85
- it "returns true on success" do
86
- subject = "apple"
87
- (subject.should_not == "orange").should be_falsey
88
- end
89
-
90
- it "fails when target.==(actual) returns false" do
91
- subject = "apple"
92
- expect(RSpec::Expectations).to receive(:fail_with).with(%[expected not: == "apple"\n got: "apple"], "apple", "apple")
93
- subject.should_not == "apple"
94
- end
95
- end
96
-
97
- describe "should ===" do
98
- it "delegates message to target" do
99
- subject = "apple"
100
- expect(subject).to receive(:===).with("apple").and_return(true)
101
- subject.should === "apple"
102
- end
103
-
104
- it "fails when target.===(actual) returns false" do
105
- subject = "apple"
106
- expect(subject).to receive(:===).with("orange").and_return(false)
107
- expect(RSpec::Expectations).to receive(:fail_with).with(%[expected: "orange"\n got: "apple" (using ===)], "orange", "apple")
108
- subject.should === "orange"
109
- end
110
- end
111
-
112
- describe "should_not ===" do
113
- it "delegates message to target" do
114
- subject = "orange"
115
- expect(subject).to receive(:===).with("apple").and_return(false)
116
- subject.should_not === "apple"
117
- end
118
-
119
- it "fails when target.===(actual) returns false" do
120
- subject = "apple"
121
- expect(subject).to receive(:===).with("apple").and_return(true)
122
- expect(RSpec::Expectations).to receive(:fail_with).with(%[expected not: === "apple"\n got: "apple"], "apple", "apple")
123
- subject.should_not === "apple"
124
- end
125
- end
126
-
127
- describe "should =~" do
128
- it "delegates message to target" do
129
- subject = "foo"
130
- expect(subject).to receive(:=~).with(/oo/).and_return(true)
131
- subject.should =~ /oo/
132
- end
133
-
134
- it "fails when target.=~(actual) returns false" do
135
- subject = "fu"
136
- expect(subject).to receive(:=~).with(/oo/).and_return(false)
137
- expect(RSpec::Expectations).to receive(:fail_with).with(%[expected: /oo/\n got: "fu" (using =~)], /oo/, "fu")
138
- subject.should =~ /oo/
139
- end
140
- end
141
-
142
- describe "should_not =~" do
143
- it "delegates message to target" do
144
- subject = "fu"
145
- expect(subject).to receive(:=~).with(/oo/).and_return(false)
146
- subject.should_not =~ /oo/
147
- end
148
-
149
- it "fails when target.=~(actual) returns false" do
150
- subject = "foo"
151
- expect(subject).to receive(:=~).with(/oo/).and_return(true)
152
- expect(RSpec::Expectations).to receive(:fail_with).with(%[expected not: =~ /oo/\n got: "foo"], /oo/, "foo")
153
- subject.should_not =~ /oo/
154
- end
155
- end
156
-
157
- describe "should >" do
158
- it "passes if > passes" do
159
- 4.should > 3
160
- end
161
-
162
- it "fails if > fails" do
163
- expect(RSpec::Expectations).to receive(:fail_with).with(%[expected: > 5\n got: 4], 5, 4)
164
- 4.should > 5
165
- end
166
- end
167
-
168
- describe "should >=" do
169
- it "passes if actual == expected" do
170
- 4.should >= 4
171
- end
172
-
173
- it "passes if actual > expected" do
174
- 4.should >= 3
175
- end
176
-
177
- it "fails if > fails" do
178
- expect(RSpec::Expectations).to receive(:fail_with).with(%[expected: >= 5\n got: 4], 5, 4)
179
- 4.should >= 5
180
- end
181
- end
182
-
183
- describe "should <" do
184
- it "passes if < passes" do
185
- 4.should < 5
186
- end
187
-
188
- it "fails if > fails" do
189
- expect(RSpec::Expectations).to receive(:fail_with).with(%[expected: < 3\n got: 4], 3, 4)
190
- 4.should < 3
191
- end
192
- end
193
-
194
- describe "should <=" do
195
- it "passes if actual == expected" do
196
- 4.should <= 4
197
- end
198
-
199
- it "passes if actual < expected" do
200
- 4.should <= 5
201
- end
202
-
203
- it "fails if > fails" do
204
- expect(RSpec::Expectations).to receive(:fail_with).with(%[expected: <= 3\n got: 4], 3, 4)
205
- 4.should <= 3
206
- end
207
- end
208
-
209
- describe "OperatorMatcher registry" do
210
- let(:custom_klass) { Class.new }
211
- let(:custom_subklass) { Class.new(custom_klass) }
212
-
213
- after {
214
- RSpec::Matchers::BuiltIn::OperatorMatcher.unregister(custom_klass, "=~")
215
- }
216
-
217
- it "allows operator matchers to be registered for types" do
218
- RSpec::Matchers::BuiltIn::OperatorMatcher.register(custom_klass, "=~", RSpec::Matchers::BuiltIn::Match)
219
- expect(RSpec::Matchers::BuiltIn::OperatorMatcher.get(custom_klass, "=~")).to eq(RSpec::Matchers::BuiltIn::Match)
220
- end
221
-
222
- it "considers ancestors when finding an operator matcher" do
223
- RSpec::Matchers::BuiltIn::OperatorMatcher.register(custom_klass, "=~", RSpec::Matchers::BuiltIn::Match)
224
- expect(RSpec::Matchers::BuiltIn::OperatorMatcher.get(custom_subklass, "=~")).to eq(RSpec::Matchers::BuiltIn::Match)
225
- end
226
-
227
- it "returns nil if there is no matcher registered for a type" do
228
- expect(RSpec::Matchers::BuiltIn::OperatorMatcher.get(custom_klass, "=~")).to be_nil
229
- end
230
- end
231
-
232
- describe RSpec::Matchers::BuiltIn::PositiveOperatorMatcher do
233
- it "works when the target has implemented #send" do
234
- o = Object.new
235
- def o.send(*args); raise "DOH! Library developers shouldn't use #send!" end
236
- expect {
237
- o.should == o
238
- }.not_to raise_error
239
- end
240
- end
241
-
242
- describe RSpec::Matchers::BuiltIn::NegativeOperatorMatcher do
243
- it "works when the target has implemented #send" do
244
- o = Object.new
245
- def o.send(*args); raise "DOH! Library developers shouldn't use #send!" end
246
- expect {
247
- o.should_not == :foo
248
- }.not_to raise_error
249
- end
250
- end
251
- end
252
-
@@ -1,165 +0,0 @@
1
- require 'spec_helper'
2
-
3
- shared_examples_for "output_to_stream" do |stream_name|
4
- matcher_method = :"to_#{stream_name}"
5
-
6
- define_method :matcher do |*args|
7
- output(args.first).send(matcher_method)
8
- end
9
-
10
- it 'is diffable' do
11
- expect(matcher).to be_diffable
12
- end
13
-
14
- context "expect { ... }.to output.#{matcher_method}" do
15
- it "passes if the block outputs to #{stream_name}" do
16
- expect { stream.print 'foo' }.to matcher
17
- end
18
-
19
- it "fails if the block does not output to #{stream_name}" do
20
- expect {
21
- expect { }.to matcher
22
- }.to fail_with("expected block to output to #{stream_name}, but did not")
23
- end
24
- end
25
-
26
- context "expect { ... }.not_to output.#{matcher_method}" do
27
- it "passes if the block does not output to #{stream_name}" do
28
- expect { }.not_to matcher
29
- end
30
-
31
- it "fails if the block outputs to #{stream_name}" do
32
- expect {
33
- expect { stream.print 'foo' }.not_to matcher
34
- }.to fail_with("expected block to not output to #{stream_name}, but did")
35
- end
36
- end
37
-
38
- context "expect { ... }.to output('string').#{matcher_method}" do
39
- it "passes if the block outputs that string to #{stream_name}" do
40
- expect { stream.print 'foo' }.to matcher("foo")
41
- end
42
-
43
- it "fails if the block does not output to #{stream_name}" do
44
- expect {
45
- expect { }.to matcher('foo')
46
- }.to fail_with("expected block to output \"foo\" to #{stream_name}, but output nothing")
47
- end
48
-
49
- it "fails if the block outputs a different string to #{stream_name}" do
50
- expect {
51
- expect { stream.print 'food' }.to matcher('foo')
52
- }.to fail_with("expected block to output \"foo\" to #{stream_name}, but output \"food\"")
53
- end
54
- end
55
-
56
- context "expect { ... }.to_not output('string').#{matcher_method}" do
57
- it "passes if the block outputs a different string to #{stream_name}" do
58
- expect { stream.print 'food' }.to_not matcher('foo')
59
- end
60
-
61
- it "passes if the block does not output to #{stream_name}" do
62
- expect { }.to_not matcher('foo')
63
- end
64
-
65
- it "fails if the block outputs the same string to #{stream_name}" do
66
- expect {
67
- expect { stream.print 'foo' }.to_not matcher('foo')
68
- }.to fail_with("expected block to not output \"foo\" to #{stream_name}, but did")
69
- end
70
- end
71
-
72
- context "expect { ... }.to output(/regex/).#{matcher_method}" do
73
- it "passes if the block outputs a string to #{stream_name} that matches the regex" do
74
- expect { stream.print 'foo' }.to matcher(/foo/)
75
- end
76
-
77
- it "fails if the block does not output to #{stream_name}" do
78
- expect {
79
- expect { }.to matcher(/foo/)
80
- }.to fail_matching("expected block to output /foo/ to #{stream_name}, but output nothing\nDiff")
81
- end
82
-
83
- it "fails if the block outputs a string to #{stream_name} that does not match" do
84
- expect {
85
- expect { stream.print 'foo' }.to matcher(/food/)
86
- }.to fail_matching("expected block to output /food/ to #{stream_name}, but output \"foo\"\nDiff")
87
- end
88
- end
89
-
90
- context "expect { ... }.to_not output(/regex/).#{matcher_method}" do
91
- it "passes if the block outputs a string to #{stream_name} that does not match the regex" do
92
- expect { stream.print 'food' }.to_not matcher(/bar/)
93
- end
94
-
95
- it "passes if the block does not output to #{stream_name}" do
96
- expect { }.to_not matcher(/foo/)
97
- end
98
-
99
- it "fails if the block outputs a string to #{stream_name} that matches the regex" do
100
- expect {
101
- expect { stream.print 'foo' }.to_not matcher(/foo/)
102
- }.to fail_matching("expected block to not output /foo/ to #{stream_name}, but did\nDiff")
103
- end
104
- end
105
-
106
- context "expect { ... }.to output(matcher).#{matcher_method}" do
107
- it "passes if the block outputs a string to #{stream_name} that passes the given matcher" do
108
- expect { stream.print 'foo' }.to matcher(a_string_starting_with("f"))
109
- end
110
-
111
- it "fails if the block outputs a string to #{stream_name} that does not pass the given matcher" do
112
- expect {
113
- expect { stream.print 'foo' }.to matcher(a_string_starting_with("b"))
114
- }.to fail_matching("expected block to output a string starting with \"b\" to #{stream_name}, but output \"foo\"\nDiff")
115
- end
116
- end
117
-
118
- context "expect { ... }.to_not output(matcher).#{matcher_method}" do
119
- it "passes if the block does not output a string to #{stream_name} that passes the given matcher" do
120
- expect { stream.print 'foo' }.to_not matcher(a_string_starting_with("b"))
121
- end
122
-
123
- it "fails if the block outputs a string to #{stream_name} that passes the given matcher" do
124
- expect {
125
- expect { stream.print 'foo' }.to_not matcher(a_string_starting_with("f"))
126
- }.to fail_matching("expected block to not output a string starting with \"f\" to #{stream_name}, but did\nDiff")
127
- end
128
- end
129
- end
130
-
131
- module RSpec
132
- module Matchers
133
- describe "output.to_stderr matcher" do
134
- it_behaves_like("an RSpec matcher", :valid_value => lambda { warn('foo') }, :invalid_value => lambda {}) do
135
- let(:matcher) { output.to_stderr }
136
- end
137
-
138
- include_examples "output_to_stream", :stderr do
139
- let(:stream) { $stderr }
140
- end
141
- end
142
-
143
- describe "output.to_stdout matcher" do
144
- it_behaves_like("an RSpec matcher", :valid_value => lambda { print 'foo' }, :invalid_value => lambda {}) do
145
- let(:matcher) { output.to_stdout }
146
- end
147
-
148
- include_examples "output_to_stream", :stdout do
149
- let(:stream) { $stdout }
150
- end
151
- end
152
-
153
- describe "output (without `to_stdout` or `to_stderr`)" do
154
- it 'raises an error explaining the use is invalid' do
155
- expect {
156
- expect { stream.print 'foo' }.to output
157
- }.to raise_error(/must chain.*to_stdout.*to_stderr/)
158
- end
159
-
160
- it 'still provides a description (e.g. when used in a one-liner)' do
161
- expect(output("foo").description).to eq('output "foo" to some stream')
162
- end
163
- end
164
- end
165
- end