lib/tryouts/drill/response.rb in tryouts-0.7.4 vs lib/tryouts/drill/response.rb in tryouts-0.8.0
- old
+ new
@@ -42,10 +42,12 @@
reality.output <= dream.output
when :ne
reality.output != dream.output
when :respond_to?, :kind_of?, :is_a?
reality.output.send(dream.format, dream.output)
+ when :grep
+ !reality.output.grep(dream.output).empty?
else
if dream.format.nil?
reality.output == dream.output
elsif reality.output.respond_to?(dream.format)
@@ -81,16 +83,14 @@
when :match
"#{reality.output.inspect}.match(#{dream.output.inspect})"
when :gt, :gte, :lt, :lte, :ne
op = {:gt=>'>',:gte=>'>=', :lt=>'<', :lte => '<=', :ne => '!='}.find { |i| i[0] == dream.format }
"#{reality.output.inspect} #{op[1]} #{dream.output.inspect}"
- when :respond_to?
- "#{reality.output.class}.respond_to? #{dream.output.inspect}"
- when :kind_of?
- "#{reality.output.class}.kind_of? #{dream.output.inspect}"
- when :is_a?
- "#{reality.output.class}.is_a? #{dream.output.inspect}"
+ when :respond_to?, :kind_of?, :is_a?
+ "#{reality.output.class}.#{dream.format} #{dream.output.inspect}"
+ when :grep
+ "!#{reality.output}.grep(#{dream.output.inspect}).empty?"
else
if dream.format.nil?
"#{reality.output.inspect} == #{dream.output.inspect}"
elsif reality.output.respond_to?(dream.format)
@@ -122,11 +122,11 @@
d.from_block definition
d
end
def from_block(definition)
- instance_eval &definition
+ self.output = instance_eval &definition
self
end
# Takes a String +val+ and splits the lines into an Array.
def inline(val=nil)
@@ -154,10 +154,12 @@
@output
when :proc
true
when :respond_to?, :is_a?, :kind_of?
true
+ when :grep
+ @output
else
@output
end
end
end
@@ -171,10 +173,12 @@
attr_accessor :stash
attr_accessor :error
attr_accessor :trace
attr_accessor :ecode
attr_accessor :etype
+ # For :cli drills only. Contains the shell command string.
+ attr_accessor :command
def initialize
@stash = Tryouts::HASH_TYPE.new
end
def ==(dream)
@@ -186,10 +190,10 @@
when :proc
test = dream.output
(test.arity > 0 ? test.call(@output) : test.call)
when :exception
@etype
- when :respond_to?, :is_a?, :kind_of?
+ when :respond_to?, :is_a?, :kind_of?, :grep
@output.send(dream.format, dream.output)
when nil
@output
else
return nil if @output.nil?
\ No newline at end of file