Sha256: 782a265f9bcb6d46ebce652987da1f63ec03bed8d5ec1a68ff1cde026a3db4c4

Contents?: true

Size: 1.54 KB

Versions: 1

Compression:

Stored size: 1.54 KB

Contents

module Spec
  module Expectations
    module Should
      class Base

        instance_methods.each { |m| undef_method m unless m =~ /^(__|\w)/ }

        def default_message(expectation, expected=:no_expectation_specified)
          message = "#{@target.inspect_for_expectation_not_met_error} #{expectation}"
          if (expected != :no_expectation_specified)
            message << " " << expected.inspect_for_expectation_not_met_error
          end
          message
         end

        def fail_with_message(message)
          Kernel::raise(Spec::Expectations::ExpectationNotMetError.new(message))
        end
    
        def find_supported_sym(original_sym)
          ["#{original_sym}?", "#{original_sym}s?"].each do |alternate_sym|
            return alternate_sym.to_s if @target.respond_to?(alternate_sym.to_s)
          end
          return original_sym.supported_by_rspec? ? original_sym : "#{original_sym}?"
        end

        def method_missing(original_sym, *args, &block)
          if original_sym.to_s =~ /^not_/
            return Not.new(@target).__send__(original_sym.to_s[4..-1].to_sym, *args, &block)
          end
          if original_sym.to_s =~ /^be_/
            @be_seen = true
            return __send__(original_sym.to_s[3..-1].to_sym, *args, &block)
          end
          if original_sym.to_s =~ /^have_/
            return have.__send__(original_sym.to_s[5..-1].to_sym, *args, &block)
          end
          __delegate_method_missing_to_target original_sym, find_supported_sym(original_sym), *args
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rspec-0.7.3 lib/spec/expectations/should/base.rb