delano-tryouts 0.6.1 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.txt CHANGED
@@ -1,6 +1,17 @@
1
1
  TRYOUTS, CHANGES
2
2
 
3
3
 
4
+ #### 0.6.2 (2009-06-24) ###############################
5
+
6
+ NOTE: command testing (:cli) is still disabled.
7
+
8
+ * CHANGE: dream arguments are now ordered: format, output
9
+ * ADDED: One-liner drill syntax
10
+ * ADDED: new dream formats: :regex, :gt, :gte, :lt, :lte, :size
11
+ * ADDED: Calls to xdrill now also clear the dream catcher
12
+ * ADDED: Support for multiple dreams per drill
13
+
14
+
4
15
  #### 0.6.1 (2009-06-24) ###############################
5
16
 
6
17
  NOTE: command testing (:cli) is still disabled.
data/bin/sergeant CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  TRYOUTS_HOME = File.expand_path(File.join(File.dirname(__FILE__), '..'))
4
4
 
5
+ $:.unshift File.join(TRYOUTS_HOME, 'lib')
6
+
5
7
  #local_libs = %w{tryouts net-scp amazon-ec2 aws-s3 caesars drydock rye storable sysinfo annoy}
6
8
  #local_libs.each { |dir| $:.unshift File.join(TRYOUTS_HOME, '..', dir, 'lib') }
7
9
 
data/lib/tryouts.rb CHANGED
@@ -29,7 +29,7 @@ class Tryouts
29
29
  # Raised when there is a problem loading or parsing a Tryouts::Drill::Dream object
30
30
  class BadDreams < Exception; end
31
31
 
32
- VERSION = "0.6.1"
32
+ VERSION = "0.6.2"
33
33
 
34
34
  require 'tryouts/mixins'
35
35
  require 'tryouts/tryout'
@@ -41,7 +41,7 @@ class Tryouts
41
41
  TRYOUT_MSG = "\n %s "
42
42
  DRILL_MSG = ' %-50s '
43
43
  DRILL_ERR = ' %s: '
44
-
44
+
45
45
  # An Array of +_tryouts.rb+ file paths that have been loaded.
46
46
  @@loaded_files = []
47
47
  # An Hash of Tryouts instances stored under the name of the Tryouts subclass.
@@ -86,7 +86,7 @@ class Tryouts
86
86
  end
87
87
 
88
88
  # Populate this Tryouts from a block. The block should contain calls to
89
- # the external DSL methods: tryout, command, dreams
89
+ # the external DSL methods: tryout, command, library, group
90
90
  def from_block(b, &inline)
91
91
  instance_eval &b
92
92
  end
@@ -58,8 +58,8 @@ class Run < Drydock::Command
58
58
  msg = " You didn't even try to acheive your dreams :[ "
59
59
  elsif failed == 0
60
60
  puts PUG if Tryouts.verbose > 4
61
- msg = " All %s dreams came true ".color(:green)
62
- msg = msg % [passed+failed]
61
+ msg = passed > 1 ? "All %s dreams" : "Your only dream"
62
+ msg = (" #{msg} came true " % [passed+failed]).color(:green)
63
63
  else
64
64
  puts BUG if Tryouts.verbose > 4
65
65
  score = (passed.to_f / (passed.to_f+failed.to_f)) * 100
data/lib/tryouts/drill.rb CHANGED
@@ -24,30 +24,29 @@ class Tryouts
24
24
 
25
25
  # A Sergeant object which executes the drill
26
26
  attr_reader :sergeant
27
- # A Dream object (the expected output of the test)
28
- attr_reader :dream
27
+ # An Array of Dream objects (the expected output of the test)
28
+ attr_reader :dreams
29
29
  # A Reality object (the actual output of the test)
30
30
  attr_reader :reality
31
31
 
32
- def initialize(name, dtype, *opts, &drill)
32
+ def initialize(name, dtype, *args, &drill)
33
33
  @name, @dtype, @drill = name, dtype, drill
34
- @sergeant = hire_sergeant opts
35
- # For CLI drills, a block takes precedence over inline args.
36
- # A block will contain multiple shell commands (see Rye::Box#batch)
37
- drill_args = [] if dtype == :cli && drill.is_a?(Proc)
38
- @reality = Tryouts::Drill::Reality.new
39
- end
40
-
41
- def hire_sergeant(opts={})
34
+ @dreams = []
42
35
  if @dtype == :cli
43
- Tryouts::Drill::Sergeant::CLI.new(*opts)
36
+ @sergeant = Tryouts::Drill::Sergeant::CLI.new *args
44
37
  elsif @dtype == :api
45
- Tryouts::Drill::Sergeant::API.new(opts.first) # should be a hash
38
+ default_output = drill.nil? ? args.shift : nil
39
+ @sergeant = Tryouts::Drill::Sergeant::API.new default_output
40
+ @dreams << Tryouts::Drill::Dream.new(*args) unless args.empty?
46
41
  else
47
42
  raise NoSergeant, "Weird drill sergeant: #{@dtype}"
48
43
  end
44
+ # For CLI drills, a block takes precedence over inline args.
45
+ # A block will contain multiple shell commands (see Rye::Box#batch)
46
+ drill_args = [] if dtype == :cli && drill.is_a?(Proc)
47
+ @reality = Tryouts::Drill::Reality.new
49
48
  end
50
-
49
+
51
50
  def run(context=nil)
52
51
  begin
53
52
  print Tryouts::DRILL_MSG % @name
@@ -55,11 +54,10 @@ class Tryouts
55
54
  # Store the stash from the drill block
56
55
  @reality.stash = context.stash if context.respond_to? :stash
57
56
  # If the drill block returned true we assume success if there's no dream
58
- if @dream.nil? && @reality.output == true
59
- @dream = Tryouts::Drill::Dream.new
60
- @dream.output = true
57
+ if @dreams.empty? && @reality.output == true
58
+ @dreams << Tryouts::Drill::Dream.new
59
+ @dreams.first.output = true
61
60
  end
62
- process_reality
63
61
  rescue => ex
64
62
  @reality.ecode, @reality.etype = -2, ex.class
65
63
  @reality.error, @reality.trace = ex.message, ex.backtrace
@@ -68,24 +66,14 @@ class Tryouts
68
66
  end
69
67
 
70
68
  def success?
71
- @dream == @reality
69
+ @dreams.each { |d| return false unless d == @reality }
70
+ true
72
71
  end
73
72
 
74
73
 
75
- def add_dream(d)
76
- @dream = d
77
- end
74
+ def add_dream(d); @dreams << d; end
75
+ def add_dreams(*d); @dreams += d; end
78
76
 
79
77
  private
80
-
81
- # Use the :format provided in the dream to convert the output from reality
82
- def process_reality
83
- case @dream.format
84
- when :class
85
- @reality.output = @reality.output.class
86
- when :exception
87
- @reality.output = @reality.etype
88
- end
89
- end
90
-
78
+
91
79
  end; end
@@ -19,7 +19,27 @@ class Tryouts::Drill
19
19
  ## I don't think this check is necessary or useful
20
20
  ##return false unless reality.error.nil? && reality.trace.nil?
21
21
  return true if reality.output == true and dream.nil?
22
- reality.output == dream.output
22
+
23
+ case dream.format
24
+ when :class
25
+ reality.output.class == dream.output
26
+ when :exception
27
+ reality.etype == dream.output
28
+ when :regex
29
+ !reality.output.match(dream.output).nil?
30
+ when :size
31
+ reality.output.size == dream.output
32
+ when :gt
33
+ reality.output > dream.output
34
+ when :gte
35
+ reality.output >= dream.output
36
+ when :lt
37
+ reality.output < dream.output
38
+ when :lte
39
+ reality.output <= dream.output
40
+ else
41
+ reality.output == dream.output
42
+ end
23
43
 
24
44
  end
25
45
  end
@@ -9,14 +9,14 @@ class Tryouts; class Drill; module Sergeant
9
9
  #
10
10
  class API
11
11
 
12
- attr_reader :opts
12
+ attr_reader :output
13
13
 
14
14
  # +opts+ is a Hash with the following optional keys:
15
15
  #
16
16
  # * +:output+ specify a return value. This will be
17
17
  # used if no block is specified for the drill.
18
- def initialize(opts={})
19
- @opts = opts
18
+ def initialize(output=nil)
19
+ @output = output
20
20
  end
21
21
 
22
22
  def run(block, context, &inline)
@@ -24,7 +24,7 @@ class Tryouts; class Drill; module Sergeant
24
24
  runtime = (block.nil? ? inline : block)
25
25
  response = Tryouts::Drill::Reality.new
26
26
  if runtime.nil?
27
- response.output = @opts[:output]
27
+ response.output = @output
28
28
  else
29
29
  begin
30
30
  response.output = context.instance_eval &runtime
@@ -20,6 +20,12 @@ class Hash
20
20
  end
21
21
  steps
22
22
  end
23
-
23
+
24
+ unless method_defined?(:last)
25
+ def last
26
+ self[ self.keys.last ]
27
+ end
28
+ end
29
+
24
30
  end
25
31
 
@@ -53,7 +53,7 @@ class Tryouts
53
53
  puts Tryouts::TRYOUT_MSG.bright % @name
54
54
  @drills.each do |drill|
55
55
  drill.run DrillContext.new
56
- note = @dream ? '' : '(nodream)'
56
+ note = drill.dreams.empty? ? '[nodream]' : ''
57
57
  puts drill.success? ? "PASS".color(:green) : "FAIL #{note}".color(:red)
58
58
  puts " #{drill.reality.output.inspect}" if Tryouts.verbose > 0
59
59
  if Tryouts.verbose > 1
@@ -71,12 +71,17 @@ class Tryouts
71
71
  return true if success?
72
72
  failed = @drills.select { |d| !d.success? }
73
73
  failed.each_with_index do |drill,index|
74
- dream, reality = drill.dream, drill.reality
74
+ dreams, reality = drill.dreams, drill.reality
75
75
  title = ' %-59s' % %Q{ERROR #{index+1}/#{failed.size} "#{drill.name}"}
76
76
  puts $/, ' ' << title.color(:red).att(:reverse)
77
77
 
78
- if dream
79
- puts '%12s: %s' % [ "expected", dream.output.inspect]
78
+ if dreams.empty?
79
+ puts '%12s: %s' % ["expected", "[nodream]"]
80
+ puts '%12s: %s' % ["returned", reality.output.inspect]
81
+ else
82
+ dreams.each do |dream|
83
+ puts '%12s: %s' % [ "expected", dream.output.inspect]
84
+ end
80
85
  puts '%12s: %s' % ["returned", reality.output.inspect]
81
86
  unless reality.error.nil?
82
87
  puts '%12s: %s' % ["error", reality.error.inspect]
@@ -85,11 +90,8 @@ class Tryouts
85
90
  puts '%12s: %s' % ["trace", reality.trace.join($/ + ' '*14)]
86
91
  puts
87
92
  end
88
- else
89
- puts '%12s: %s' % ["expected", "[nodream]"]
90
- puts '%12s: %s' % ["returned", reality.output.inspect]
93
+
91
94
  end
92
-
93
95
  end
94
96
  false
95
97
  end
@@ -105,8 +107,8 @@ class Tryouts
105
107
  # more dreams in +@dream_catcher+, it will be added to drill +d+.
106
108
  def add_drill(d)
107
109
  unless @dream_catcher.empty?
108
- d.add_dream @dream_catcher.first
109
- @dream_catcher.clear
110
+ d.add_dreams *@dream_catcher.clone # We need to clone here b/c
111
+ @dream_catcher.clear # Ruby passes by reference.
110
112
  end
111
113
  drills << d
112
114
  d
@@ -131,15 +133,11 @@ class Tryouts
131
133
  # +args+ is sent directly to the Drill class. The values are specific on the Sergeant.
132
134
  def drill(dname, *args, &definition)
133
135
  raise "Empty drill name (#{@name})" if dname.nil? || dname.empty?
134
- if definition.nil?
135
- drill = Tryouts::Drill.new(dname, @dtype, :output => args.first)
136
- else
137
- drill = Tryouts::Drill.new(dname, @dtype, args.first, &definition)
138
- end
136
+ drill = Tryouts::Drill.new(dname, @dtype, *args, &definition)
139
137
  self.add_drill drill
140
138
  end
141
139
  # A quick way to comment out a drill
142
- def xdrill(*args, &b); end # ignore calls to xdrill
140
+ def xdrill(*args, &b); @dream_catcher.clear; end # ignore calls to xdrill
143
141
 
144
142
 
145
143
  #
@@ -149,12 +147,12 @@ class Tryouts
149
147
  dobj = Tryouts::Drill::Dream.from_block definition
150
148
  else
151
149
  if args.size == 1
152
- dobj = Tryouts::Drill::Dream.new(args.shift) # dream 'OUTPUT'
150
+ dobj = Tryouts::Drill::Dream.new(args.shift) # dream 'OUTPUT'
153
151
  else
154
- dobj = Tryouts::Drill::Dream.new(*args.reverse) # dream :form, 'OUTPUT'
152
+ dobj = Tryouts::Drill::Dream.new(*args) # dream 'OUTPUT', :format
155
153
  end
156
154
  end
157
- @dream_catcher << dobj
155
+ @dream_catcher.push dobj
158
156
  dobj
159
157
  end
160
158
  # A quick way to comment out a dream
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.6.1"
4
+ s.version = "0.6.2"
5
5
  s.summary = "Tryouts are high-level tests for your Ruby code. May all your dreams come true!"
6
6
  s.description = s.summary
7
7
  s.author = "Delano Mandelbaum"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: delano-tryouts
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Delano Mandelbaum