Class: Matest::Example
- Inherits:
-
Object
- Object
- Matest::Example
- Defined in:
- lib/matest/example.rb
Direct Known Subclasses
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
- #description ⇒ Object
- #example_block ⇒ Object
-
#initialize(example_block, description, lets) ⇒ Example
constructor
A new instance of Example.
-
#just_before_assertion ⇒ Object
def without_block the_new = self.clone the_new.instance_variable_set(:@example_block__for_internal_use, nil) the_new end.
- #lets ⇒ Object
- #track_lets ⇒ Object
- #track_variables ⇒ Object
Constructor Details
#initialize(example_block, description, lets) ⇒ Example
Returns a new instance of Example.
3 4 5 6 7 8 9 10 11 |
# File 'lib/matest/example.rb', line 3 def initialize(example_block, description, lets) @example_block__for_internal_use = ExampleBlock.new(example_block) @description__for_internal_use = description @lets__for_internal_use = lets lets.each do |let| self.class.let(let.var_name, &let.block) send(let.var_name) if let.bang end end |
Class Method Details
.let(var_name, &block) ⇒ Object
29 30 31 32 33 |
# File 'lib/matest/example.rb', line 29 def self.let(var_name, &block) define_method(var_name) do instance_variable_set(:"@#{var_name}__from_let", block.call) end end |
.local_var(var_name) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/matest/example.rb', line 35 def self.local_var(var_name) define_method(var_name) do instance_variable_get(:"@#{var_name}") end define_method("#{var_name}=") do |value| instance_variable_set(:"@#{var_name}", value) end end |
Instance Method Details
#call ⇒ Object
25 26 27 |
# File 'lib/matest/example.rb', line 25 def call instance_eval(&example_block.block) end |
#description ⇒ Object
21 22 23 |
# File 'lib/matest/example.rb', line 21 def description @description__for_internal_use end |
#example_block ⇒ Object
17 18 19 |
# File 'lib/matest/example.rb', line 17 def example_block @example_block__for_internal_use end |
#just_before_assertion ⇒ Object
def without_block
the_new = self.clone
the_new.instance_variable_set(:@example_block__for_internal_use, nil)
the_new
end
67 68 69 70 |
# File 'lib/matest/example.rb', line 67 def just_before_assertion # return a clone of self, but with ExampleBeforeAssertion.new(example_block.block, description, lets) end |
#lets ⇒ Object
13 14 15 |
# File 'lib/matest/example.rb', line 13 def lets @lets__for_internal_use end |
#track_lets ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/matest/example.rb', line 50 def track_lets instance_variables.select {|var| var.to_s =~ /__from_let\Z/ }.map {|var| name = var.to_s name["__from_let"] = "" name[0] = "" [name, instance_variable_get(var)] } end |
#track_variables ⇒ Object
44 45 46 47 48 |
# File 'lib/matest/example.rb', line 44 def track_variables instance_variables.reject {|var| var.to_s =~ /__for_internal_use\Z/ || var.to_s =~ /__from_let\Z/ }.map {|var| [var, instance_variable_get(var)] } end |