File: english_phrasing_spec.rb

package info (click to toggle)
ruby-rspec 3.5.0c3e0m0s0-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 6,312 kB
  • ctags: 4,788
  • sloc: ruby: 62,572; sh: 785; makefile: 100
file content (81 lines) | stat: -rw-r--r-- 2,522 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
module RSpec
  module Matchers
    RSpec.describe EnglishPhrasing do
      describe ".split_words" do
        it "replaces underscores with spaces" do
          expect(
            described_class.split_words(:banana_creme_pie)
          ).to eq("banana creme pie")
        end

        it "first casts its argument to string" do
          arg = double(:to_s => "banana")
          expect(described_class.split_words(arg)).to eq("banana")
        end
      end

      describe ".list" do
        context "given nil" do
          it "returns value from inspect, and a leading space" do
            expect(described_class.list(nil)).to eq(" nil")
          end
        end

        context "given a Struct" do
          it "returns value from inspect, and a leading space" do
            banana = Struct.new("Banana", :flavor).new
            expect(
              described_class.list(banana)
            ).to eq(" #{banana.inspect}")
          end
        end

        context "given an Enumerable" do
          before do
            allow(RSpec::Support::ObjectFormatter).to(
              receive(:format).and_return("Banana")
            )
          end

          context "with zero items" do
            it "returns the empty string" do
              expect(described_class.list([])).to eq("")
            end
          end

          context "with one item" do
            let(:list) { [double] }
            it "returns description, and a leading space" do
              expect(described_class.list(list)).to eq(" Banana")
              expect(RSpec::Support::ObjectFormatter).to(
                have_received(:format).once
              )
            end
          end

          context "with two items" do
            let(:list) { [double, double] }
            it "returns descriptions, and a leading space" do
              expect(described_class.list(list)).to eq(" Banana and Banana")
              expect(RSpec::Support::ObjectFormatter).to(
                have_received(:format).twice
              )
            end
          end

          context "with three items" do
            let(:list) { [double, double, double] }
            it "returns descriptions, and a leading space" do
              expect(
                described_class.list(list)
              ).to eq(" Banana, Banana, and Banana")
              expect(RSpec::Support::ObjectFormatter).to(
                have_received(:format).exactly(3).times
              )
            end
          end
        end
      end
    end
  end
end