Sha256: fc47893a3649962035c031d2da35c0b3a9360ffbb3b21de8253b062242f6023b

Contents?: true

Size: 1.4 KB

Versions: 192

Compression:

Stored size: 1.4 KB

Contents

module RSpec
  module Matchers
    module Pretty
      def split_words(sym)
        sym.to_s.gsub(/_/,' ')
      end

      def to_sentence(words)
        return "" unless words
        words = Array(words).map{|w| w.inspect}
        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

      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

      def name_to_sentence
        split_words(name)
      end

      def expected_to_sentence
        to_sentence(@expected) if defined?(@expected)
      end

      def name
        defined?(@name) ? @name : underscore(self.class.name.split("::").last)
      end

      # Borrowed from ActiveSupport
      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
    end
  end
end

Version data entries

192 entries across 93 versions & 14 rubygems

Version Path
classiccms-0.3.0 vendor/bundle/gems/rspec-expectations-2.9.0/lib/rspec/matchers/pretty.rb
sunrise-cms-0.3.0.rc vendor/bundle/ruby/1.9.1/gems/rails-uploader-0.0.1/vendor/bundle/ruby/1.9.1/gems/rspec-expectations-2.10.0/lib/rspec/matchers/pretty.rb
sunrise-cms-0.3.0.rc vendor/bundle/ruby/1.9.1/gems/rspec-expectations-2.10.0/lib/rspec/matchers/pretty.rb
rails-uploader-0.0.1 vendor/bundle/ruby/1.9.1/gems/rspec-expectations-2.10.0/lib/rspec/matchers/pretty.rb
resque-pool-0.3.0 vendor/bundle/ruby/1.8/gems/rspec-expectations-2.8.0/lib/rspec/matchers/pretty.rb
resque-pool-0.3.0 vendor/bundle/ruby/1.8/gems/rspec-expectations-2.9.0/lib/rspec/matchers/pretty.rb
resque-pool-0.3.0 vendor/bundle/ruby/1.8/gems/rspec-expectations-2.9.1/lib/rspec/matchers/pretty.rb
ftl-0.2.0 vendor/bundle/gems/rspec-expectations-2.10.0/lib/rspec/matchers/pretty.rb
classiccms-0.2.4.pre vendor/bundle/gems/rspec-expectations-2.9.1/lib/rspec/matchers/pretty.rb
classiccms-0.2.4.pre vendor/bundle/gems/rspec-expectations-2.9.0/lib/rspec/matchers/pretty.rb
classiccms-0.2.4.pre vendor/bundle/gems/rspec-expectations-2.10.0/lib/rspec/matchers/pretty.rb
rspec-expectations-2.10.0 lib/rspec/matchers/pretty.rb
horseman-0.0.5 vendor/ruby/1.9.1/gems/rspec-expectations-2.9.1/lib/rspec/matchers/pretty.rb
frameworks-capybara-0.2.0.rc6 vendor/bundle/ruby/1.8/gems/rspec-expectations-2.9.0/lib/rspec/matchers/pretty.rb
frameworks-capybara-0.2.0.rc5 vendor/bundle/ruby/1.8/gems/rspec-expectations-2.9.0/lib/rspec/matchers/pretty.rb
rspec-expectations-2.9.1 lib/rspec/matchers/pretty.rb
frameworks-capybara-0.2.0.rc4 vendor/bundle/ruby/1.8/gems/rspec-expectations-2.9.0/lib/rspec/matchers/pretty.rb
frameworks-capybara-0.2.0.rc3 vendor/bundle/ruby/1.8/gems/rspec-expectations-2.9.0/lib/rspec/matchers/pretty.rb
frameworks-capybara-0.2.0.rc2 vendor/bundle/ruby/1.8/gems/rspec-expectations-2.9.0/lib/rspec/matchers/pretty.rb
classicCMS-0.2.3 vendor/bundle/gems/rspec-expectations-2.9.0/lib/rspec/matchers/pretty.rb