Class | Bacon::TestUnitOutput::Should |
In: |
lib/bacon.rb
|
Parent: | Object |
# File lib/bacon.rb, line 260 260: def initialize(object) 261: @object = object 262: @negated = false 263: end
# File lib/bacon.rb, line 275 275: def be(*args, &block) 276: if args.empty? 277: self 278: else 279: block = args.shift unless block_given? 280: satisfy(*args, &block) 281: end 282: end
# File lib/bacon.rb, line 317 317: def flunk(reason="Flunked") 318: raise Bacon::Error.new(:failed, reason) 319: end
# File lib/bacon.rb, line 302 302: def method_missing(name, *args, &block) 303: name = "#{name}?" if name.to_s =~ /\w[^?]\z/ 304: 305: desc = @negated ? "not " : "" 306: desc << @object.inspect << "." << name.to_s 307: desc << "(" << args.map{|x|x.inspect}.join(", ") << ") failed" 308: 309: satisfy(desc) { |x| x.__send__(name, *args, &block) } 310: end
# File lib/bacon.rb, line 265 265: def not(*args, &block) 266: @negated = !@negated 267: 268: if args.empty? 269: self 270: else 271: be(*args, &block) 272: end 273: end
# File lib/bacon.rb, line 287 287: def satisfy(*args, &block) 288: if args.size == 1 && String === args.first 289: description = args.shift 290: else 291: description = "" 292: end 293: 294: r = yield(@object, *args) 295: if Bacon::Counter[:depth] > 0 296: Bacon::Counter[:requirements] += 1 297: raise Bacon::Error.new(:failed, description) unless @negated ^ r 298: end 299: @negated ^ r ? r : false 300: end