Class: Speq::TestBlock
- Inherits:
-
Object
- Object
- Speq::TestBlock
- Defined in:
- lib/speq.rb,
lib/speq/string_fmt.rb
Overview
Test code executes within the context of this class
Constant Summary collapse
- METHODS =
%i[speq on does with of is].freeze
Instance Method Summary collapse
-
#initialize(parent, &block) ⇒ TestBlock
constructor
A new instance of TestBlock.
- #inspect ⇒ Object
- #method_missing(method_name, *args, &block) ⇒ Object
- #respond_to_missing?(method_name) ⇒ Boolean
- #speq(description, &block) ⇒ Object
Constructor Details
#initialize(parent, &block) ⇒ TestBlock
Returns a new instance of TestBlock.
18 19 20 21 22 |
# File 'lib/speq.rb', line 18 def initialize(parent, &block) @outer_scope = eval('self', block.binding) @parent = parent instance_eval(&block) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/speq.rb', line 28 def method_missing(method_name, *args, &block) if METHODS.include?(method_name) || @parent.context && Question.question?(method_name) Expression.new(@parent).send(method_name, *args, &block) elsif @outer_scope.respond_to?(method_name) @outer_scope.send(method_name, *args, &block) else super end end |
Instance Method Details
#inspect ⇒ Object
7 8 9 |
# File 'lib/speq/string_fmt.rb', line 7 def inspect "block in '#{@parent.description}'" end |
#respond_to_missing?(method_name) ⇒ Boolean
39 40 41 42 43 |
# File 'lib/speq.rb', line 39 def respond_to_missing?(method_name, *) METHODS.include?(method_name) || @outer_scope.respond_to?(method_name) || super end |