delano-tryouts 0.8.1 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.txt +8 -0
- data/lib/tryouts/drill/response.rb +0 -99
- data/lib/tryouts/drill.rb +5 -1
- data/lib/tryouts/tryout.rb +4 -4
- data/lib/tryouts.rb +4 -4
- data/tryouts/15_dreams_tryouts.rb +24 -10
- data/tryouts/20_cli_tryouts.rb +1 -1
- data/tryouts.gemspec +1 -1
- metadata +1 -1
data/CHANGES.txt
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
TRYOUTS, CHANGES
|
2
2
|
|
3
|
+
|
4
|
+
#### 0.8.2 (2009-07-19) ###############################
|
5
|
+
|
6
|
+
* CHANGE: Moved Drill and Reality to separate files.
|
7
|
+
* CHANGE: dream blocks are now lazy executed just before the
|
8
|
+
drill is executed.
|
9
|
+
|
10
|
+
|
3
11
|
#### 0.8.1 (2009-07-14) ###############################
|
4
12
|
|
5
13
|
* CHANGE: Fixed parentheses warning in tryouts.rb for Ruby 1.8
|
@@ -114,103 +114,4 @@ class Tryouts::Drill
|
|
114
114
|
end
|
115
115
|
|
116
116
|
|
117
|
-
# = Dream
|
118
|
-
#
|
119
|
-
# Contains the expected response of a Drill
|
120
|
-
#
|
121
|
-
class Dream < Tryouts::Drill::Response
|
122
|
-
|
123
|
-
def self.from_block(definition)
|
124
|
-
d = Tryouts::Drill::Dream.new
|
125
|
-
d.from_block definition
|
126
|
-
d
|
127
|
-
end
|
128
|
-
|
129
|
-
def from_block(definition)
|
130
|
-
self.output = instance_eval &definition
|
131
|
-
self
|
132
|
-
end
|
133
|
-
|
134
|
-
# Takes a String +val+ and splits the lines into an Array.
|
135
|
-
def inline(val=nil)
|
136
|
-
lines = (val.split($/) || [])
|
137
|
-
lines.shift if lines.first.strip == ""
|
138
|
-
lines.pop if lines.last.strip == ""
|
139
|
-
lines
|
140
|
-
end
|
141
|
-
|
142
|
-
def ==(reality)
|
143
|
-
return @answer unless @answer.nil?
|
144
|
-
@answer = Response.compare(self, reality)
|
145
|
-
end
|
146
|
-
|
147
|
-
def test_to_string(reality)
|
148
|
-
return @test_string unless @test_string.nil?
|
149
|
-
@test_string = Response.compare_string(self, reality)
|
150
|
-
end
|
151
|
-
|
152
|
-
def comparison_value
|
153
|
-
return @ret unless @ret.nil?
|
154
|
-
@ret = case @format
|
155
|
-
when :gt, :gte, :lt, :lte, :ne
|
156
|
-
op = {:gt=>'>',:gte=>'>=', :lt=>'<', :lte => '<=', :ne => '!='}.find { |i| i[0] == @format }
|
157
|
-
@output
|
158
|
-
when :proc
|
159
|
-
true
|
160
|
-
when :respond_to?, :is_a?, :kind_of?
|
161
|
-
true
|
162
|
-
when :grep
|
163
|
-
@output
|
164
|
-
else
|
165
|
-
@output
|
166
|
-
end
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
# = Reality
|
171
|
-
#
|
172
|
-
# Contains the actual response of a Drill
|
173
|
-
#
|
174
|
-
class Reality < Tryouts::Drill::Response
|
175
|
-
# An ordered hash taken from the DrillContext that created this Reality.
|
176
|
-
attr_accessor :stash
|
177
|
-
attr_accessor :error
|
178
|
-
attr_accessor :trace
|
179
|
-
attr_accessor :ecode
|
180
|
-
attr_accessor :etype
|
181
|
-
# For :cli drills only. Contains the shell command string.
|
182
|
-
attr_accessor :command
|
183
|
-
def initialize
|
184
|
-
@stash = Tryouts::HASH_TYPE.new
|
185
|
-
end
|
186
|
-
|
187
|
-
def ==(dream)
|
188
|
-
Response.compare(dream, self)
|
189
|
-
end
|
190
|
-
|
191
|
-
def comparison_value(dream)
|
192
|
-
case dream.format
|
193
|
-
when :proc
|
194
|
-
test = dream.output
|
195
|
-
(test.arity > 0 ? test.call(@output) : test.call)
|
196
|
-
when :exception
|
197
|
-
@etype
|
198
|
-
when :respond_to?, :is_a?, :kind_of?, :grep
|
199
|
-
@output.send(dream.format, dream.output)
|
200
|
-
when nil
|
201
|
-
@output
|
202
|
-
else
|
203
|
-
return nil if @output.nil?
|
204
|
-
|
205
|
-
if !dream.format.is_a?(Symbol)
|
206
|
-
"This dream format is not a Symbol: #{dream.format}"
|
207
|
-
elsif @output.respond_to?(dream.format)
|
208
|
-
@output.send(dream.format)
|
209
|
-
else
|
210
|
-
@output
|
211
|
-
end
|
212
|
-
end
|
213
|
-
end
|
214
|
-
end
|
215
|
-
|
216
117
|
end
|
data/lib/tryouts/drill.rb
CHANGED
@@ -10,6 +10,8 @@ class Tryouts
|
|
10
10
|
|
11
11
|
require 'tryouts/drill/context'
|
12
12
|
require 'tryouts/drill/response'
|
13
|
+
require 'tryouts/drill/dream'
|
14
|
+
require 'tryouts/drill/reality'
|
13
15
|
require 'tryouts/drill/sergeant/cli'
|
14
16
|
require 'tryouts/drill/sergeant/api'
|
15
17
|
require 'tryouts/drill/sergeant/benchmark'
|
@@ -24,7 +26,6 @@ class Tryouts
|
|
24
26
|
attr_reader :name
|
25
27
|
# A Proc object which contains the drill logic.
|
26
28
|
attr_reader :drill
|
27
|
-
|
28
29
|
# A Sergeant object which executes the drill
|
29
30
|
attr_reader :sergeant
|
30
31
|
# An Array of Dream objects (the expected output of the test)
|
@@ -97,6 +98,9 @@ class Tryouts
|
|
97
98
|
def skip?; @skip; end
|
98
99
|
|
99
100
|
def run(context=nil)
|
101
|
+
unless @dreams.empty?
|
102
|
+
@dreams.each { |d| d.execute_output_block }
|
103
|
+
end
|
100
104
|
begin
|
101
105
|
@reality = @sergeant.run @drill, context
|
102
106
|
# Store the stash from the drill block
|
data/lib/tryouts/tryout.rb
CHANGED
@@ -147,11 +147,11 @@ class Tryouts
|
|
147
147
|
args = args.size == 1 ? [args.first] : args.reverse
|
148
148
|
dobj = Tryouts::Drill::Dream.new(*args)
|
149
149
|
else
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
dobj = Tryouts::Drill::Dream.from_block definition
|
150
|
+
msg = "Dreams with blocks take only 1 argument (Tryout: '#{@name}')"
|
151
|
+
raise TooManyArgs, msg if args.size > 1
|
152
|
+
dobj = Tryouts::Drill::Dream.new
|
154
153
|
dobj.format = args.first if args.size == 1
|
154
|
+
dobj.output_block = definition
|
155
155
|
end
|
156
156
|
@dream_catcher.push dobj
|
157
157
|
dobj
|
data/lib/tryouts.rb
CHANGED
@@ -34,9 +34,9 @@ class Tryouts
|
|
34
34
|
class Exception < RuntimeError; end
|
35
35
|
# = BadDreams
|
36
36
|
# Raised when there is a problem loading or parsing a Tryouts::Drill::Dream object
|
37
|
-
class BadDream < Exception; end
|
38
|
-
|
39
|
-
class NoDrillType < Exception
|
37
|
+
class BadDream < Tryouts::Exception; end
|
38
|
+
class TooManyArgs < Tryouts::Exception; end
|
39
|
+
class NoDrillType < Tryouts::Exception
|
40
40
|
attr_accessor :tname
|
41
41
|
def initialize(t); @tname = t; end
|
42
42
|
def message
|
@@ -45,7 +45,7 @@ class Tryouts
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
VERSION = "0.8.
|
48
|
+
VERSION = "0.8.2"
|
49
49
|
|
50
50
|
require 'tryouts/mixins'
|
51
51
|
require 'tryouts/tryout'
|
@@ -3,6 +3,10 @@ group "Syntax"
|
|
3
3
|
|
4
4
|
tryouts "Dreams" do
|
5
5
|
|
6
|
+
setup do
|
7
|
+
Tryouts.const_set :TEST_VALUE, 9000
|
8
|
+
end
|
9
|
+
|
6
10
|
drill "dream inline", :muggsy do
|
7
11
|
:muggsy
|
8
12
|
end
|
@@ -15,7 +19,7 @@ tryouts "Dreams" do
|
|
15
19
|
dream do
|
16
20
|
:muggsy
|
17
21
|
end
|
18
|
-
drill "dream output
|
22
|
+
drill "dream output can be specified with a block" do
|
19
23
|
:muggsy
|
20
24
|
end
|
21
25
|
|
@@ -26,15 +30,25 @@ tryouts "Dreams" do
|
|
26
30
|
:muggsy
|
27
31
|
end
|
28
32
|
|
29
|
-
|
33
|
+
# NOTE: The constant is defined in the setup block which is called before the
|
34
|
+
# drill block is executed. As of 0.8.2 the dream block is executed literally
|
35
|
+
# just before the drill block which is why this test returns true.
|
36
|
+
dream do
|
37
|
+
Tryouts.const_get :TEST_VALUE
|
38
|
+
end
|
39
|
+
drill "dream output from a block is executed just before the drill" do
|
40
|
+
9000
|
41
|
+
end
|
42
|
+
|
43
|
+
## NOTE: The following should raise a Tryouts::TooManyArgs error b/c dreams takes 1 arg
|
44
|
+
#
|
45
|
+
#dream :class, 2 do
|
46
|
+
# Symbol
|
47
|
+
#end
|
48
|
+
#drill "dream with a format argument and a block" do
|
49
|
+
# :muggsy
|
50
|
+
#end
|
30
51
|
#
|
31
|
-
|
32
|
-
## Symbol
|
33
|
-
##end
|
34
|
-
##drill "dream with a format argument and a block" do
|
35
|
-
## :muggsy
|
36
|
-
##end
|
37
|
-
|
38
|
-
xdrill "this drill will fail b/c it has no dream", :muggsy
|
52
|
+
#drill "this drill will fail b/c it has no dream", :muggsy
|
39
53
|
|
40
54
|
end
|
data/tryouts/20_cli_tryouts.rb
CHANGED
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.2"
|
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"
|