Class: Spec::Expectations::Should::Have

Inherits:
Object
  • Object
show all
Defined in:
lib/spec/expectations/should/have.rb

Direct Known Subclasses

NotHave

Instance Method Summary collapse

Constructor Details

#initialize(target, relativity = :exactly, expected = nil) ⇒ Have

Returns a new instance of Have.



5
6
7
8
9
# File 'lib/spec/expectations/should/have.rb', line 5

def initialize(target, relativity=:exactly, expected=nil)
  @target = target
  init_collection_handler(target, relativity, expected)
  init_item_handler(target)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/spec/expectations/should/have.rb', line 19

def method_missing(sym, *args)
  if @collection_handler.wants_to_handle(sym)
    @collection_handler.handle_message(sym, *args)
  elsif @item_handler.wants_to_handle(sym)
    @item_handler.handle_message(sym, *args)
  else
    Spec::Expectations.fail_with("target does not respond to #has_#{sym}?")
  end
end

Instance Method Details

#init_collection_handler(target, relativity, expected) ⇒ Object



11
12
13
# File 'lib/spec/expectations/should/have.rb', line 11

def init_collection_handler(target, relativity, expected)
  @collection_handler = CollectionHandler.new(target, relativity, expected)
end

#init_item_handler(target) ⇒ Object



15
16
17
# File 'lib/spec/expectations/should/have.rb', line 15

def init_item_handler(target)
  @item_handler = PositiveItemHandler.new(target)
end