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.24.0 lib/rubocop/rspec/util.rb
rubocop-rspec-1.23.0 lib/rubocop/rspec/util.rb
rubocop-rspec-1.22.2 lib/rubocop/rspec/util.rb
rubocop-rspec-1.22.1 lib/rubocop/rspec/util.rb
rubocop-rspec-1.22.0 lib/rubocop/rspec/util.rb
rubocop-rspec-1.21.0 lib/rubocop/rspec/util.rb
rubocop-rspec-1.20.1 lib/rubocop/rspec/util.rb
rubocop-rspec-1.20.0 lib/rubocop/rspec/util.rb
rubocop-rspec-1.19.0 lib/rubocop/rspec/util.rb
rubocop-rspec-1.18.0 lib/rubocop/rspec/util.rb
rubocop-rspec-1.17.1 lib/rubocop/rspec/util.rb
rubocop-rspec-1.17.0 lib/rubocop/rspec/util.rb
rubocop-rspec-1.16.0 lib/rubocop/rspec/util.rb
rubocop-rspec-1.15.1 lib/rubocop/rspec/util.rb
rubocop-rspec-1.15.0 lib/rubocop/rspec/util.rb
rubocop-rspec-1.14.0 lib/rubocop/rspec/util.rb
rubocop-rspec-1.13.0 lib/rubocop/rspec/util.rb
rubocop-rspec-1.12.0 lib/rubocop/rspec/util.rb
rubocop-rspec-1.11.0 lib/rubocop/rspec/util.rb
rubocop-rspec-1.10.0 lib/rubocop/rspec/util.rb