Module: Pathway::Rspec::ListHelpers

Included in:
FieldListHelpers
Defined in:
lib/pathway/rspec/matchers/list_helpers.rb

Instance Method Summary collapse

Instance Method Details

#as_list(items) ⇒ Object



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

def as_list(items)
  as_sentence(items.map(&:inspect))
end

#as_sentence(items, connector: ", ", last_connector: " and ") ⇒ Object



8
9
10
11
12
13
14
# File 'lib/pathway/rspec/matchers/list_helpers.rb', line 8

def as_sentence(items, connector: ", ", last_connector: " and ")
  *rest, last = items

  result = String.new
  result << rest.join(connector) << last_connector if rest.any?
  result << last
end