Sha256: 7387b7f47167c577086d34bfdbed90cfcdc1f27a49e4e27e596297cee29f9e50

Contents?: true

Size: 911 Bytes

Versions: 7

Compression:

Stored size: 911 Bytes

Contents

module Shoulda
  module Matchers
    TERMINAL_MAX_WIDTH = 72

    # @private
    def self.warn(message)
      header = "Warning from shoulda-matchers:"
      divider = "*" * TERMINAL_MAX_WIDTH
      wrapped_message = word_wrap(message, TERMINAL_MAX_WIDTH)
      full_message = [
        divider,
        [header, wrapped_message.strip].join("\n\n"),
        divider
      ].join("\n")

      Kernel.warn(full_message)
    end

    # @private
    def self.warn_about_deprecated_method(old_method, new_method)
      warn <<EOT
#{old_method} is deprecated and will be removed in the next major
release. Please use #{new_method} instead.
EOT
    end

    # Source: <https://www.ruby-forum.com/topic/57805>
    # @private
    def self.word_wrap(text, width=80)
      text.
        gsub(/\n+/, " ").
        gsub( /(\S{#{width}})(?=\S)/, '\1 ' ).
        gsub( /(.{1,#{width}})(?:\s+|$)/, "\\1\n" )
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/shoulda-matchers-2.8.0/lib/shoulda/matchers/warn.rb
shoulda-matchers-3.0.0 lib/shoulda/matchers/warn.rb
shoulda-matchers-3.0.0.rc1 lib/shoulda/matchers/warn.rb
shoulda-matchers-2.8.0 lib/shoulda/matchers/warn.rb
shoulda-matchers-2.8.0.rc2 lib/shoulda/matchers/warn.rb
shoulda-matchers-2.8.0.rc1 lib/shoulda/matchers/warn.rb
shoulda-matchers-2.7.0 lib/shoulda/matchers/warn.rb