Sha256: ddf6bdfc25c7071ebb48071553cb4382bad8e50271565e8ce5b957937ddcba54

Contents?: true

Size: 1.17 KB

Versions: 54

Compression:

Stored size: 1.17 KB

Contents

module RSpec
  module Matchers
    module BuiltIn
      class Has
        def initialize(expected, *args)
          @expected, @args = expected, args
        end

        def matches?(actual)
          actual.__send__(predicate(@expected), *@args)
        end
        alias == matches?

        def failure_message_for_should
          "expected ##{predicate(@expected)}#{failure_message_args_description} to return true, got false"
        end

        def failure_message_for_should_not
          "expected ##{predicate(@expected)}#{failure_message_args_description} to return false, got true"
        end

        def description
          [method_description(@expected), args_description].compact.join(' ')
        end

        private

        def predicate(sym)
          "#{sym.to_s.sub("have_","has_")}?".to_sym
        end

        def method_description(method)
          method.to_s.gsub('_', ' ')
        end

        def args_description
          return nil if @args.empty?
          @args.map { |arg| arg.inspect }.join(', ')
        end

        def failure_message_args_description
          desc = args_description
          "(#{desc})" if desc
        end
      end
    end
  end
end

Version data entries

54 entries across 54 versions & 18 rubygems

Version Path
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.4.0/gems/rspec-expectations-2.14.5/lib/rspec/matchers/built_in/has.rb
vagrant-unbundled-1.9.5.1 vendor/bundle/ruby/2.4.0/gems/rspec-expectations-2.14.5/lib/rspec/matchers/built_in/has.rb
vagrant-unbundled-1.9.1.1 vendor/bundle/ruby/2.4.0/gems/rspec-expectations-2.14.5/lib/rspec/matchers/built_in/has.rb
vagrant-unbundled-1.8.5.2 vendor/bundle/ruby/2.3.0/gems/rspec-expectations-2.14.5/lib/rspec/matchers/built_in/has.rb
vagrant-unbundled-1.8.5.1 vendor/bundle/ruby/2.3.0/gems/rspec-expectations-2.14.5/lib/rspec/matchers/built_in/has.rb
vagrant-unbundled-1.8.4.2 vendor/bundle/ruby/2.3.0/gems/rspec-expectations-2.14.5/lib/rspec/matchers/built_in/has.rb
vagrant-unbundled-1.8.4.1 vendor/bundle/ruby/2.3.0/gems/rspec-expectations-2.14.5/lib/rspec/matchers/built_in/has.rb
vagrant-unbundled-1.8.1.1 vendor/bundle/ruby/2.3.0/gems/rspec-expectations-2.14.5/lib/rspec/matchers/built_in/has.rb
opal-rspec-cj-0.4.4 vendor_lib/rspec/matchers/built_in/has.rb
opal-rspec-0.4.3 vendor_lib/rspec/matchers/built_in/has.rb
vagrant-cloudstack-1.1.0 vendor/bundle/gems/rspec-expectations-2.14.5/lib/rspec/matchers/built_in/has.rb
opal-rspec-0.4.2 vendor_lib/rspec/matchers/built_in/has.rb
opal-rspec-0.4.1 vendor_lib/rspec/matchers/built_in/has.rb
opal-rspec-0.4.0 vendor_lib/rspec/matchers/built_in/has.rb
opal-rspec-0.4.0.beta4 vendor_lib/rspec/matchers/built_in/has.rb
judge-2.0.5 vendor/bundle/ruby/2.1.0/gems/rspec-expectations-2.13.0/lib/rspec/matchers/built_in/has.rb
dxruby_rp5-0.0.4 spec/vendor/rspec-expectations-2.14.4/lib/rspec/matchers/built_in/has.rb
rspec-expectations-2.14.5 lib/rspec/matchers/built_in/has.rb
mango-0.8.0 vendor/bundler/ruby/2.1.0/gems/rspec-expectations-2.14.4/lib/rspec/matchers/built_in/has.rb
mango-0.7.1 vendor/bundler/ruby/2.0.0/gems/rspec-expectations-2.14.4/lib/rspec/matchers/built_in/has.rb