Class Spec::Expectations::Should::CollectionHandler
In: lib/spec/expectations/should/have.rb
Parent: Object

Methods

Public Class methods

[Source]

    # File lib/spec/expectations/should/have.rb, line 37
37:         def initialize(target, relativity=:exactly, expected=nil)
38:           @target = target
39:           @expected = expected == :no ? 0 : expected
40:           @at_least = (relativity == :at_least)
41:           @at_most = (relativity == :at_most)
42:         end

Public Instance methods

[Source]

    # File lib/spec/expectations/should/have.rb, line 91
91:         def actual_size_of(collection)
92:           return collection.length if collection.respond_to? :length
93:           return collection.size if collection.respond_to? :size
94:         end

[Source]

    # File lib/spec/expectations/should/have.rb, line 81
81:         def as_specified?(sym, args)
82:           return actual_size_of(collection(sym, args)) >= @expected if @at_least
83:           return actual_size_of(collection(sym, args)) <= @expected if @at_most
84:           return actual_size_of(collection(sym, args)) == @expected
85:         end

[Source]

    # File lib/spec/expectations/should/have.rb, line 44
44:         def at_least(expected_number=nil)
45:           @at_least = true
46:           @at_most = false
47:           @expected = expected_number == :no ? 0 : expected_number
48:           self
49:         end

[Source]

    # File lib/spec/expectations/should/have.rb, line 51
51:         def at_most(expected_number=nil)
52:           @at_least = false
53:           @at_most = true
54:           @expected = expected_number == :no ? 0 : expected_number
55:           self
56:         end

[Source]

    # File lib/spec/expectations/should/have.rb, line 74
74:         def build_message(sym, args)
75:           message = "#{@target.inspect} should have"
76:           message += " at least" if @at_least
77:           message += " at most" if @at_most
78:           message += " #{@expected} #{sym} (has #{actual_size_of(collection(sym, args))})"
79:         end

[Source]

    # File lib/spec/expectations/should/have.rb, line 87
87:         def collection(sym, args)
88:           @target.send(sym, *args)
89:         end

[Source]

    # File lib/spec/expectations/should/have.rb, line 68
68:         def handle_message(sym, *args)
69:           return at_least(args[0]) if sym == :at_least
70:           return at_most(args[0]) if sym == :at_most
71:           Spec::Expectations.fail_with(build_message(sym, args)) unless as_specified?(sym, args)
72:         end

[Source]

    # File lib/spec/expectations/should/have.rb, line 58
58:         def method_missing(sym, *args)
59:           if @target.respond_to?(sym)
60:             handle_message(sym, *args)
61:           end
62:         end

[Source]

    # File lib/spec/expectations/should/have.rb, line 64
64:         def wants_to_handle(sym)
65:           respond_to?(sym) || @target.respond_to?(sym)
66:         end

[Validate]