Class Index [+]

Quicksearch

RSpec::Matchers::Pretty

Public Instance Methods

_pretty_print(array) click to toggle source
    # File lib/rspec/matchers/pretty.rb, line 23
23:       def _pretty_print(array)
24:         result = ""
25:         array.each_with_index do |item, index|
26:           if index < (array.length - 2)
27:             result << "#{item.inspect}, "
28:           elsif index < (array.length - 1)
29:             result << "#{item.inspect} and "
30:           else
31:             result << "#{item.inspect}"
32:           end
33:         end
34:         result
35:       end
expected_to_sentence() click to toggle source
    # File lib/rspec/matchers/pretty.rb, line 41
41:       def expected_to_sentence
42:         to_sentence(@expected) if defined?(@expected)
43:       end
name() click to toggle source
    # File lib/rspec/matchers/pretty.rb, line 45
45:       def name
46:         defined?(@name) ? @name : underscore(self.class.name.split("::").last)
47:       end
name_to_sentence() click to toggle source
    # File lib/rspec/matchers/pretty.rb, line 37
37:       def name_to_sentence
38:         split_words(name)
39:       end
split_words(sym) click to toggle source
   # File lib/rspec/matchers/pretty.rb, line 4
4:       def split_words(sym)
5:         sym.to_s.gsub(/_/,' ')
6:       end
to_sentence(words) click to toggle source
    # File lib/rspec/matchers/pretty.rb, line 8
 8:       def to_sentence(words)
 9:         return "" unless words
10:         words = Array(words).map{|w| w.inspect}
11:         case words.length
12:           when 0
13:             ""
14:           when 1
15:             " #{words[0]}"
16:           when 2
17:             " #{words[0]} and #{words[1]}"
18:           else
19:             " #{words[0...-1].join(', ')}, and #{words[-1]}"
20:         end
21:       end
underscore(camel_cased_word) click to toggle source

Borrowed from ActiveSupport

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

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.