Class: Nanotest::Spec

Inherits:
Object show all
Defined in:
lib/nanotest/spec.rb

Overview

“Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.” –Antoine de Saint Exupéry

Instance Method Summary collapse

Constructor Details

#initialize(obj, positive = true) ⇒ Spec

Returns a new instance of Spec.



7
8
9
# File 'lib/nanotest/spec.rb', line 7

def initialize(obj, positive=true)
  @obj, @positive = obj, positive
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/nanotest/spec.rb', line 11

def method_missing(method, *args, &block)
  file, line = caller.first.split(':')[0..1]
  bool = @obj.__send__(method, *args, &block)
  bool = !bool unless @positive
  Nanotest.assert(nil, file, line) { bool }
  @obj
end