Module: RSpec::Matchers::Pretty

### Home Classes Methods

### In Files

- lib/rspec/matchers/pretty.rb

### Methods

- #_pretty_print
- #expected_to_sentence
- #name
- #name_to_sentence
- #split_words
- #to_sentence
- #to_word
- #underscore

### Class/Module Index

Quicksearch

- RSpec
- RSpec::Expectations
- RSpec::Expectations::DeprecatedConstants
- RSpec::Expectations::Deprecation
- RSpec::Expectations::Differ
- RSpec::Expectations::ExpectationHandler
- RSpec::Expectations::ExpectationNotMetError
- RSpec::Expectations::ExpectationTarget
- RSpec::Expectations::NegativeExpectationHandler
- RSpec::Expectations::PositiveExpectationHandler
- RSpec::Expectations::Syntax
- RSpec::Expectations::Syntax::ExpectExpressionGenerator
- RSpec::Expectations::Syntax::ShouldExpressionGenerator
- RSpec::Expectations::Version
- RSpec::Matchers
- RSpec::Matchers::BuiltIn
- RSpec::Matchers::BuiltIn::BaseMatcher
- RSpec::Matchers::BuiltIn::Be
- RSpec::Matchers::BuiltIn::BeAKindOf
- RSpec::Matchers::BuiltIn::BeAnInstanceOf
- RSpec::Matchers::BuiltIn::BeComparedTo
- RSpec::Matchers::BuiltIn::BeFalse
- RSpec::Matchers::BuiltIn::BeHelpers
- RSpec::Matchers::BuiltIn::BeNil
- RSpec::Matchers::BuiltIn::BePredicate
- RSpec::Matchers::BuiltIn::BeTrue
- RSpec::Matchers::BuiltIn::BeWithin
- RSpec::Matchers::BuiltIn::Change
- RSpec::Matchers::BuiltIn::Cover
- RSpec::Matchers::BuiltIn::EndWith
- RSpec::Matchers::BuiltIn::Eq
- RSpec::Matchers::BuiltIn::Eql
- RSpec::Matchers::BuiltIn::Equal
- RSpec::Matchers::BuiltIn::Exist
- RSpec::Matchers::BuiltIn::Has
- RSpec::Matchers::BuiltIn::Have
- RSpec::Matchers::BuiltIn::Include
- RSpec::Matchers::BuiltIn::Match
- RSpec::Matchers::BuiltIn::MatchArray
- RSpec::Matchers::BuiltIn::NegativeOperatorMatcher
- RSpec::Matchers::BuiltIn::PositiveOperatorMatcher
- RSpec::Matchers::BuiltIn::RaiseError
- RSpec::Matchers::BuiltIn::RespondTo
- RSpec::Matchers::BuiltIn::Satisfy
- RSpec::Matchers::BuiltIn::StartAndEndWith
- RSpec::Matchers::BuiltIn::StartWith
- RSpec::Matchers::BuiltIn::ThrowSymbol
- RSpec::Matchers::BuiltIn::YieldControl
- RSpec::Matchers::BuiltIn::YieldProbe
- RSpec::Matchers::BuiltIn::YieldSuccessiveArgs
- RSpec::Matchers::BuiltIn::YieldWithArgs
- RSpec::Matchers::BuiltIn::YieldWithNoArgs
- RSpec::Matchers::Configuration
- RSpec::Matchers::DSL
- RSpec::Matchers::DSL::Matcher
- RSpec::Matchers::Extensions
- RSpec::Matchers::Extensions::InstanceEvalWithArgs
- RSpec::Matchers::OperatorMatcher
- RSpec::Matchers::Pretty
- Array

No matching classes.

# RSpec::Matchers::Pretty

### Public Instance Methods

_pretty_print(array) click to toggle source

    # File lib/rspec/matchers/pretty.rb, line 23
    def _pretty_print(array)
      result = ""
      array.each_with_index do |item, index|
        if index < (array.length - 2)
          result << "#{item.inspect}, "
        elsif index < (array.length - 1)
          result << "#{item.inspect} and "
        else
          result << "#{item.inspect}"
        end
      end
      result
    end

expected_to_sentence() click to toggle source

    # File lib/rspec/matchers/pretty.rb, line 45
    def expected_to_sentence
      to_sentence(@expected) if defined?(@expected)
    end

name() click to toggle source

    # File lib/rspec/matchers/pretty.rb, line 49
    def name
      defined?(@name) ? @name : underscore(self.class.name.split("::").last)
    end

name_to_sentence() click to toggle source

    # File lib/rspec/matchers/pretty.rb, line 41
    def name_to_sentence
      split_words(name)
    end

split_words(sym) click to toggle source

    # File lib/rspec/matchers/pretty.rb, line 4
    def split_words(sym)
      sym.to_s.gsub(/_/,' ')
    end

to_sentence(words) click to toggle source

    # File lib/rspec/matchers/pretty.rb, line 8
    def to_sentence(words)
      return "" unless words
      words = Array(words).map { |w| to_word(w) }
      case words.length
        when 0
          ""
        when 1
          " #{words[0]}"
        when 2
          " #{words[0]} and #{words[1]}"
        else
          " #{words[0...-1].join(', ')}, and #{words[-1]}"
      end
    end

to_word(item) click to toggle source

    # File lib/rspec/matchers/pretty.rb, line 37
    def to_word(item)
      is_matcher_with_description?(item) ? item.description : item.inspect
    end

underscore(camel_cased_word) click to toggle source

Borrowed from ActiveSupport

    # File lib/rspec/matchers/pretty.rb, line 54
    def underscore(camel_cased_word)
      word = camel_cased_word.to_s.dup
      word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
      word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
      word.tr!("-", "_")
      word.downcase!
      word
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.