Class: Tryouts::Drill::Dream
- Defined in:
- lib/tryouts/drill/dream.rb
Overview
Dream
Contains the expected response of a Drill
Instance Attribute Summary collapse
-
#output_block ⇒ Object
A proc which is run just before the associated drill.
Attributes inherited from Response
Instance Method Summary collapse
- #==(reality) ⇒ Object
- #comparison_value ⇒ Object
-
#execute_output_block(&definition) ⇒ Object
Populates
@output
with the return value ofoutput_block
or&definition
if provided. -
#inline(val = nil) ⇒ Object
Takes a String
val
and splits the lines into an Array. - #test_to_string(reality) ⇒ Object
Methods inherited from Response
compare, compare_string, #initialize
Constructor Details
This class inherits a constructor from Tryouts::Drill::Response
Instance Attribute Details
#output_block ⇒ Object
A proc which is run just before the associated drill. The return value overrides @output
.
12 13 14 |
# File 'lib/tryouts/drill/dream.rb', line 12 def output_block @output_block end |
Instance Method Details
#==(reality) ⇒ Object
30 31 32 33 |
# File 'lib/tryouts/drill/dream.rb', line 30 def ==(reality) return @answer unless @answer.nil? @answer = Response.compare(self, reality) end |
#comparison_value ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/tryouts/drill/dream.rb', line 40 def comparison_value return @ret unless @ret.nil? @ret = case @format when :gt, :gte, :lt, :lte, :ne op = {:gt=>'>',:gte=>'>=', :lt=>'<', :lte => '<=', :ne => '!='}.find { |i| i[0] == @format } @output when :proc true when :respond_to?, :is_a?, :kind_of? true when :grep @output else @output end end |
#execute_output_block(&definition) ⇒ Object
Populates @output
with the return value of output_block
or &definition
if provided.
16 17 18 19 20 |
# File 'lib/tryouts/drill/dream.rb', line 16 def execute_output_block(&definition) definition ||= @output_block return if definition.nil? self.output = instance_eval &definition end |
#inline(val = nil) ⇒ Object
Takes a String val
and splits the lines into an Array.
23 24 25 26 27 28 |
# File 'lib/tryouts/drill/dream.rb', line 23 def inline(val=nil) lines = (val.split($/) || []) lines.shift if lines.first.strip == "" lines.pop if lines.last.strip == "" lines end |
#test_to_string(reality) ⇒ Object
35 36 37 38 |
# File 'lib/tryouts/drill/dream.rb', line 35 def test_to_string(reality) return @test_string unless @test_string.nil? @test_string = Response.compare_string(self, reality) end |