Module: RSpec::Matchers::Pretty Private

Included in:
BuiltIn::BaseMatcher, DSL::Matcher
Defined in:
lib/rspec/matchers/pretty.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Contains logic to facilitate converting ruby symbols and objects to english phrases.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.split_words(sym) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Converts a symbol into an english expression.



9
10
11
# File 'lib/rspec/matchers/pretty.rb', line 9

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

Instance Method Details

#nameObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Provides a name for the matcher.



45
46
47
# File 'lib/rspec/matchers/pretty.rb', line 45

def name
  defined?(@name) ? @name : underscore(self.class.name.split("::").last)
end

#to_sentence(words) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Converts a collection of objects into an english expression.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rspec/matchers/pretty.rb', line 16

def to_sentence(words)
  return " #{words.inspect}" unless words
  words = Array(words).map { |w| to_word(w) }
  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

#to_word(item) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Converts the given item to string suitable for use in a list expression.



33
34
35
# File 'lib/rspec/matchers/pretty.rb', line 33

def to_word(item)
  is_matcher_with_description?(item) ? item.description : item.inspect
end