Module: RSpec::Matchers::EnglishPhrasing
- Defined in:
- lib/rspec/matchers/english_phrasing.rb
Overview
Facilitates converting ruby objects to English phrases.
Class Method Summary collapse
-
.list(obj) ⇒ Object
when given an empty list.
-
.split_words(sym) ⇒ Object
Converts a symbol into an English expression.
Class Method Details
.list(obj) ⇒ Object
Note:
The returned string has a leading space except
when given an empty list.
Converts an object (often a collection of objects) into an English list.
list(['banana', 'kiwi', 'mango'])
#=> " \"banana\", \"kiwi\", and \"mango\""
Given an empty collection, returns the empty string.
list([]) #=> ""
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rspec/matchers/english_phrasing.rb', line 26 def self.list(obj) return " #{RSpec::Support::ObjectFormatter.format(obj)}" if !obj || Struct === obj || Hash === obj items = Array(obj).map { |w| RSpec::Support::ObjectFormatter.format(w) } case items.length when 0 "" when 1 " #{items[0]}" when 2 " #{items[0]} and #{items[1]}" else " #{items[0...-1].join(', ')}, and #{items[-1]}" end end |
.split_words(sym) ⇒ Object
Converts a symbol into an English expression.
split_words(:banana_creme_pie) #=> "banana creme pie"
9 10 11 |
# File 'lib/rspec/matchers/english_phrasing.rb', line 9 def self.split_words(sym) sym.to_s.tr('_', ' ') end |