Class: Matest::Example

Inherits:
Object
  • Object
show all
Defined in:
lib/matest.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(example_block, description, lets) ⇒ Example

Returns a new instance of Example.



48
49
50
51
52
53
54
55
# File 'lib/matest.rb', line 48

def initialize(example_block, description, lets)
  @__example_block = example_block
  @__description = description
  lets.each do |let|
    self.class.let(let.var_name, &let.block)
    send(let.var_name) if let.and_call
  end
end

Class Method Details

.let(var_name, &block) ⇒ Object



61
62
63
64
65
# File 'lib/matest.rb', line 61

def self.let(var_name, &block)
  define_method(var_name) do
    instance_variable_set(:"@#{var_name}", block.call)
  end
end

Instance Method Details

#callObject



57
58
59
# File 'lib/matest.rb', line 57

def call
  instance_eval(&example_block)
end

#descriptionObject



44
45
46
# File 'lib/matest.rb', line 44

def description
  @__description
end

#example_blockObject



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

def example_block
  @__example_block
end

#trackObject



67
68
69
# File 'lib/matest.rb', line 67

def track
  instance_variables.reject {|i| i.to_s =~ /\A@__/}.map {|i| [i, instance_variable_get(i)] }
end