Sha256: 41f4660fd5a98eb7ad192ea6835c7096a3199f75a62d9154205bc84fda3aaf15

Contents?: true

Size: 481 Bytes

Versions: 47

Compression:

Stored size: 481 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module RSpec
    # Utility methods
    module Util
      # Error raised by `Util.one` if size is less than zero or greater than one
      SizeError = Class.new(IndexError)

      # Return only element in array if it contains exactly one member
      def one(array)
        return array.first if array.one?

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

Version data entries

47 entries across 47 versions & 1 rubygems

Version Path
rubocop-rspec-1.38.1 lib/rubocop/rspec/util.rb
rubocop-rspec-1.38.0 lib/rubocop/rspec/util.rb
rubocop-rspec-1.37.1 lib/rubocop/rspec/util.rb
rubocop-rspec-1.37.0 lib/rubocop/rspec/util.rb
rubocop-rspec-1.36.0 lib/rubocop/rspec/util.rb
rubocop-rspec-1.35.0 lib/rubocop/rspec/util.rb
rubocop-rspec-1.34.1 lib/rubocop/rspec/util.rb
rubocop-rspec-1.34.0 lib/rubocop/rspec/util.rb
rubocop-rspec-1.33.0 lib/rubocop/rspec/util.rb
rubocop-rspec-1.32.0 lib/rubocop/rspec/util.rb
rubocop-rspec-1.31.0 lib/rubocop/rspec/util.rb
rubocop-rspec-1.30.1 lib/rubocop/rspec/util.rb
rubocop-rspec-1.30.0 lib/rubocop/rspec/util.rb
rubocop-rspec-1.29.1 lib/rubocop/rspec/util.rb
rubocop-rspec-1.29.0 lib/rubocop/rspec/util.rb
rubocop-rspec-1.28.0 lib/rubocop/rspec/util.rb
rubocop-rspec-1.27.0 lib/rubocop/rspec/util.rb
rubocop-rspec-1.26.0 lib/rubocop/rspec/util.rb
rubocop-rspec-1.25.1 lib/rubocop/rspec/util.rb
rubocop-rspec-1.25.0 lib/rubocop/rspec/util.rb