Module: RSpec::Matchers::Pretty

Included in:
Be, MatchArray, Matcher
Defined in:
lib/rspec/matchers/pretty.rb

Instance Method Summary collapse

Instance Method Details

#_pretty_print(array) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rspec/matchers/pretty.rb', line 22

def _pretty_print(array)
  result = ""
  array.each_with_index do |item, index|
    if index < (array.length - 2)
      result << "#{item.inspect}, "
    elsif index < (array.length - 1)
      result << "#{item.inspect} and "
    else
      result << "#{item.inspect}"
    end
  end
  result
end

#split_words(sym) ⇒ Object



4
5
6
# File 'lib/rspec/matchers/pretty.rb', line 4

def split_words(sym)
  sym.to_s.gsub(/_/,' ')
end

#to_sentence(words) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rspec/matchers/pretty.rb', line 8

def to_sentence(words)
  words = words.map{|w| w.inspect}
  case words.length
    when 0
      ""
    when 1
      " #{words[0]}"
    when 2
      " #{words[0]} and #{words[1]}"
    else
      " #{words[0...-1].join(', ')}, and #{words[-1]}"
  end
end