Class: Tryouts::Drill::Dream

Inherits:
Response show all
Defined in:
lib/tryouts/drill/response.rb

Overview

Dream

Contains the expected response of a Drill

Instance Attribute Summary

Attributes inherited from Response

#format, #output

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Response

compare, compare_string, #initialize

Constructor Details

This class inherits a constructor from Tryouts::Drill::Response

Class Method Details

.from_block(definition) ⇒ Object



123
124
125
126
127
# File 'lib/tryouts/drill/response.rb', line 123

def self.from_block(definition)
  d = Tryouts::Drill::Dream.new
  d.from_block definition
  d
end

Instance Method Details

#==(reality) ⇒ Object



142
143
144
145
# File 'lib/tryouts/drill/response.rb', line 142

def ==(reality)
  return @answer unless @answer.nil?
  @answer = Response.compare(self, reality)
end

#comparison_valueObject



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/tryouts/drill/response.rb', line 152

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

#from_block(definition) ⇒ Object



129
130
131
132
# File 'lib/tryouts/drill/response.rb', line 129

def from_block(definition)
  self.output = instance_eval &definition
  self
end

#inline(val = nil) ⇒ Object

Takes a String val and splits the lines into an Array.



135
136
137
138
139
140
# File 'lib/tryouts/drill/response.rb', line 135

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



147
148
149
150
# File 'lib/tryouts/drill/response.rb', line 147

def test_to_string(reality)
  return @test_string unless @test_string.nil?
  @test_string = Response.compare_string(self, reality)
end