Sha256: 39b7301eb73a577e719cbb21d0d69d9129bdcccd33efb0b3792ad3263dcddb07

Contents?: true

Size: 1.82 KB

Versions: 5916

Compression:

Stored size: 1.82 KB

Contents

module RSpec
  module Matchers
    # Facilitates converting ruby objects to English phrases.
    module EnglishPhrasing
      # Converts a symbol into an English expression.
      #
      #     split_words(:banana_creme_pie) #=> "banana creme pie"
      #
      def self.split_words(sym)
        sym.to_s.tr('_', ' ')
      end

      # @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([]) #=> ""
      #
      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

      if RUBY_VERSION == '1.8.7'
        # Not sure why, but on travis on 1.8.7 we have gotten these warnings:
        # lib/rspec/matchers/english_phrasing.rb:28: warning: default `to_a' will be obsolete
        # So it appears that `Array` can trigger that (e.g. by calling `to_a` on the passed object?)
        # So here we replace `Kernel#Array` with our own warning-free implementation for 1.8.7.
        # @private
        # rubocop:disable Naming/MethodName
        def self.Array(obj)
          case obj
          when Array then obj
          else [obj]
          end
        end
        # rubocop:enable Naming/MethodName
      end
    end
  end
end

Version data entries

5,916 entries across 5,904 versions & 50 rubygems

Version Path
ory-kratos-client-0.8.0.alpha2 vendor/bundle/ruby/2.5.0/gems/rspec-expectations-3.10.1/lib/rspec/matchers/english_phrasing.rb
ory-client-0.0.1.alpha21 vendor/bundle/ruby/2.5.0/gems/rspec-expectations-3.10.1/lib/rspec/matchers/english_phrasing.rb
ory-keto-client-0.7.0.alpha1 vendor/bundle/ruby/2.5.0/gems/rspec-expectations-3.10.1/lib/rspec/matchers/english_phrasing.rb
ory-keto-client-0.7.0.alpha0 vendor/bundle/ruby/2.5.0/gems/rspec-expectations-3.10.1/lib/rspec/matchers/english_phrasing.rb
ory-kratos-client-0.7.6.alpha7 vendor/bundle/ruby/2.5.0/gems/rspec-expectations-3.10.1/lib/rspec/matchers/english_phrasing.rb
ory-kratos-client-0.7.6.alpha6 vendor/bundle/ruby/2.5.0/gems/rspec-expectations-3.10.1/lib/rspec/matchers/english_phrasing.rb
ory-kratos-client-0.7.6.alpha5 vendor/bundle/ruby/2.5.0/gems/rspec-expectations-3.10.1/lib/rspec/matchers/english_phrasing.rb
ory-kratos-client-0.7.6.alpha4 vendor/bundle/ruby/2.5.0/gems/rspec-expectations-3.10.1/lib/rspec/matchers/english_phrasing.rb
ory-kratos-client-0.7.6.alpha3 vendor/bundle/ruby/2.5.0/gems/rspec-expectations-3.10.1/lib/rspec/matchers/english_phrasing.rb
ory-kratos-client-0.7.6.alpha1 vendor/bundle/ruby/2.5.0/gems/rspec-expectations-3.10.1/lib/rspec/matchers/english_phrasing.rb
ory-kratos-client-0.7.5.alpha2 vendor/bundle/ruby/2.5.0/gems/rspec-expectations-3.10.1/lib/rspec/matchers/english_phrasing.rb
tdiary-5.1.7 vendor/bundle/ruby/3.0.0/gems/rspec-expectations-3.10.1/lib/rspec/matchers/english_phrasing.rb
tdiary-5.1.7 vendor/bundle/ruby/2.7.0/gems/rspec-expectations-3.10.1/lib/rspec/matchers/english_phrasing.rb
mx-platform-ruby-0.4.0 vendor/bundle/ruby/2.6.0/gems/rspec-expectations-3.10.1/lib/rspec/matchers/english_phrasing.rb
mx-platform-ruby-0.3.2 vendor/bundle/ruby/2.6.0/gems/rspec-expectations-3.10.1/lib/rspec/matchers/english_phrasing.rb
mx-platform-ruby-0.3.1 vendor/bundle/ruby/2.6.0/gems/rspec-expectations-3.10.1/lib/rspec/matchers/english_phrasing.rb
rails_mini_profiler-0.2.0 vendor/bundle/ruby/3.0.0/gems/rspec-expectations-3.10.1/lib/rspec/matchers/english_phrasing.rb
mumukit-content-type-1.11.1 vendor/bundle/ruby/2.6.0/gems/rspec-expectations-3.10.1/lib/rspec/matchers/english_phrasing.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/2.7.0/gems/rspec-expectations-3.10.1/lib/rspec/matchers/english_phrasing.rb
tdiary-5.1.6 vendor/bundle/ruby/3.0.0/gems/rspec-expectations-3.10.1/lib/rspec/matchers/english_phrasing.rb