Object
# File lib/rspec/matchers/built_in/have.rb, line 5 5: def initialize(expected, relativity=:exactly) 6: @expected = case expected 7: when :no then 0 8: when String then expected.to_i 9: else expected 10: end 11: @relativity = relativity 12: @actual = @collection_name = @plural_collection_name = nil 13: end
# File lib/rspec/matchers/built_in/have.rb, line 81 81: def description 82: "have #{relative_expectation} #{@collection_name}" 83: end
# File lib/rspec/matchers/built_in/have.rb, line 35 35: def determine_collection(collection_or_owner) 36: if collection_or_owner.respond_to?(@collection_name) 37: collection_or_owner.send(@collection_name, *@args, &@block) 38: elsif (@plural_collection_name && collection_or_owner.respond_to?(@plural_collection_name)) 39: collection_or_owner.send(@plural_collection_name, *@args, &@block) 40: elsif determine_query_method(collection_or_owner) 41: collection_or_owner 42: else 43: collection_or_owner.send(@collection_name, *@args, &@block) 44: end 45: end
# File lib/rspec/matchers/built_in/have.rb, line 47 47: def determine_query_method(collection) 48: [:size, :length, :count].detect {|m| collection.respond_to?(m)} 49: end
# File lib/rspec/matchers/built_in/have.rb, line 55 55: def failure_message_for_should 56: "expected #{relative_expectation} #{@collection_name}, got #{@actual}" 57: end
# File lib/rspec/matchers/built_in/have.rb, line 59 59: def failure_message_for_should_not 60: if @relativity == :exactly 61: return "expected target not to have #{@expected} #{@collection_name}, got #{@actual}" 62: elsif @relativity == :at_most 63: return Isn't life confusing enough?Instead of having to figure out the meaning of this: should_not have_at_most(#{@expected}).#{@collection_name}We recommend that you use this instead: should have_at_least(#{@expected + 1}).#{@collection_name} 64: elsif @relativity == :at_least 65: return Isn't life confusing enough?Instead of having to figure out the meaning of this: should_not have_at_least(#{@expected}).#{@collection_name}We recommend that you use this instead: should have_at_most(#{@expected - 1}).#{@collection_name} 66: end 67: end
# File lib/rspec/matchers/built_in/have.rb, line 23 23: def matches?(collection_or_owner) 24: collection = determine_collection(collection_or_owner) 25: query_method = determine_query_method(collection) 26: raise not_a_collection unless query_method 27: @actual = collection.send(query_method) 28: case @relativity 29: when :at_least then @actual >= @expected 30: when :at_most then @actual <= @expected 31: else @actual == @expected 32: end 33: end
# File lib/rspec/matchers/built_in/have.rb, line 51 51: def not_a_collection 52: "expected #{@collection_name} to be a collection but it does not respond to #length, #size or #count" 53: end
# File lib/rspec/matchers/built_in/have.rb, line 91 91: def method_missing(method, *args, &block) 92: @collection_name = method 93: if inflector = (defined?(ActiveSupport::Inflector) && ActiveSupport::Inflector.respond_to?(:pluralize) ? ActiveSupport::Inflector : (defined?(Inflector) ? Inflector : nil)) 94: @plural_collection_name = inflector.pluralize(method.to_s) 95: end 96: @args = args 97: @block = block 98: self 99: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.