tryouts 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.txt CHANGED
@@ -1,6 +1,16 @@
1
1
  TRYOUTS, CHANGES
2
2
 
3
3
 
4
+ #### 0.5.0 (2009-06-07) ###############################
5
+
6
+ * FIXED: Fix for running drills without dreams and for specifying verbose without a command name
7
+ * CHANGE: The executable has been renamed to 'sergeant'
8
+ * CHANGE: Gave reality a default rcode (0)
9
+ * CHANGE: Now using module_eval (was: class_eval) for setup and clean
10
+ * ADDED: Displays percentage of failed dreams
11
+ * ADDED: Drill stash!
12
+ * ADDED: xdream and better handling for drills and dreams with no name
13
+
4
14
  #### 0.4.1 (2009-06-07) ###############################
5
15
 
6
16
  * CHANGE: The CLI output is no longer terrifyingly ugly.
data/README.rdoc CHANGED
@@ -67,15 +67,16 @@ Tryouts employs the same approach for testing Ruby codes. The return value of th
67
67
  end
68
68
 
69
69
 
70
- == ALPHA Notice
70
+ == BETA Notice
71
71
 
72
72
  This library is very new (est. 2009-05-19) and has not been vetted by the scrutiny of time. In particular you can expect:
73
73
 
74
- * Ugly/awkward output from the tryouts executable. I wrote the core functionality that I needed to start writing tryouts for my other projects. I haven't spent very much time on reporting yet. However, this will change!
75
74
  * The test definition syntax may change in future releases.
76
75
  * Unexpected errors.
77
76
 
77
+
78
78
  == 3 Ways to define tryouts
79
+
79
80
  There are three ways to define an instance of this class:
80
81
  * In +_tryouts.rb+ files using the DSL syntax. One file per Tryouts object.
81
82
  * See: http://github.com/delano/tryouts/blob/master/tryouts/mockoutcli_tryouts.rb
@@ -1,4 +1,4 @@
1
- #!/usr/local/bin/ruby
1
+ #!/usr/bin/ruby
2
2
 
3
3
  TRYOUTS_HOME = File.expand_path(File.join(File.dirname(__FILE__), '..'))
4
4
 
@@ -15,7 +15,7 @@ require 'tryouts/cli'
15
15
  module TryoutsCLI
16
16
  extend Drydock
17
17
 
18
- debug :off
18
+ debug :on
19
19
  default :run, :with_args
20
20
 
21
21
  global :q, :quiet, "Decrease output"
@@ -26,14 +26,29 @@ module TryoutsCLI
26
26
 
27
27
  about "Run tryouts from current working directory"
28
28
  argv :files
29
+ option :q, :quiet, "Decrease output (same as global)"
30
+ option :v, :verbose, "Increase output (same as global)" do
31
+ @verbose ||= 0
32
+ @verbose += 1
33
+ end
29
34
  command :run => Tryouts::CLI::Run
30
35
 
31
36
  about "Show dreams available from the current working directory"
32
37
  argv :files
38
+ option :q, :quiet, "Decrease output (same as global)"
39
+ option :v, :verbose, "Increase output (same as global)" do
40
+ @verbose ||= 0
41
+ @verbose += 1
42
+ end
33
43
  command :dreams => Tryouts::CLI::Run
34
44
 
35
45
  about "Show tryouts available from the current working directory"
36
46
  argv :files
47
+ option :q, :quiet, "Decrease output (same as global)"
48
+ option :v, :verbose, "Increase output (same as global)" do
49
+ @verbose ||= 0
50
+ @verbose += 1
51
+ end
37
52
  command :list => Tryouts::CLI::Run
38
53
 
39
54
  end
data/lib/tryouts.rb CHANGED
@@ -30,7 +30,7 @@ class Tryouts
30
30
  # Raised when there is a problem loading or parsing a Tryouts::Drill::Dream object
31
31
  class BadDreams < Exception; end
32
32
 
33
- VERSION = "0.4.1"
33
+ VERSION = "0.5.0"
34
34
 
35
35
  require 'tryouts/mixins'
36
36
  require 'tryouts/tryout'
@@ -119,7 +119,6 @@ class Tryouts
119
119
  @@instances.last.command(*args)
120
120
  end
121
121
 
122
-
123
122
  # Require +name+. If +path+ is supplied, it will "require path".
124
123
  # * +name+ The name of the library in question (required). Stored as a Symbol to +@library+.
125
124
  # * +path+ Add a path to the front of $LOAD_PATH (optional). Use this if you want to load
@@ -165,6 +164,9 @@ class Tryouts
165
164
  return if name.nil?
166
165
  dtype ||= @dtype
167
166
  command ||= @command if dtype == :cli
167
+
168
+ raise "No drill type specified for #{name}." if dtype.nil?
169
+
168
170
  to = find_tryout(name, dtype)
169
171
  if to.nil?
170
172
  to = Tryouts::Tryout.new(name, dtype, command)
@@ -261,6 +263,19 @@ class Tryouts
261
263
  end
262
264
  end
263
265
 
266
+ # Returns +@tryouts+.
267
+ #
268
+ # Also acts as a stub for Tryouts#tryout in case someone
269
+ # specifies "tryouts 'name' do ..." in the DSL.
270
+ def tryouts(*args, &block)
271
+ return tryout(*args, &block) unless args.empty?
272
+ @tryouts
273
+ end
274
+ # An alias for Tryouts.tryout.
275
+ def self.tryouts(*args, &block)
276
+ tryout(args, &block)
277
+ end
278
+
264
279
  # +name+ of the Drill associated to this Dream
265
280
  # +output+ A String or Array of expected output. A Dream object will be created using this value (optional)
266
281
  # +definition+ is a block which will be run on an instance of Dream
@@ -295,6 +310,15 @@ class Tryouts
295
310
  @@instances.last.dream(*args, &block)
296
311
  end
297
312
 
313
+ # This method does nothing. It provides a quick way to disable a dream.
314
+ #
315
+ # NOTE: This is a DSL-only method and is not intended for OO use.
316
+ def xdream(*args, &block); end
317
+ # This method does nothing. It provides a quick way to disable a dream.
318
+ #
319
+ # NOTE: this is a standalone DSL-syntax method.
320
+ def self.xdream(*args, &block); end
321
+
298
322
  # Populate @@dreams with the content of the file +dpath+.
299
323
  #
300
324
  # NOTE: this is an OO syntax method
@@ -1,124 +1,171 @@
1
1
 
2
2
  class Tryouts; module CLI
3
3
 
4
- # = Run
5
- #
6
- # The logic bin/tryouts uses for running tryouts.
7
- class Run < Drydock::Command
4
+ # = Run
5
+ #
6
+ # The logic bin/tryouts uses for running tryouts.
7
+ class Run < Drydock::Command
8
8
 
9
- def init
10
- @tryouts_globs = [GYMNASIUM_GLOB, File.join(Dir.pwd, '*_tryouts.rb')]
11
- end
12
-
13
- def dreams
14
- load_available_tryouts_files
15
- if @global.verbose > 0
16
- puts Tryouts.dreams.to_yaml
17
- else
18
- Tryouts.dreams.each_pair do |n,dreams|
19
- puts n
20
- dreams.each_pair do |n, dream|
21
- puts " " << n
22
- dream.each_pair do |n, drill|
23
- puts " " << n
24
- end
9
+ def init
10
+ @tryouts_globs = [GYMNASIUM_GLOB, File.join(Dir.pwd, '*_tryouts.rb')]
11
+ end
12
+
13
+ # $ sergeant dreams [path/2/tryouts]
14
+ # Display the dreams from all known tryouts
15
+ def dreams
16
+ load_available_tryouts_files
17
+ if @global.verbose > 0
18
+ puts Tryouts.dreams.to_yaml
19
+ else
20
+ Tryouts.dreams.each_pair do |n,dreams|
21
+ puts n
22
+ dreams.each_pair do |n, dream|
23
+ puts " " << n
24
+ dream.each_pair do |n, drill|
25
+ puts " " << n
25
26
  end
26
27
  end
27
28
  end
28
29
  end
30
+ end
31
+
32
+ # $ sergeant run [path/2/tryouts]
33
+ # Executes all tryouts that can be found from the current working directory.
34
+ def run
35
+ if @global.verbose > 0
36
+ puts "#{Tryouts.sysinfo.to_s} (#{RUBY_VERSION})"
37
+ end
29
38
 
30
- def run
31
- if @global.verbose > 0
32
- puts "#{Tryouts.sysinfo.to_s} (#{RUBY_VERSION})"
33
- end
34
-
35
- load_available_tryouts_files
39
+ load_available_tryouts_files
36
40
 
37
- passed, failed = 0, 0
38
- Tryouts.instances.each_pair do |group,tryouts_inst|
39
- puts '', ' %-60s'.att(:reverse) % group
40
- puts " #{tryouts_inst.paths.join("\n ")}" if @global.verbose > 0
41
- tryouts_inst.tryouts.each_pair do |name,to|
42
- to.run
43
- to.report
44
- STDOUT.flush
45
- passed += to.passed
46
- failed += to.failed
47
- end
41
+ passed, failed = 0, 0
42
+ Tryouts.instances.each_pair do |group,tryouts_inst|
43
+ puts '', ' %-60s'.att(:reverse) % group
44
+ puts " #{tryouts_inst.paths.join("\n ")}" if @global.verbose > 0
45
+ tryouts_inst.tryouts.each_pair do |name,to|
46
+ to.run
47
+ to.report
48
+ STDOUT.flush
49
+ passed += to.passed
50
+ failed += to.failed
48
51
  end
49
- unless @global.quiet
50
- if failed == 0
51
- puts MOOKIE if @global.verbose > 5
52
- puts $/, " All #{passed+failed} dreams came true ".att(:reverse).color(:green)
53
- else
54
- puts $/, " #{passed} of #{passed+failed} dreams came true ".att(:reverse).color(:red)
55
- end
56
-
52
+ end
53
+ unless @global.quiet
54
+ if (passed == 0 && failed == 0)
55
+ puts DEV if @global.verbose > 4
56
+ msg = " You didn't even try to acheive your dreams :[ "
57
+ elsif failed == 0
58
+ puts PUG if @global.verbose > 4
59
+ msg = " All %s dreams came true ".color(:green)
60
+ msg = msg % [passed+failed]
61
+ else
62
+ puts BUG if @global.verbose > 4
63
+ score = (passed.to_f / (passed.to_f+failed.to_f)) * 100
64
+ msg = " %s of %s dreams came true (%d%%) ".color(:red)
65
+ msg = msg % [passed, passed+failed, score.to_i]
57
66
  end
67
+ puts $/, msg.att(:reverse)
58
68
  end
59
-
60
- def list
61
- load_available_tryouts_files
62
- ##if @global.verbose > 2
63
- ## puts Tryouts.instances.to_yaml # BUG: Raises "can't dump anonymous class Class"
64
- ##else
65
- Tryouts.instances.each_pair do |n,tryouts_inst|
66
- puts n
67
- if @global.verbose > 0
68
- puts " #{tryouts_inst.paths.join("\n ")}"
69
- end
70
- tryouts_inst.tryouts.each_pair do |t2,tryout|
71
- puts " " << tryout.name
72
- tryout.drills.each do |drill|
73
- puts " " << drill.name
74
- end
75
- end
69
+ end
70
+
71
+ # $ sergeant list
72
+ # Displays all known tryouts from the current working directory
73
+ def list
74
+ load_available_tryouts_files
75
+ Tryouts.instances.each_pair do |n,tryouts_inst|
76
+ puts n
77
+ if @global.verbose > 0
78
+ puts " #{tryouts_inst.paths.join("\n ")}"
79
+ end
80
+ tryouts_inst.tryouts.each_pair do |t2,tryout|
81
+ puts " " << tryout.name
82
+ tryout.drills.each do |drill|
83
+ puts " " << drill.name
76
84
  end
77
- ##end
85
+ end
78
86
  end
79
-
80
- private
81
- def load_available_tryouts_files
82
- @tryouts_files = []
83
- # If file paths were given, check those only.
84
- unless @argv.empty?
85
- @argv.each do |file|
86
- file = File.join(file, '**', '*_tryouts.rb') if File.directory?(file)
87
- @tryouts_files += Dir.glob file
88
- end
89
- # Otherwise check the default globs
90
- else
91
- @tryouts_globs.each do |glob|
92
- @tryouts_files += Dir.glob glob
93
- end
87
+ end
88
+
89
+ private
90
+
91
+ # Find and load all tryouts files
92
+ def load_available_tryouts_files
93
+ @tryouts_files = []
94
+ # If file paths were given, check those only.
95
+ unless @argv.empty?
96
+ @argv.each do |file|
97
+ file = File.join(file, '**', '*_tryouts.rb') if File.directory?(file)
98
+ @tryouts_files += Dir.glob file
99
+ end
100
+ # Otherwise check the default globs
101
+ else
102
+ @tryouts_globs.each do |glob|
103
+ @tryouts_files += Dir.glob glob
94
104
  end
95
- @tryouts_files.uniq! # Don't load the same file twice
96
- @tryouts_files.each { |f| puts "LOADING: #{f}"} if @global.verbose > 0
97
- @tryouts_files.each { |file| Tryouts.parse_file file }
98
105
  end
106
+ @tryouts_files.uniq! # Don't load the same file twice
107
+ @tryouts_files.each { |f| puts "LOADING: #{f}"} if @global.verbose > 0
108
+ @tryouts_files.each { |file| Tryouts.parse_file file }
99
109
  end
110
+ end
100
111
  end; end
101
112
 
102
- MOOKIE = %q{
103
- __,-----._ ,-.
104
- ,' ,-. \`---. ,-----<._/
105
- (,.-. o:.` )),"\\\-._ ,' `.
106
- ('"-` .\ \`:_ )\ `-;'-._ \
107
- ,,-. \` ; : \( `-' ) -._ : `:
108
- ( \ `._\\\ ` ; ; ` : )
109
- \`. `-. __ , / \ ;, (
110
- `.`-.___--' `- / ; | : |
111
- `-' `-.`--._ ' ; |
112
- (`--._`. ; /\ |
113
- \ ' \ , ) :
114
- | `--::---- \' ; ;|
115
- \ .__,- ( ) : :|
116
- \ : `------; \ | | ;
117
- \ : / , ) | | (
118
- -hrr- \ \ `-^-| | / , ,\
119
- ) ) | -^- ; `-^-^'
120
- _,' _ ; | |
121
- / , , ,' /---. :
122
- `-^-^' ( : :,'
123
- `-^--'
124
- }
113
+ class Tryouts::CLI::Run
114
+ DEV = %q{
115
+ ^^ @@@@@@@@@
116
+ ^^ ^^ @@@@@@@@@@@@@@@
117
+ @@@@@@@@@@@@@@@@@@ ^^
118
+ @@@@@@@@@@@@@@@@@@@@
119
+ ~~~ ~~~~~~~~ ~~ &&&&&&&&&&&&&&&&&&&& ~~~~~~~ ~~~~~~~~~~~ ~~
120
+ ~~ ~ ~ ~~~~~~~~~~~~~~~~~~~~ ~ ~~ ~~ ~
121
+ ~ ~~ ~~ ~~ ~~~~~~~~~~~~~ ~~~~ ~ ~~~ ~ ~~~ ~
122
+ ~ ~ ~~~~~~ ~~ ~~~ ~~ ~ ~~ ~~ ~
123
+ ~ ~ ~ ~~ ~~~~~~ ~ ~~ ~ ~~~
124
+ ~ ~ ~ ~~ ~ ~
125
+ }
126
+ BUG = %q{
127
+ ,--.____ ____.--.
128
+ / .'.'"``--...----------.___.----------...--''"`.`. \
129
+ | .'.' . . `.`. |
130
+ `. .'| . ' - . _ `-----' _ . - ' . |`. .'
131
+ `.' `| .' _ "-._ _.-" _ `. |' `.'
132
+ | | " -. .- " | |
133
+ \| ;;.. "|i. .i|" ..;; |/
134
+ `| ,---.``. ' ' .'',---. |'
135
+ | <'(__.'>.'---` '---`.<`.__)`> |
136
+ | `. `~ .' ,-------. `. ~'.' |
137
+ | |=_"`=.' . `-.___.-' . `.='"_=| |
138
+ | | ==/ : ` : i : ' : \== | |
139
+ | | ==/ /\___|___/\ \== | |
140
+ `.| =Y .' """_""" `. Y= |.'
141
+ L || ; .=="==. ; || J
142
+ \ ; .' ' ` `. ; /
143
+ `. ; ; .'
144
+ ; ;'\ /`; ;
145
+ `; .'.'/. ,\`.`. ;'
146
+ `-=;_-' `-----' `-_;=-' -bodom-
147
+ }
148
+ PUG = %q{
149
+ __,-----._ ,-.
150
+ ,' ,-. \`---. ,-----<._/
151
+ (,.-. o:.` )),"\\\-._ ,' `.
152
+ ('"-` .\ \`:_ )\ `-;'-._ \
153
+ ,,-. \` ; : \( `-' ) -._ : `:
154
+ ( \ `._\\\ ` ; ; ` : )
155
+ \`. `-. __ , / \ ;, (
156
+ `.`-.___--' `- / ; | : |
157
+ `-' `-.`--._ ' ; |
158
+ (`--._`. ; /\ |
159
+ \ ' \ , ) :
160
+ | `--::---- \' ; ;|
161
+ \ .__,- ( ) : :|
162
+ \ : `------; \ | | ;
163
+ \ : / , ) | | (
164
+ \ \ `-^-| | / , ,\
165
+ ) ) | -^- ; `-^-^'
166
+ _,' _ ; | |
167
+ / , , ,' /---. :
168
+ `-^-^' ( : :,'
169
+ `-^--' -hrr-
170
+ }
171
+ end
data/lib/tryouts/drill.rb CHANGED
@@ -52,6 +52,7 @@ class Tryouts
52
52
  begin
53
53
  print Tryouts::DRILL_MSG % @name
54
54
  @reality = @sergeant.run @drill, context
55
+ @reality.stash = context.stash if context.respond_to? :stash
55
56
  process_reality
56
57
  rescue => ex
57
58
  @reality.rcode = -2
@@ -100,6 +100,13 @@ class Tryouts::Drill
100
100
  #
101
101
  # Contains the actual response of a Drill
102
102
  #
103
- class Reality < Tryouts::Drill::Response; end
103
+ class Reality < Tryouts::Drill::Response
104
+ # An ordered hash taken from the DrillContext that created this Reality.
105
+ attr_accessor :stash
106
+ def initialize
107
+ @rcode = 0
108
+ @stash = Tryouts::HASH_TYPE.new
109
+ end
110
+ end
104
111
 
105
112
  end
@@ -0,0 +1,42 @@
1
+
2
+
3
+
4
+ class Tryouts; class Drill; module Sergeant
5
+
6
+ # = API
7
+ #
8
+ # The sergeant responsible for running Ruby code (API) drills.
9
+ #
10
+ class API
11
+
12
+ # +return_value+ specify a return value. This will be
13
+ # used if no block is specified for the drill.
14
+ def initialize(return_value=nil)
15
+ @return_value = return_value
16
+ end
17
+
18
+ def run(block, context, &inline)
19
+
20
+ # A Proc object takes precedence over an inline block.
21
+ runtime = (block.nil? ? inline : block)
22
+ response = Tryouts::Drill::Reality.new
23
+ if runtime.nil?
24
+ response.output = @return_value
25
+ else
26
+ begin
27
+ unless runtime.nil?
28
+ ret = context.instance_eval &runtime
29
+ response.output, response.rcode = ret, 0
30
+ end
31
+ rescue => ex
32
+ response.rcode = 1
33
+ response.output = ret
34
+ response.emsg = ex.message
35
+ response.backtrace = ex.backtrace
36
+ end
37
+ end
38
+ response
39
+ end
40
+
41
+ end
42
+ end; end; end
@@ -0,0 +1,199 @@
1
+ # AUTHOR
2
+ # jan molic /mig/at/1984/dot/cz/
3
+ #
4
+ # DESCRIPTION
5
+ # Hash with preserved order and some array-like extensions
6
+ # Public domain.
7
+ #
8
+ # THANKS
9
+ # Andrew Johnson for his suggestions and fixes of Hash[],
10
+ # merge, to_a, inspect and shift
11
+ class Tryouts::OrderedHash < ::Hash
12
+ attr_accessor :order
13
+
14
+ class << self
15
+ def [] *args
16
+ hsh = Tryouts::OrderedHash.new
17
+ if Hash === args[0]
18
+ hsh.replace args[0]
19
+ elsif (args.size % 2) != 0
20
+ raise ArgumentError, "odd number of elements for Hash"
21
+ else
22
+ 0.step(args.size - 1, 2) do |a|
23
+ b = a + 1
24
+ hsh[args[a]] = args[b]
25
+ end
26
+ end
27
+ hsh
28
+ end
29
+ end
30
+ def initialize(*a, &b)
31
+ super
32
+ @order = []
33
+ end
34
+ def store_only a,b
35
+ store a,b
36
+ end
37
+ alias orig_store store
38
+ def store a,b
39
+ @order.push a unless has_key? a
40
+ super a,b
41
+ end
42
+ alias []= store
43
+ def == hsh2
44
+ return false if @order != hsh2.order
45
+ super hsh2
46
+ end
47
+ def clear
48
+ @order = []
49
+ super
50
+ end
51
+ def delete key
52
+ @order.delete key
53
+ super
54
+ end
55
+ def each_key
56
+ @order.each { |k| yield k }
57
+ self
58
+ end
59
+ def each_value
60
+ @order.each { |k| yield self[k] }
61
+ self
62
+ end
63
+ def each
64
+ @order.each { |k| yield k,self[k] }
65
+ self
66
+ end
67
+ alias each_pair each
68
+ def delete_if
69
+ @order.clone.each { |k|
70
+ delete k if yield(k)
71
+ }
72
+ self
73
+ end
74
+ def values
75
+ ary = []
76
+ @order.each { |k| ary.push self[k] }
77
+ ary
78
+ end
79
+ def keys
80
+ @order
81
+ end
82
+ def first
83
+ {@order.first => self[@order.first]}
84
+ end
85
+ def last
86
+ {@order.last => self[@order.last]}
87
+ end
88
+ def invert
89
+ hsh2 = Hash.new
90
+ @order.each { |k| hsh2[self[k]] = k }
91
+ hsh2
92
+ end
93
+ def reject &block
94
+ self.dup.delete_if &block
95
+ end
96
+ def reject! &block
97
+ hsh2 = reject &block
98
+ self == hsh2 ? nil : hsh2
99
+ end
100
+ def replace hsh2
101
+ @order = hsh2.keys
102
+ super hsh2
103
+ end
104
+ def shift
105
+ key = @order.first
106
+ key ? [key,delete(key)] : super
107
+ end
108
+ def unshift k,v
109
+ unless self.include? k
110
+ @order.unshift k
111
+ orig_store(k,v)
112
+ true
113
+ else
114
+ false
115
+ end
116
+ end
117
+ def push k,v
118
+ unless self.include? k
119
+ @order.push k
120
+ orig_store(k,v)
121
+ true
122
+ else
123
+ false
124
+ end
125
+ end
126
+ def pop
127
+ key = @order.last
128
+ key ? [key,delete(key)] : nil
129
+ end
130
+ def to_a
131
+ ary = []
132
+ each { |k,v| ary << [k,v] }
133
+ ary
134
+ end
135
+ def to_s
136
+ self.to_a.to_s
137
+ end
138
+ def inspect
139
+ ary = []
140
+ each {|k,v| ary << k.inspect + "=>" + v.inspect}
141
+ '{' + ary.join(", ") + '}'
142
+ end
143
+ def update hsh2
144
+ hsh2.each { |k,v| self[k] = v }
145
+ self
146
+ end
147
+ alias :merge! update
148
+ def merge hsh2
149
+ ##self.dup update(hsh2) ## 2009-05-12 -- delano
150
+ update hsh2 ## dup doesn't take an argument
151
+ ## and there's no need for it here
152
+ end
153
+ def select
154
+ ary = []
155
+ each { |k,v| ary << [k,v] if yield k,v }
156
+ ary
157
+ end
158
+ def class
159
+ Hash
160
+ end
161
+ def __class__
162
+ Tryouts::OrderedHash
163
+ end
164
+
165
+ attr_accessor "to_yaml_style"
166
+ def yaml_inline= bool
167
+ if respond_to?("to_yaml_style")
168
+ self.to_yaml_style = :inline
169
+ else
170
+ unless defined? @__yaml_inline_meth
171
+ @__yaml_inline_meth =
172
+ lambda {|opts|
173
+ YAML::quick_emit(object_id, opts) {|emitter|
174
+ emitter << '{ ' << map{|kv| kv.join ': '}.join(', ') << ' }'
175
+ }
176
+ }
177
+ class << self
178
+ def to_yaml opts = {}
179
+ begin
180
+ @__yaml_inline ? @__yaml_inline_meth[ opts ] : super
181
+ rescue
182
+ @to_yaml_style = :inline
183
+ super
184
+ end
185
+ end
186
+ end
187
+ end
188
+ end
189
+ @__yaml_inline = bool
190
+ end
191
+ def yaml_inline!() self.yaml_inline = true end
192
+
193
+ def each_with_index
194
+ @order.each_with_index { |k, index| yield k, self[k], index }
195
+ self
196
+ end
197
+ end # class Tryouts::OrderedHash
198
+
199
+
@@ -34,7 +34,25 @@ class Tryouts
34
34
  # Each Drill is executed in a new instance of this class. That means
35
35
  # instance variables are not carried through, but class variables are.
36
36
  # The before and after blocks are also run in this context.
37
- class DrillContext; end
37
+ class DrillContext
38
+ # An ordered Hash of stashed objects.
39
+ attr_reader :stash
40
+ def initialize; @stash = Tryouts::HASH_TYPE.new; end
41
+ # If called with no arguments, returns +@stash+.
42
+ # If called with arguments, it will add a new value to the +@stash+
43
+ # and return the new value. e.g.
44
+ #
45
+ # stash :name, 'some value' # => 'some value'
46
+ #
47
+ def stash(*args)
48
+ if args.empty?
49
+ @stash
50
+ else
51
+ @stash[args[0]] = args[1]
52
+ args[1]
53
+ end
54
+ end
55
+ end
38
56
 
39
57
  def initialize(name, dtype, command=nil, *args)
40
58
  raise "Must supply command for dtype :cli" if dtype == :cli && command.nil?
@@ -56,13 +74,16 @@ class Tryouts
56
74
  # Execute all Drill objects
57
75
  def run
58
76
  update_drills! # Ensure all drills have all known dreams
59
- DrillContext.class_eval &setup if setup.is_a?(Proc)
77
+ DrillContext.module_eval &setup if setup.is_a?(Proc)
60
78
  puts Tryouts::TRYOUT_MSG.bright % @name
61
79
  @drills.each do |drill|
62
80
  drill.run(DrillContext.new) # Returns true or false
81
+ drill.reality.stash.each_pair do |n,v|
82
+ puts '%14s: %s' % [n,v.inspect]
83
+ end
63
84
  drill.success? ? @passed += 1 : @failed += 1
64
85
  end
65
- DrillContext.class_eval &clean if clean.is_a?(Proc)
86
+ DrillContext.module_eval &clean if clean.is_a?(Proc)
66
87
  end
67
88
 
68
89
  # Prints error output. If there are no errors, it prints nothing.
@@ -70,7 +91,7 @@ class Tryouts
70
91
  return true if success?
71
92
  failed = @drills.select { |d| !d.success? }
72
93
  failed.each_with_index do |drill,index|
73
- title = ' %-59s' % %Q{ERROR #{index+1}/#{failed.size} in "#{drill.name}"}
94
+ title = ' %-59s' % %Q{ERROR #{index+1}/#{failed.size} "#{drill.name}"}
74
95
  puts $/, ' ' << title.color(:red).att(:reverse)
75
96
 
76
97
  if drill.dream
@@ -81,17 +102,13 @@ class Tryouts
81
102
  puts '%24s: %s' % ["expected error msg", drill.dream.emsg.inspect]
82
103
  puts '%24s: %s' % ["actual error msg", drill.reality.emsg.inspect]
83
104
  end
84
- else
85
- puts '%24s' % ["[nodream]"]
105
+
86
106
  if drill.reality.rcode > 0
87
- puts '%24s: %s' % ["rcode", drill.reality.rcode.inspect]
88
- puts '%24s: %s' % ["msg", drill.reality.emsg.inspect]
107
+ puts '%24s: ' % ["backtrace"]
108
+ puts drill.reality.backtrace, $/
89
109
  end
90
- end
91
-
92
- if drill.reality.rcode > 0
93
- puts '%24s: ' % ["backtrace"]
94
- puts drill.reality.backtrace, $/
110
+ else
111
+ puts '%24s' % ["[nodream]"]
95
112
  end
96
113
 
97
114
  end
@@ -141,31 +158,36 @@ class Tryouts
141
158
  @clean = block
142
159
  end
143
160
 
161
+ # Create and add a Drill object to the list for this Tryout
162
+ # +name+ is the name of the drill.
163
+ # +args+ is sent directly to the Drill class. The values are specific on the Sergeant.
164
+ def drill(dname, *args, &definition)
165
+ raise "Empty drill name (#{@name})" if dname.nil? || dname.empty?
166
+ args.unshift(@command) if @dtype == :cli
167
+ drill = Tryouts::Drill.new(dname, @dtype, *args, &definition)
168
+ add_drill drill
169
+ end
170
+ # A quick way to comment out a drill
171
+ def xdrill(*args, &b); end # ignore calls to xdrill
172
+
144
173
  # +name+ of the Drill associated to this Dream
145
174
  # +output+ A String or Array of expected output. A Dream object will be created using this value (optional)
146
175
  # +definition+ is a block which will be run on an instance of Dream
147
176
  #
148
177
  # NOTE: This method is DSL-only. It's not intended to be used in OO syntax.
149
- def dream(name, output=nil, format=nil, rcode=0, emsg=nil, &definition)
178
+ def dream(dname, output=nil, format=nil, rcode=0, emsg=nil, &definition)
179
+ raise "Empty dream name (#{@name})" if dname.nil? || dname.empty?
150
180
  if output.nil?
181
+ raise "No output or block for '#{dname}' (#{@name})" if definition.nil?
151
182
  dobj = Tryouts::Drill::Dream.from_block definition
152
183
  else
153
184
  dobj = Tryouts::Drill::Dream.new(output)
154
185
  dobj.format, dobj.rcode, dobj.emsg = format, rcode, emsg
155
186
  end
156
- @dreams[name] = dobj
187
+ @dreams[dname] = dobj
157
188
  dobj
158
189
  end
159
-
160
- # Create and add a Drill object to the list for this Tryout
161
- # +name+ is the name of the drill.
162
- # +args+ is sent directly to the Drill class. The values are specific on the Sergeant.
163
- def drill(name, *args, &definition)
164
- args.unshift(@command) if @dtype == :cli
165
- drill = Tryouts::Drill.new(name, @dtype, *args, &definition)
166
- add_drill drill
167
- end
168
- def xdrill(*args, &b); end # ignore calls to xdrill
169
-
190
+ # A quick way to comment out a dream
191
+ def xdream(*args, &b); end
170
192
 
171
193
  end; end
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.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Delano Mandelbaum
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-06 00:00:00 -04:00
12
+ date: 2009-06-08 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -55,7 +55,7 @@ dependencies:
55
55
  description: Tryouts are high-level tests for your Ruby code. May all your dreams come true!
56
56
  email: tryouts@solutious.com
57
57
  executables:
58
- - tryouts
58
+ - sergeant
59
59
  extensions: []
60
60
 
61
61
  extra_rdoc_files:
@@ -67,20 +67,18 @@ files:
67
67
  - README.rdoc
68
68
  - Rakefile
69
69
  - bin/mockout
70
- - bin/tryouts
70
+ - bin/sergeant
71
71
  - lib/tryouts.rb
72
72
  - lib/tryouts/cli.rb
73
73
  - lib/tryouts/cli/run.rb
74
74
  - lib/tryouts/drill.rb
75
75
  - lib/tryouts/drill/response.rb
76
+ - lib/tryouts/drill/sergeant/api.rb
76
77
  - lib/tryouts/drill/sergeant/cli.rb
77
78
  - lib/tryouts/mixins.rb
78
79
  - lib/tryouts/mixins/hash.rb
80
+ - lib/tryouts/orderedhash.rb
79
81
  - lib/tryouts/tryout.rb
80
- - tryouts.gemspec
81
- - tryouts/mockoutcli_dreams.rb
82
- - tryouts/mockoutcli_dreams.yaml
83
- - tryouts/mockoutcli_tryouts.rb
84
82
  has_rdoc: true
85
83
  homepage: http://github.com/delano/tryouts
86
84
  licenses: []
data/tryouts.gemspec DELETED
@@ -1,75 +0,0 @@
1
- @spec = Gem::Specification.new do |s|
2
- s.name = "tryouts"
3
- s.rubyforge_project = "tryouts"
4
- s.version = "0.4.1"
5
- s.summary = "Tryouts are high-level tests for your Ruby code. May all your dreams come true!"
6
- s.description = s.summary
7
- s.author = "Delano Mandelbaum"
8
- s.email = "tryouts@solutious.com"
9
- s.homepage = "http://github.com/delano/tryouts"
10
-
11
- # = EXECUTABLES =
12
- # The list of executables in your project (if any). Don't include the path,
13
- # just the base filename.
14
- s.executables = %w[tryouts]
15
-
16
- # Directories to extract rdocs from
17
- s.require_paths = %w[lib]
18
-
19
- # Specific files to include rdocs from
20
- s.extra_rdoc_files = %w[README.rdoc LICENSE.txt]
21
-
22
- # Update --main to reflect the default page to display
23
- s.rdoc_options = ["--line-numbers", "--title", "Tryouts: #{s.summary}", "--main", "README.rdoc"]
24
-
25
- # = DEPENDENCIES =
26
- # Add all gem dependencies
27
- s.add_dependency 'drydock', '>= 0.6.5'
28
- s.add_dependency 'rye', '>= 0.6.6'
29
- s.add_dependency 'sysinfo', '>= 0.5.1'
30
-
31
- # = MANIFEST =
32
- # The complete list of files to be included in the release. When GitHub packages your gem,
33
- # it doesn't allow you to run any command that accesses the filesystem. You will get an
34
- # error. You can ask your VCS for the list of versioned files:
35
- # git ls-files
36
- # svn list -R
37
- s.files = %w(
38
- CHANGES.txt
39
- LICENSE.txt
40
- README.rdoc
41
- Rakefile
42
- bin/mockout
43
- bin/tryouts
44
- lib/tryouts.rb
45
- lib/tryouts/cli.rb
46
- lib/tryouts/cli/run.rb
47
- lib/tryouts/drill.rb
48
- lib/tryouts/drill/response.rb
49
- lib/tryouts/drill/sergeant/cli.rb
50
- lib/tryouts/mixins.rb
51
- lib/tryouts/mixins/hash.rb
52
- lib/tryouts/tryout.rb
53
- tryouts.gemspec
54
- tryouts/mockoutcli_dreams.rb
55
- tryouts/mockoutcli_dreams.yaml
56
- tryouts/mockoutcli_tryouts.rb
57
- )
58
-
59
- s.has_rdoc = true
60
- s.rubygems_version = '1.3.0'
61
-
62
- if s.respond_to? :specification_version then
63
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
64
- s.specification_version = 2
65
-
66
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
67
- s.add_runtime_dependency(%q<RedCloth>, [">= 4.0.4"])
68
- else
69
- s.add_dependency(%q<RedCloth>, [">= 4.0.4"])
70
- end
71
- else
72
- s.add_dependency(%q<RedCloth>, [">= 4.0.4"])
73
- end
74
-
75
- end
@@ -1,19 +0,0 @@
1
-
2
- dreams "Common Usage" do
3
- dream "No args" do
4
- output inline(%Q{
5
- Date: 2009-02-16
6
- Owners: greg, rupaul, telly, prince kinko
7
- Players: d-bam, alberta, birds, condor man
8
- })
9
- end
10
- dream "YAML Output" do
11
- format :to_yaml
12
- output ({
13
- "Date" => "2009-02-16",
14
- "Players" => ["d-bam", "alberta", "birds", "condor man"],
15
- "Owners" => ["greg", "rupaul", "telly", "prince kinko"]
16
- })
17
- end
18
- end
19
-
@@ -1,10 +0,0 @@
1
- common usage:
2
- yaml output:
3
- :format: :yaml
4
- :rcode: 0
5
- no args:
6
- :rcode: 0
7
- :output:
8
- - " Date: 2009-02-16\n"
9
- - " Players: d-bam, alberta, birds, condor man\n"
10
- - " Coaches: greg|rupaul|telly|prince kinko\n"
@@ -1,27 +0,0 @@
1
-
2
- TRYOUTS_HOME = File.expand_path(File.join(File.dirname(__FILE__), ".."))
3
- MOCKOUT_PATH = File.join(TRYOUTS_HOME, "bin", "mockout")
4
-
5
- group "mockout cli"
6
- command :mockout, MOCKOUT_PATH
7
- dreams File.join(GYMNASIUM_HOME, 'mockoutcli_dreams.rb')
8
-
9
- tryout "Common Usage" do
10
- drill "No Command"
11
- drill "No args", :info
12
- drill "YAML Output", :f, :yaml, :info
13
- drill "JSON Output", :f, :json, :info
14
- end
15
-
16
- tryout "inline dream that passes", :cli, :mockout do
17
- output = ["we expect mockout to", "echo these lines back"]
18
-
19
- # $ bin/mockout sergeant -e "we expect mockout to" "echo these lines back"
20
- drill "echo arguments", :info, :e, output[0], output[1]
21
- dream "echo arguments", output
22
- end
23
-
24
- tryout "inline dream that fails", :cli, :mockout do
25
- dream "echo arguments", "The dream does"
26
- drill "echo arguments", :info, :e, "not match reality"
27
- end