Welcome to mirror list, hosted at ThFree Co, Russian Federation.

sentence_spec.rb « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b37925abbc6a5ce9778bdd055bfdcf387cec2faa (plain)
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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Sentence, feature_category: :shared do
  delegate :to_exclusive_sentence, to: :described_class

  describe '.to_exclusive_sentence' do
    it 'calls #to_sentence on the array' do
      array = double

      expect(array).to receive(:to_sentence)

      to_exclusive_sentence(array)
    end

    it 'joins arrays with two elements correctly' do
      array = %w[foo bar]

      expect(to_exclusive_sentence(array)).to eq('foo or bar')
    end

    it 'joins arrays with more than two elements correctly' do
      array = %w[foo bar baz]

      expect(to_exclusive_sentence(array)).to eq('foo, bar, or baz')
    end

    it 'localizes the connector words' do
      array = %w[foo bar baz]

      expect(described_class).to receive(:_).with(' or ').and_return(' <1> ')
      expect(described_class).to receive(:_).with(', or ').and_return(', <2> ')
      expect(to_exclusive_sentence(array)).to eq('foo, bar, <2> baz')
    end
  end
end