Module: RuboCop::RSpec::Util

Included in:
Cop::RSpec::DescribeMethod
Defined in:
lib/rubocop/rspec/util.rb

Overview

Utility methods

Constant Summary collapse

SizeError =

Error raised by ‘Util.one` if size is less than zero or greater than one

Class.new(IndexError)

Instance Method Summary collapse

Instance Method Details

#one(array) ⇒ Object

Return only element in array if it contains exactly one member

Raises:



11
12
13
14
15
16
# File 'lib/rubocop/rspec/util.rb', line 11

def one(array)
  return array.first if array.one?

  raise SizeError,
        "expected size to be exactly 1 but size was #{array.size}"
end