Class: Insist

Inherits:
Object
  • Object
show all
Includes:
Assert, Comparators, Enumerables, Nil, Predicates, Raises
Defined in:
lib/insist.rb,
lib/insist/namespace.rb

Overview

Insist on correctness.

Example:

data = { "hello" => "world" }
insist { data["hello"] } == "world"

This class aims to work similarly to how rspec’s “should” stuff does, but instead of molesting Object allows you to neatly wrap values with blocks while still checking for expected values.

Direct Known Subclasses

Reject

Defined Under Namespace

Modules: Assert, Comparators, Enumerables, Nil, Predicates, Raises Classes: Failure

Constant Summary

Constants included from Predicates

Predicates::PREDICATE_METHOD_RE

Instance Method Summary collapse

Methods included from Predicates

#method_missing, #respond_to?

Methods included from Assert

#assert

Methods included from Raises

#fails, #raises

Methods included from Nil

#nil?

Methods included from Enumerables

#include?

Methods included from Comparators

#!=, #!~, #<, #<=, #==, #=~, #>, #>=

Constructor Details

#initialize(&block) ⇒ Insist

Create a new insist with a block.

Example:

Insist.new { value }

Better:

insist { value }


41
42
43
# File 'lib/insist.rb', line 41

def initialize(&block)
  @callback = block
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Insist::Predicates

Instance Method Details

#valueObject

def initialize



45
46
47
48
49
# File 'lib/insist.rb', line 45

def value
  # TODO(sissel): make caching the value optional
  @value ||= @callback.call
  return @value
end