11require "spec_helper"
22
3- RSpec . describe "Integration with RSpec's #be_* matcher" , type : :integration do
3+ RSpec . describe "Integration with RSpec's #be_<predicate> matcher" , type : :integration do
44 # rubocop:disable Metrics/BlockLength
55 [ "be" , "be_a" , "be_an" ] . each do |prefix |
66 # rubocop:enable Metrics/BlockLength
2323 plain "Expected "
2424 beta %|:foo|
2525 plain " to respond to "
26- alpha %|` strong?` |
26+ alpha %|strong?|
2727 plain " or "
28- alpha %|` strongs?` |
28+ alpha %|strongs?|
2929 plain "."
3030 end
3131 } ,
4242 it "produces the correct failure message" do
4343 as_both_colored_and_uncolored do |color_enabled |
4444 snippet = <<~TEST . strip
45- hash = { foo: "bar", baz: "qux", blargh: "foz", fizz: "buzz" }
45+ hash = { foo: "bar", baz: "qux", blargh: "foz", fizz: "buzz", aaaaaa: "bbbbbb" }
4646 expect(hash).to #{ prefix } _strong
4747 TEST
4848 program = make_plain_test_program (
5757 expectation : proc {
5858 line do
5959 plain " Expected "
60- beta %|{ foo: "bar", baz: "qux", blargh: "foz", fizz: "buzz" }|
60+ beta %|{ foo: "bar", baz: "qux", blargh: "foz", fizz: "buzz", aaaaaa: "bbbbbb" }|
6161 end
6262
6363 line do
6464 plain "to respond to "
65- alpha %|` strong?` |
65+ alpha %|strong?|
6666 plain " or "
67- alpha %|` strongs?` |
67+ alpha %|strongs?|
6868 end
6969 } ,
7070 )
@@ -102,9 +102,9 @@ class Foo
102102 plain "Expected "
103103 beta %|#<Foo>|
104104 plain " to have a public method "
105- alpha %|` strong?` |
105+ alpha %|strong?|
106106 plain " or "
107- alpha %|` strongs?` |
107+ alpha %|strongs?|
108108 plain "."
109109 end
110110 } ,
@@ -147,9 +147,9 @@ class << hash
147147
148148 line do
149149 plain "to have a public method "
150- alpha %|` strong?` |
150+ alpha %|strong?|
151151 plain " or "
152- alpha %|` strongs?` |
152+ alpha %|strongs?|
153153 end
154154 } ,
155155 )
@@ -190,19 +190,19 @@ def true?; false; end
190190 plain "Expected "
191191 beta %|#<Foo>|
192192 plain " to return a truthy result for "
193- alpha %|` true?` |
193+ alpha %|true?|
194194 plain " or "
195- alpha %|` trues?` |
195+ alpha %|trues?|
196196 plain "."
197197 end
198198
199199 newline
200200
201201 line do
202202 plain "(Perhaps you want to use "
203- blue "` be(true)` "
203+ blue "be(true)"
204204 plain " or "
205- blue "` be_truthy` "
205+ blue "be_truthy"
206206 plain " instead?)"
207207 end
208208 } ,
@@ -250,18 +250,18 @@ def true?; false; end
250250
251251 line do
252252 plain "to return a truthy result for "
253- alpha %|` true?` |
253+ alpha %|true?|
254254 plain " or "
255- alpha %|` trues?` |
255+ alpha %|trues?|
256256 end
257257
258258 newline
259259
260260 line do
261261 plain "(Perhaps you want to use "
262- blue "` be(true)` "
262+ blue "be(true)"
263263 plain " or "
264- blue "` be_truthy` "
264+ blue "be_truthy"
265265 plain " instead?)"
266266 end
267267 } ,
@@ -300,9 +300,9 @@ def false?; false; end
300300 plain "Expected "
301301 beta %|#<X>|
302302 plain " to return a truthy result for "
303- alpha %|` false?` |
303+ alpha %|false?|
304304 plain " or "
305- alpha %|` falses?` |
305+ alpha %|falses?|
306306 plain "."
307307 end
308308 } ,
@@ -341,9 +341,9 @@ def y?; false; end
341341 plain "Expected "
342342 beta %|#<X>|
343343 plain " to return a truthy result for "
344- alpha %|`y?` |
344+ alpha %|y? |
345345 plain " or "
346- alpha %|` ys?` |
346+ alpha %|ys?|
347347 plain "."
348348 end
349349 } ,
@@ -392,9 +392,9 @@ def y?; false; end
392392
393393 line do
394394 plain "to return a truthy result for "
395- alpha %|`y?` |
395+ alpha %|y? |
396396 plain " or "
397- alpha %|` ys?` |
397+ alpha %|ys?|
398398 end
399399 } ,
400400 )
@@ -432,9 +432,9 @@ def ys?; false; end
432432 plain "Expected "
433433 beta %|#<X>|
434434 plain " to return a truthy result for "
435- alpha %|`y?` |
435+ alpha %|y? |
436436 plain " or "
437- alpha %|` ys?` |
437+ alpha %|ys?|
438438 plain "."
439439 end
440440 } ,
@@ -483,9 +483,9 @@ def ys?; false; end
483483
484484 line do
485485 plain "to return a truthy result for "
486- alpha %|`y?` |
486+ alpha %|y? |
487487 plain " or "
488- alpha %|` ys?` |
488+ alpha %|ys?|
489489 end
490490 } ,
491491 )
@@ -502,40 +502,92 @@ def ys?; false; end
502502 end
503503
504504 context "and returns true" do
505- it "produces the correct failure message when used in the negative" do
506- as_both_colored_and_uncolored do |color_enabled |
507- snippet = <<~TEST . strip
508- class Foo
509- def strong?; true; end
510- end
505+ context "when the inspected version of the actual value is short" do
506+ it "produces the correct failure message when used in the negative" do
507+ as_both_colored_and_uncolored do |color_enabled |
508+ snippet = <<~TEST . strip
509+ class Foo
510+ def strong?; true; end
511+ end
511512
512- expect(Foo.new).not_to #{ prefix } _strong
513- TEST
514- program = make_plain_test_program (
515- snippet ,
516- color_enabled : color_enabled ,
517- )
513+ expect(Foo.new).not_to #{ prefix } _strong
514+ TEST
515+ program = make_plain_test_program (
516+ snippet ,
517+ color_enabled : color_enabled ,
518+ )
518519
519- expected_output = build_expected_output (
520- color_enabled : color_enabled ,
521- snippet : %|expect(Foo.new).not_to #{ prefix } _strong| ,
522- expectation : proc {
523- line do
524- plain "Expected "
525- beta %|#<Foo>|
526- plain " not to return a truthy result for "
527- alpha %|`strong?`|
528- plain " or "
529- alpha %|`strongs?`|
530- plain "."
520+ expected_output = build_expected_output (
521+ color_enabled : color_enabled ,
522+ snippet : %|expect(Foo.new).not_to #{ prefix } _strong| ,
523+ expectation : proc {
524+ line do
525+ plain "Expected "
526+ beta %|#<Foo>|
527+ plain " not to return a truthy result for "
528+ alpha %|strong?|
529+ plain " or "
530+ alpha %|strongs?|
531+ plain "."
532+ end
533+ } ,
534+ )
535+
536+ expect ( program ) .
537+ to produce_output_when_run ( expected_output ) .
538+ in_color ( color_enabled ) .
539+ removing_object_ids
540+ end
541+ end
542+ end
543+
544+ context "when the inspected version of the actual value is long" do
545+ it "produces the correct failure message when used in the negative" do
546+ as_both_colored_and_uncolored do |color_enabled |
547+ snippet = <<~TEST . strip
548+ hash = {
549+ foo: "bar",
550+ baz: "qux",
551+ blargh: "foz",
552+ fizz: "buzz",
553+ aaaaaa: "bbbbbb"
554+ }
555+
556+ class << hash
557+ def ys?; true; end
531558 end
532- } ,
533- )
534559
535- expect ( program ) .
536- to produce_output_when_run ( expected_output ) .
537- in_color ( color_enabled ) .
538- removing_object_ids
560+ expect(hash).not_to #{ prefix } _y
561+ TEST
562+ program = make_plain_test_program (
563+ snippet ,
564+ color_enabled : color_enabled ,
565+ )
566+
567+ expected_output = build_expected_output (
568+ color_enabled : color_enabled ,
569+ snippet : %|expect(hash).not_to #{ prefix } _y| ,
570+ newline_before_expectation : true ,
571+ expectation : proc {
572+ line do
573+ plain " Expected "
574+ beta %|{ foo: "bar", baz: "qux", blargh: "foz", fizz: "buzz", aaaaaa: "bbbbbb" }|
575+ end
576+
577+ line do
578+ plain "not to return a truthy result for "
579+ alpha %|y?|
580+ plain " or "
581+ alpha %|ys?|
582+ end
583+ } ,
584+ )
585+
586+ expect ( program ) .
587+ to produce_output_when_run ( expected_output ) .
588+ in_color ( color_enabled ) .
589+ removing_object_ids
590+ end
539591 end
540592 end
541593 end
0 commit comments