tryouts 0.8.2 → 0.8.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.txt +5 -0
- data/lib/tryouts.rb +1 -1
- data/lib/tryouts/drill/dream.rb +57 -0
- data/lib/tryouts/drill/reality.rb +49 -0
- data/tryouts.gemspec +3 -1
- metadata +3 -1
data/CHANGES.txt
CHANGED
data/lib/tryouts.rb
CHANGED
@@ -0,0 +1,57 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
class Tryouts::Drill
|
4
|
+
# = Dream
|
5
|
+
#
|
6
|
+
# Contains the expected response of a Drill
|
7
|
+
#
|
8
|
+
class Dream < Tryouts::Drill::Response
|
9
|
+
|
10
|
+
# A proc which is run just before the associated drill.
|
11
|
+
# The return value overrides <tt>@output</tt>.
|
12
|
+
attr_accessor :output_block
|
13
|
+
|
14
|
+
# Populates <tt>@output</tt> with the return value of
|
15
|
+
# <tt>output_block</tt> or <tt>&definition</tt> if provided.
|
16
|
+
def execute_output_block(&definition)
|
17
|
+
definition ||= @output_block
|
18
|
+
return if definition.nil?
|
19
|
+
self.output = instance_eval &definition
|
20
|
+
end
|
21
|
+
|
22
|
+
# Takes a String +val+ and splits the lines into an Array.
|
23
|
+
def inline(val=nil)
|
24
|
+
lines = (val.split($/) || [])
|
25
|
+
lines.shift if lines.first.strip == ""
|
26
|
+
lines.pop if lines.last.strip == ""
|
27
|
+
lines
|
28
|
+
end
|
29
|
+
|
30
|
+
def ==(reality)
|
31
|
+
return @answer unless @answer.nil?
|
32
|
+
@answer = Response.compare(self, reality)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_to_string(reality)
|
36
|
+
return @test_string unless @test_string.nil?
|
37
|
+
@test_string = Response.compare_string(self, reality)
|
38
|
+
end
|
39
|
+
|
40
|
+
def comparison_value
|
41
|
+
return @ret unless @ret.nil?
|
42
|
+
@ret = case @format
|
43
|
+
when :gt, :gte, :lt, :lte, :ne
|
44
|
+
op = {:gt=>'>',:gte=>'>=', :lt=>'<', :lte => '<=', :ne => '!='}.find { |i| i[0] == @format }
|
45
|
+
@output
|
46
|
+
when :proc
|
47
|
+
true
|
48
|
+
when :respond_to?, :is_a?, :kind_of?
|
49
|
+
true
|
50
|
+
when :grep
|
51
|
+
@output
|
52
|
+
else
|
53
|
+
@output
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
class Tryouts::Drill
|
2
|
+
|
3
|
+
# = Reality
|
4
|
+
#
|
5
|
+
# Contains the actual response of a Drill
|
6
|
+
#
|
7
|
+
class Reality < Tryouts::Drill::Response
|
8
|
+
# An ordered hash taken from the DrillContext that created this Reality.
|
9
|
+
attr_accessor :stash
|
10
|
+
attr_accessor :error
|
11
|
+
attr_accessor :trace
|
12
|
+
attr_accessor :ecode
|
13
|
+
attr_accessor :etype
|
14
|
+
# For :cli drills only. Contains the shell command string.
|
15
|
+
attr_accessor :command
|
16
|
+
def initialize
|
17
|
+
@stash = Tryouts::HASH_TYPE.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def ==(dream)
|
21
|
+
Response.compare(dream, self)
|
22
|
+
end
|
23
|
+
|
24
|
+
def comparison_value(dream)
|
25
|
+
case dream.format
|
26
|
+
when :proc
|
27
|
+
test = dream.output
|
28
|
+
(test.arity > 0 ? test.call(@output) : test.call)
|
29
|
+
when :exception
|
30
|
+
@etype
|
31
|
+
when :respond_to?, :is_a?, :kind_of?, :grep
|
32
|
+
@output.send(dream.format, dream.output)
|
33
|
+
when nil
|
34
|
+
@output
|
35
|
+
else
|
36
|
+
return nil if @output.nil?
|
37
|
+
|
38
|
+
if !dream.format.is_a?(Symbol)
|
39
|
+
"This dream format is not a Symbol: #{dream.format}"
|
40
|
+
elsif @output.respond_to?(dream.format)
|
41
|
+
@output.send(dream.format)
|
42
|
+
else
|
43
|
+
@output
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
data/tryouts.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
@spec = Gem::Specification.new do |s|
|
2
2
|
s.name = "tryouts"
|
3
3
|
s.rubyforge_project = "tryouts"
|
4
|
-
s.version = "0.8.
|
4
|
+
s.version = "0.8.3"
|
5
5
|
s.summary = "Tryouts is a high-level testing library (DSL) for your Ruby codes and command-line applications."
|
6
6
|
s.description = s.summary
|
7
7
|
s.author = "Delano Mandelbaum"
|
@@ -49,6 +49,8 @@
|
|
49
49
|
lib/tryouts/cli/run.rb
|
50
50
|
lib/tryouts/drill.rb
|
51
51
|
lib/tryouts/drill/context.rb
|
52
|
+
lib/tryouts/drill/dream.rb
|
53
|
+
lib/tryouts/drill/reality.rb
|
52
54
|
lib/tryouts/drill/response.rb
|
53
55
|
lib/tryouts/drill/sergeant/api.rb
|
54
56
|
lib/tryouts/drill/sergeant/benchmark.rb
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tryouts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Delano Mandelbaum
|
@@ -64,6 +64,8 @@ files:
|
|
64
64
|
- lib/tryouts/cli/run.rb
|
65
65
|
- lib/tryouts/drill.rb
|
66
66
|
- lib/tryouts/drill/context.rb
|
67
|
+
- lib/tryouts/drill/dream.rb
|
68
|
+
- lib/tryouts/drill/reality.rb
|
67
69
|
- lib/tryouts/drill/response.rb
|
68
70
|
- lib/tryouts/drill/sergeant/api.rb
|
69
71
|
- lib/tryouts/drill/sergeant/benchmark.rb
|