tryouts 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGES.txt CHANGED
@@ -1,6 +1,11 @@
1
1
  TRYOUTS, CHANGES
2
2
 
3
3
 
4
+ #### 0.4.1 (2009-06-07) ###############################
5
+
6
+ * CHANGE: The CLI output is no longer terrifyingly ugly.
7
+
8
+
4
9
  #### 0.4.0 (2009-06-05) ###############################
5
10
 
6
11
  NOTE: Initial public release
data/README.rdoc CHANGED
@@ -1,11 +1,7 @@
1
- = Tryouts - v0.5 ALPHA
1
+ = Tryouts - v0.4 BETA
2
2
 
3
3
  Tryouts is a high-level testing library for your command-line applications and Ruby codes.
4
4
 
5
- *WORK IN PROGRESS*
6
-
7
- 2009-05-24 - A BBQ started nearby as I was writing this documentation. It's incomplete and I'm sorry about that but I can tell you that this BBQ smells really, really good.
8
-
9
5
 
10
6
  == Terminology
11
7
 
@@ -27,7 +23,7 @@ The tryout definition would look like this:
27
23
 
28
24
  command :executable, "path/2/executable"
29
25
 
30
- tryout "Common Usage", :cli do
26
+ tryout "Common Usage" do
31
27
  drill "No Command"
32
28
  drill "YAML Output", :f, 'yaml'
33
29
  end
@@ -56,7 +52,7 @@ Tryouts employs the same approach for testing Ruby codes. The return value of th
56
52
 
57
53
  library :caesars, LIBRARY_PATH
58
54
 
59
- tryout "Common Usage", :api do
55
+ tryout "Common Usage" do
60
56
  dream "Some Maths", 3
61
57
  drill "Some Maths" do
62
58
  12 / 4
data/bin/tryouts CHANGED
@@ -15,7 +15,7 @@ require 'tryouts/cli'
15
15
  module TryoutsCLI
16
16
  extend Drydock
17
17
 
18
- debug :on
18
+ debug :off
19
19
  default :run, :with_args
20
20
 
21
21
  global :q, :quiet, "Decrease output"
@@ -29,25 +29,31 @@ class Tryouts; module CLI
29
29
 
30
30
  def run
31
31
  if @global.verbose > 0
32
- puts "RUBY #{RUBY_VERSION} - #{RUBY_PLATFORM}"
32
+ puts "#{Tryouts.sysinfo.to_s} (#{RUBY_VERSION})"
33
33
  end
34
34
 
35
35
  load_available_tryouts_files
36
36
 
37
- successes = []
37
+ passed, failed = 0, 0
38
38
  Tryouts.instances.each_pair do |group,tryouts_inst|
39
- puts '', '-'*60 unless @global.quiet
40
- puts group
39
+ puts '', ' %-60s'.att(:reverse) % group
41
40
  puts " #{tryouts_inst.paths.join("\n ")}" if @global.verbose > 0
42
41
  tryouts_inst.tryouts.each_pair do |name,to|
43
42
  to.run
44
43
  to.report
45
44
  STDOUT.flush
46
- successes << to.success?
45
+ passed += to.passed
46
+ failed += to.failed
47
47
  end
48
48
  end
49
- unless successes.member?(false)
50
- puts $/, "All your dreams came true" unless @global.quiet
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
+
51
57
  end
52
58
  end
53
59
 
@@ -87,8 +93,32 @@ class Tryouts; module CLI
87
93
  end
88
94
  end
89
95
  @tryouts_files.uniq! # Don't load the same file twice
96
+ @tryouts_files.each { |f| puts "LOADING: #{f}"} if @global.verbose > 0
90
97
  @tryouts_files.each { |file| Tryouts.parse_file file }
91
- puts @tryouts_files if @global.verbose > 0
92
98
  end
93
99
  end
94
- end; end
100
+ end; end
101
+
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
+ }
@@ -54,8 +54,8 @@ class Tryouts::Drill
54
54
  return false
55
55
  end
56
56
 
57
- # The matching statement will be the return value.
58
- if dream.format.nil?
57
+ # The matching statement will be the return value.
58
+ if dream.format.nil? || (dream.class == reality.class)
59
59
  dream.output == reality.output
60
60
  elsif reality.respond_to? dream.format
61
61
  reality.output.send(dream.format) == dream.output
data/lib/tryouts/drill.rb CHANGED
@@ -58,7 +58,7 @@ class Tryouts
58
58
  @reality.emsg, @reality.backtrace = ex.message, ex.backtrace
59
59
  end
60
60
  note = @dream ? discrepency.join(', ') : 'nodream'
61
- puts self.success? ? "PASS" : "FAIL (#{note})"
61
+ puts self.success? ? "PASS".color(:green) : "FAIL (#{note})".color(:red)
62
62
  self.success?
63
63
  end
64
64
 
@@ -9,26 +9,24 @@ class Tryouts
9
9
 
10
10
  # The name of this tryout
11
11
  attr_reader :name
12
-
13
- # A Hash of Dream objects for this Tryout. The keys are drill names.
14
- attr_accessor :dreams
15
-
16
- # An Array of Drill objects
17
- attr_reader :drills
18
-
19
12
  # A default value for Drill.dtype
20
13
  attr_reader :dtype
21
-
22
- # For drill type :cli, this is the name of the command to test. It
23
- # should be a valid method available to a Rye::Box object.
24
- # For drill type :api, this attribute is ignored.
25
- attr_reader :command
26
-
27
14
  # A block to executed one time before starting the drills
28
15
  attr_reader :setup
29
-
30
16
  # A block to executed one time before starting the drills
31
17
  attr_reader :clean
18
+ # An Array of Drill objects
19
+ attr_reader :drills
20
+ # The number of dreams that came true (successful drills)
21
+ attr_reader :passed
22
+ # The number of dreams that did not come true (failed drills)
23
+ attr_reader :failed
24
+ # For drill type :cli, this is the name of the command to test. It
25
+ # should be a valid method available to a Rye::Box object.
26
+ # For drill type :api, this attribute is ignored.
27
+ attr_reader :command
28
+ # A Hash of Dream objects for this Tryout. The keys are drill names.
29
+ attr_accessor :dreams
32
30
 
33
31
  @@valid_dtypes = [:cli, :api]
34
32
 
@@ -42,8 +40,8 @@ class Tryouts
42
40
  raise "Must supply command for dtype :cli" if dtype == :cli && command.nil?
43
41
  raise "#{dtype} is not a valid drill type" if !@@valid_dtypes.member?(dtype)
44
42
  @name, @dtype, @command = name, dtype, command
45
- @drills = []
46
- @dreams = {}
43
+ @drills, @dreams = [], {}
44
+ @passed, @failed = 0, 0
47
45
  end
48
46
 
49
47
  ## --------------------------------------- EXTERNAL API -----
@@ -59,9 +57,10 @@ class Tryouts
59
57
  def run
60
58
  update_drills! # Ensure all drills have all known dreams
61
59
  DrillContext.class_eval &setup if setup.is_a?(Proc)
62
- puts Tryouts::TRYOUT_MSG % @name
60
+ puts Tryouts::TRYOUT_MSG.bright % @name
63
61
  @drills.each do |drill|
64
62
  drill.run(DrillContext.new) # Returns true or false
63
+ drill.success? ? @passed += 1 : @failed += 1
65
64
  end
66
65
  DrillContext.class_eval &clean if clean.is_a?(Proc)
67
66
  end
@@ -71,8 +70,8 @@ class Tryouts
71
70
  return true if success?
72
71
  failed = @drills.select { |d| !d.success? }
73
72
  failed.each_with_index do |drill,index|
74
-
75
- puts '%sERROR %2d/%-2d in "%s"' % [$/, index+1, failed.size, drill.name]
73
+ title = ' %-59s' % %Q{ERROR #{index+1}/#{failed.size} in "#{drill.name}"}
74
+ puts $/, ' ' << title.color(:red).att(:reverse)
76
75
 
77
76
  if drill.dream
78
77
  puts '%24s: %s (expected %s)' % ["response code", drill.reality.rcode, drill.dream.rcode]
@@ -94,6 +93,7 @@ class Tryouts
94
93
  puts '%24s: ' % ["backtrace"]
95
94
  puts drill.reality.backtrace, $/
96
95
  end
96
+
97
97
  end
98
98
  false
99
99
  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.0"
33
+ VERSION = "0.4.1"
34
34
 
35
35
  require 'tryouts/mixins'
36
36
  require 'tryouts/tryout'
@@ -40,13 +40,20 @@ class Tryouts
40
40
  HASH_TYPE = (RUBY_VERSION =~ /1.9/) ? ::Hash : Tryouts::OrderedHash
41
41
 
42
42
  TRYOUT_MSG = "\n %s "
43
- DRILL_MSG = ' %30s: '
44
- DRILL_ERR = ' %s: '
43
+ DRILL_MSG = ' %-50s '
44
+ DRILL_ERR = ' %s: '
45
45
 
46
46
  # An Array of +_tryouts.rb+ file paths that have been loaded.
47
47
  @@loaded_files = []
48
48
  # An Hash of Tryouts instances stored under the name of the Tryouts subclass.
49
49
  @@instances = HASH_TYPE.new
50
+ # An instance of SysInfo
51
+ @@sysinfo = SysInfo.new
52
+
53
+ # Returns +@@instances+
54
+ def self.instances; @@instances; end
55
+ # Returns +@@sysinfo+
56
+ def self.sysinfo; @@sysinfo; end
50
57
 
51
58
  # The name of this group of Tryout objects
52
59
  attr_accessor :group
@@ -66,9 +73,6 @@ class Tryouts
66
73
  attr_accessor :library
67
74
  # The name of the most recent dreams group (see self.dream)
68
75
  attr_accessor :dream_pointer
69
-
70
- # Returns +@@instances+
71
- def self.instances; @@instances; end
72
76
 
73
77
  def initialize(group=nil)
74
78
  @group = group || "Default Group"
@@ -2,13 +2,13 @@
2
2
  dreams "Common Usage" do
3
3
  dream "No args" do
4
4
  output inline(%Q{
5
- Date: 2009-02-16
6
- Owners: greg, rupaul, telly, prince kinko
7
- Players: d-bam, alberta, birds, condor man
5
+ Date: 2009-02-16
6
+ Owners: greg, rupaul, telly, prince kinko
7
+ Players: d-bam, alberta, birds, condor man
8
8
  })
9
9
  end
10
10
  dream "YAML Output" do
11
- format :yaml
11
+ format :to_yaml
12
12
  output ({
13
13
  "Date" => "2009-02-16",
14
14
  "Players" => ["d-bam", "alberta", "birds", "condor man"],
@@ -4,6 +4,7 @@ MOCKOUT_PATH = File.join(TRYOUTS_HOME, "bin", "mockout")
4
4
 
5
5
  group "mockout cli"
6
6
  command :mockout, MOCKOUT_PATH
7
+ dreams File.join(GYMNASIUM_HOME, 'mockoutcli_dreams.rb')
7
8
 
8
9
  tryout "Common Usage" do
9
10
  drill "No Command"
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.4.0"
4
+ s.version = "0.4.1"
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: tryouts
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Delano Mandelbaum