Class: NanoTest::Spec

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

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("assertion failed", file, line) { bool }
  @obj
end