class Object def should_be! method unless self.send("#{method}?") == true raise RuntimeError, " ASSERTION FAILED: #{self.inspect} should be #{method} ", caller end return self end alias_method :should_have!, :should_be! def should_not_be! method unless self.send("#{method}?") == false raise RuntimeError, " ASSERTION FAILED: #{self.inspect} should not be #{method} ", caller end return self end alias_method :should_not_have!, :should_not_be! def should! cmd, arg = NotDefined result = case cmd when :be_never_called then false when :be_nil then self.equal? nil when :be_a if arg.class == Array arg.any?{|klass| self.is_a? klass} else self.is_a? arg end when :be_an if arg.class == Array arg.any?{|klass| self.is_a? klass} else self.is_a? arg end when :be if arg.class == Array arg.any?{|klass| self.respond_to :is?, klass} else self.respond_to :is?, arg end when :include then self.include? arg when :be_in then arg.include? self when :be_true then self when :be_false then !self when :be_empty then self.empty? else if arg.equal? NotDefined self.send cmd else self.send cmd, arg end end unless result unless arg.equal? NotDefined raise RuntimeError, " ASSERTION FAILED: #{self.inspect} should #{cmd} #{arg.inspect} ", caller else raise RuntimeError, " ASSERTION FAILED: #{self.inspect} should #{cmd} ", caller end end return self end def should_not! cmd, arg = NotDefined result = case cmd when :be_never_called then false when :be_nil then self.equal? nil when :be_a if arg.class == Array arg.any?{|klass| self.is_a? klass} else self.is_a? arg end when :be_an if arg.class == Array arg.any?{|klass| self.is_a? klass} else self.is_a? arg end when :be if arg.class == Array arg.any?{|klass| self.respond_to :is?, klass} else self.respond_to :is?, arg end when :include then self.include? arg when :be_in then arg.include? self when :be_true then self when :be_false then !self when :be_empty then self.empty? else if arg.equal? NotDefined self.send cmd else self.send cmd, arg end end if result unless arg.equal? NotDefined raise RuntimeError, " ASSERTION FAILED: #{self.inspect} should not #{cmd} #{arg.inspect} ", caller else raise RuntimeError, " ASSERTION FAILED: #{self.inspect} should not #{cmd} ", caller end end return self end end