be(*args) public

Given true, false, or nil, will pass if actual value is true, false or nil (respectively). Given no args means the caller should satisfy an if condition (to be or not to be).

Predicates are any Ruby method that ends in a "?" and returns true or false. Given be_ followed by arbitrary_predicate (without the "?"), RSpec will match convert that into a query against the target object.

The arbitrary_predicate feature will handle any predicate prefixed with "be_an_" (e.g. be_an_instance_of), "be_a_" (e.g. be_a_kind_of) or "be_" (e.g. be_empty), letting you choose the prefix that best suits the predicate.


  target.should be_true
  target.should be_false
  target.should be_nil
  target.should_not be_nil

  collection.should be_empty #passes if target.empty?
  target.should_not be_empty #passes unless target.empty?
  target.should_not be_old_enough(16) #passes unless target.old_enough?(16)
Show source
Register or log in to add new notes.