shindo 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/bin/shindo CHANGED
@@ -1,81 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
- @interrupt = lambda do
3
- formatador = Thread.current[:formatador] || Formatador
4
- unless Thread.main[:exit]
5
- formatador.display_line('Gracefully Exiting... (ctrl-c to force)')
6
- Thread.main[:exit] = true
7
- else
8
- formatador.display_line('Exiting...')
9
- Thread.exit
10
- end
11
- end
12
- Kernel.trap('INT', @interrupt)
13
-
14
- require File.join(File.dirname(__FILE__), '..', 'lib', 'shindo')
15
-
16
- helpers = Dir.glob(File.join(Dir.pwd, 'tests', '**', '*helper.rb')).sort_by {|helper| helper.count(File::SEPARATOR)}
17
- tags = []
18
- for argument in ARGV
19
- if argument.match(/^[\+\-]/)
20
- tags << argument
21
- else
22
- path = File.expand_path(argument)
23
- if File.directory?(path)
24
- tests ||= []
25
- tests |= Dir.glob(File.join(path, '**', '*tests.rb'))
26
- elsif File.exists?(path)
27
- tests ||= []
28
- tests << path
29
- else
30
- Formatador.display_line("[red][bold]#{argument}[/] [red]does not exist, please fix this path and try again.[/]")
31
- Kernel.exit(1)
32
- end
33
- end
34
- end
35
-
36
- # ARGV was empty or only contained tags
37
- unless tests
38
- tests = Dir.glob(File.join('tests', '**', '*tests.rb'))
39
- end
40
-
41
- @started_at = Time.now
42
- def run_in_thread(helpers, tests, tags)
43
- shindo = Thread.new {
44
- Thread.current[:tags] = tags
45
- for file in helpers
46
- unless Thread.main[:exit]
47
- load(file)
48
- end
49
- end
50
- for file in tests
51
- unless Thread.main[:exit]
52
- load(file)
53
- end
54
- end
55
- }
56
- shindo.join
57
- if shindo[:reload]
58
- run_in_thread(helpers, tests, tags)
59
- else
60
- @totals = shindo[:totals]
61
- end
62
- end
63
- run_in_thread(helpers, tests, tags)
64
-
65
- @totals ||= { :failed => 0, :pending => 0, :succeeded => 0 }
66
- @success = @totals[:failed] == 0
67
- lines = []
68
- lines << "[red]#{@totals[:failed]} failed[/]," if @totals[:failed] > 0
69
- lines << "[yellow]#{@totals[:pending]} pending[/]," if @totals[:pending] > 0
70
- lines << "[green]#{@totals[:succeeded]} succeeded[/]"
71
- lines = lines[0...-2].join(', ') << ' and ' << lines[-1] if lines.length > 3
72
- lines << "in [bold]#{Time.now - @started_at}[/] seconds"
73
- Formatador.display_line
74
- Formatador.display_line(lines.join(' '))
75
- Formatador.display_line
76
-
77
- if @success
78
- Kernel.exit(0)
79
- else
80
- Kernel.exit(1)
81
- end
2
+ @thread_locals = { :interactive => true }
3
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'shindo', 'verbose')
4
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'shindo', 'bin')
data/bin/shindont ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ @thread_locals = { :interactive => false }
3
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'shindo', 'taciturn')
4
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'shindo', 'bin')
data/lib/shindo.rb CHANGED
@@ -5,7 +5,7 @@ require 'gestalt'
5
5
  module Shindo
6
6
 
7
7
  unless const_defined?(:VERSION)
8
- VERSION = '0.1.4'
8
+ VERSION = '0.1.5'
9
9
  end
10
10
 
11
11
  def self.tests(description = nil, tags = [], &block)
@@ -18,7 +18,8 @@ module Shindo
18
18
  def initialize(description, tags = [], &block)
19
19
  @afters = []
20
20
  @befores = []
21
- @tag_stack = []
21
+ @description_stack = []
22
+ @tag_stack = []
22
23
  Thread.current[:formatador] = Formatador.new
23
24
  Thread.current[:reload] = false
24
25
  Thread.current[:tags] ||= []
@@ -35,7 +36,6 @@ module Shindo
35
36
  end
36
37
  Thread.current[:formatador].display_line
37
38
  tests(description, tags, &block)
38
- Thread.current[:formatador].display_line
39
39
  end
40
40
 
41
41
  def after(&block)
@@ -60,13 +60,14 @@ module Shindo
60
60
  unless tags.empty?
61
61
  description << " (#{tags.join(', ')})"
62
62
  end
63
+ @description_stack.push(description)
63
64
 
64
65
  # if the test includes +tags and discludes -tags, evaluate it
65
66
  if (@if_tagged.empty? || !(@if_tagged & @tag_stack.flatten).empty?) &&
66
67
  (@unless_tagged.empty? || (@unless_tagged & @tag_stack.flatten).empty?)
67
68
  if block_given?
68
69
  begin
69
- Thread.current[:formatador].display_line(description)
70
+ display_description(description)
70
71
  Thread.current[:formatador].indent { instance_eval(&block) }
71
72
  rescue => error
72
73
  display_error(error)
@@ -75,14 +76,15 @@ module Shindo
75
76
  @description = description
76
77
  end
77
78
  else
78
- Thread.current[:formatador].display_line("[light_black]#{description}[/]")
79
+ display_description("[light_black]#{description}[/]")
79
80
  end
80
81
 
82
+ @description_stack.pop
81
83
  @afters.pop
82
84
  @befores.pop
83
85
  @tag_stack.pop
84
86
 
85
- Thread.exit if Thread.current[:exit] || Thread.current[:reload]
87
+ Thread.exit if Thread.main[:exit] || Thread.current[:reload]
86
88
  self
87
89
  end
88
90
 
@@ -103,19 +105,16 @@ module Shindo
103
105
  def assert(type, expectation, description, &block)
104
106
  return if Thread.main[:exit] || Thread.current[:reload]
105
107
  description = [@description, description].compact.join(' ')
106
- success = nil
107
- @gestalt = Gestalt.new({'formatador' => Thread.current[:formatador]})
108
108
  if block_given?
109
109
  begin
110
110
  for before in @befores.flatten.compact
111
111
  before.call
112
112
  end
113
- value = @gestalt.run(&block)
114
- success = case type
113
+ value, success = case type
115
114
  when :raises
116
- value.is_a?(expectation)
115
+ raises?(expectation, &block)
117
116
  when :returns
118
- value == expectation
117
+ returns?(expectation, &block)
119
118
  end
120
119
  for after in @afters.flatten.compact
121
120
  after.call
@@ -125,9 +124,9 @@ module Shindo
125
124
  value = error
126
125
  end
127
126
  if success
128
- success(description)
127
+ display_success(description)
129
128
  else
130
- failure(description)
129
+ display_failure(description)
131
130
  case value
132
131
  when Exception, Interrupt
133
132
  display_error(value)
@@ -141,35 +140,16 @@ module Shindo
141
140
  end
142
141
  @message = nil
143
142
  end
144
- if STDOUT.tty?
143
+ if Thread.current[:interactive] && STDOUT.tty?
145
144
  prompt(description, &block)
146
145
  end
147
146
  end
148
147
  else
149
- pending(description)
148
+ display_pending(description)
150
149
  end
151
150
  success
152
151
  end
153
152
 
154
- def display_error(error)
155
- Thread.current[:formatador].display_line("[red]#{error.message} (#{error.class})[/]")
156
- unless error.backtrace.empty?
157
- Thread.current[:formatador].indent do
158
- Thread.current[:formatador].display_lines(error.backtrace.map {|line| "[red]#{line}[/]"})
159
- end
160
- end
161
- end
162
-
163
- def failure(description, &block)
164
- Thread.current[:totals][:failed] += 1
165
- Thread.current[:formatador].display_line("[red]- #{description}[/]")
166
- end
167
-
168
- def pending(description, &block)
169
- Thread.current[:totals][:pending] += 1
170
- Thread.current[:formatador].display_line("[yellow]# #{description}[/]")
171
- end
172
-
173
153
  def prompt(description, &block)
174
154
  return if Thread.main[:exit] || Thread.current[:reload]
175
155
  Thread.current[:formatador].display("Action? [c,e,i,q,r,t,?]? ")
@@ -211,7 +191,7 @@ module Shindo
211
191
  end
212
192
  when 'q', 'quit', 'exit'
213
193
  Thread.current[:formatador].display_line("Exiting...")
214
- Thread.current[:exit] = true
194
+ Thread.main[:exit] = true
215
195
  when 'r', 'reload'
216
196
  Thread.current[:formatador].display_line("Reloading...")
217
197
  Thread.current[:reload] = true
@@ -235,17 +215,12 @@ module Shindo
235
215
  end
236
216
  Thread.current[:formatador].display_line
237
217
  end
238
- unless continue || Thread.current[:exit]
218
+ unless continue || Thread.main[:exit]
239
219
  Thread.current[:formatador].display_line("[red]- #{description}[/]")
240
220
  prompt(description, &block)
241
221
  end
242
222
  end
243
223
 
244
- def success(description, &block)
245
- Thread.current[:totals][:succeeded] += 1
246
- Thread.current[:formatador].display_line("[green]+ #{description}[/]")
247
- end
248
-
249
224
  end
250
225
 
251
226
  end
data/lib/shindo/bin.rb ADDED
@@ -0,0 +1,83 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'shindo')
2
+
3
+ @interrupt = lambda do
4
+ formatador = Thread.current[:formatador] || Formatador
5
+ unless Thread.main[:exit]
6
+ formatador.display_line('Gracefully Exiting... (ctrl-c to force)')
7
+ Thread.main[:exit] = true
8
+ else
9
+ formatador.display_line('Exiting...')
10
+ Thread.exit
11
+ end
12
+ end
13
+ Kernel.trap('INT', @interrupt)
14
+
15
+ helpers = Dir.glob(File.join(Dir.pwd, 'tests', '**', '*helper.rb')).sort_by {|helper| helper.count(File::SEPARATOR)}
16
+ tags = []
17
+ for argument in ARGV
18
+ if argument.match(/^[\+\-]/)
19
+ tags << argument
20
+ else
21
+ path = File.expand_path(argument)
22
+ if File.directory?(path)
23
+ tests ||= []
24
+ tests |= Dir.glob(File.join(path, '**', '*tests.rb'))
25
+ elsif File.exists?(path)
26
+ tests ||= []
27
+ tests << path
28
+ else
29
+ Formatador.display_line("[red][bold]#{argument}[/] [red]does not exist, please fix this path and try again.[/]")
30
+ Kernel.exit(1)
31
+ end
32
+ end
33
+ end
34
+
35
+ # ARGV was empty or only contained tags
36
+ unless tests
37
+ tests = Dir.glob(File.join('tests', '**', '*tests.rb'))
38
+ end
39
+
40
+ @started_at = Time.now
41
+ def run_in_thread(helpers, tests, thread_locals)
42
+ shindo = Thread.new {
43
+ for key, value in thread_locals
44
+ Thread.current[key] = value
45
+ end
46
+ for file in helpers
47
+ unless Thread.main[:exit]
48
+ Thread.current[:file] = file
49
+ load(file)
50
+ end
51
+ end
52
+ for file in tests
53
+ unless Thread.main[:exit]
54
+ load(file)
55
+ end
56
+ end
57
+ }
58
+ shindo.join
59
+ if shindo[:reload]
60
+ run_in_thread(helpers, tests, thread_locals)
61
+ else
62
+ @totals = shindo[:totals]
63
+ end
64
+ end
65
+ run_in_thread(helpers, tests, @thread_locals.merge({:tags => tags}))
66
+
67
+ @totals ||= { :failed => 0, :pending => 0, :succeeded => 0 }
68
+ @success = @totals[:failed] == 0
69
+ lines = []
70
+ lines << "[red]#{@totals[:failed]} failed[/]," if @totals[:failed] > 0
71
+ lines << "[yellow]#{@totals[:pending]} pending[/]," if @totals[:pending] > 0
72
+ lines << "[green]#{@totals[:succeeded]} succeeded[/]"
73
+ lines = lines[0...-2].join(', ') << ' and ' << lines[-1] if lines.length > 3
74
+ lines << "in [bold]#{Time.now - @started_at}[/] seconds"
75
+ Formatador.display_line
76
+ Formatador.display_line(lines.join(' '))
77
+ Formatador.display_line
78
+
79
+ if @success
80
+ Kernel.exit(0)
81
+ else
82
+ Kernel.exit(1)
83
+ end
@@ -0,0 +1,65 @@
1
+ module Shindo
2
+ class Tests
3
+
4
+ private
5
+
6
+ def display_description_stack(description_stack = @description_stack, formatador = Formatador.new)
7
+ return if description_stack.empty?
8
+ formatador.indent do
9
+ formatador.display_line(description_stack.pop)
10
+ display_description_stack(description_stack, formatador)
11
+ end
12
+ end
13
+
14
+ def display_description(description)
15
+ unless @indented
16
+ print ' '
17
+ @indented = true
18
+ end
19
+ end
20
+
21
+ def display_error(error)
22
+ Thread.current[:formatador].display_line
23
+ Thread.current[:formatador].display_line(Thread.current[:file])
24
+ display_description_stack
25
+ Thread.current[:formatador].display_line("[red]#{error.message} (#{error.class})[/]")
26
+ unless error.backtrace.empty?
27
+ Thread.current[:formatador].indent do
28
+ Thread.current[:formatador].display_lines(error.backtrace.map {|line| "[red]#{line}[/]"})
29
+ end
30
+ end
31
+ end
32
+
33
+ def display_failure(description)
34
+ Thread.current[:totals][:failed] += 1
35
+ Thread.current[:formatador].display_line
36
+ Thread.current[:formatador].display_line(Thread.current[:file])
37
+ display_description_stack
38
+ Thread.current[:formatador].display_line("[red]- #{description}[/]")
39
+ end
40
+
41
+ def display_pending(description)
42
+ Thread.current[:totals][:pending] += 1
43
+ print Formatador.parse("[yellow]#[/]")
44
+ end
45
+
46
+ def display_success(description)
47
+ Thread.current[:totals][:succeeded] += 1
48
+ print Formatador.parse("[green]+[/]")
49
+ end
50
+
51
+ def raises?(expectation, &block)
52
+ value = begin
53
+ instance_eval(&block)
54
+ rescue => error
55
+ error
56
+ end
57
+ [value, value.is_a?(expectation)]
58
+ end
59
+
60
+ def returns?(expectation, &block)
61
+ [value = instance_eval(&block), value == expectation]
62
+ end
63
+
64
+ end
65
+ end
@@ -0,0 +1,45 @@
1
+ module Shindo
2
+ class Tests
3
+
4
+ private
5
+
6
+ def display_description(description)
7
+ Thread.current[:formatador].display_line(description)
8
+ end
9
+
10
+ def display_error(error)
11
+ Thread.current[:formatador].display_line("[red]#{error.message} (#{error.class})[/]")
12
+ unless error.backtrace.empty?
13
+ Thread.current[:formatador].indent do
14
+ Thread.current[:formatador].display_lines(error.backtrace.map {|line| "[red]#{line}[/]"})
15
+ end
16
+ end
17
+ end
18
+
19
+ def display_failure(description)
20
+ Thread.current[:totals][:failed] += 1
21
+ Thread.current[:formatador].display_line("[red]- #{description}[/]")
22
+ end
23
+
24
+ def display_pending(description)
25
+ Thread.current[:totals][:pending] += 1
26
+ Thread.current[:formatador].display_line("[yellow]# #{description}[/]")
27
+ end
28
+
29
+ def display_success(description)
30
+ Thread.current[:totals][:succeeded] += 1
31
+ Thread.current[:formatador].display_line("[green]+ #{description}[/]")
32
+ end
33
+
34
+ def raises?(expectation, &block)
35
+ @gestalt = Gestalt.new({'formatador' => Thread.current[:formatador]})
36
+ [value = @gestalt.run(&block), value.is_a?(expectation)]
37
+ end
38
+
39
+ def returns?(expectation, &block)
40
+ @gestalt = Gestalt.new({'formatador' => Thread.current[:formatador]})
41
+ [value = @gestalt.run(&block), value == expectation]
42
+ end
43
+
44
+ end
45
+ end
data/shindo.gemspec CHANGED
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
13
13
  ## If your rubyforge_project name is different, then edit it and comment out
14
14
  ## the sub! line in the Rakefile
15
15
  s.name = 'shindo'
16
- s.version = '0.1.4'
17
- s.date = '2010-05-30'
16
+ s.version = '0.1.5'
17
+ s.date = '2010-06-14'
18
18
  s.rubyforge_project = 'shindo'
19
19
 
20
20
  ## Make sure your summary is short. The description may be as long
@@ -65,8 +65,12 @@ Gem::Specification.new do |s|
65
65
  README.rdoc
66
66
  Rakefile
67
67
  bin/shindo
68
+ bin/shindont
68
69
  lib/shindo.rb
70
+ lib/shindo/bin.rb
69
71
  lib/shindo/rake.rb
72
+ lib/shindo/taciturn.rb
73
+ lib/shindo/verbose.rb
70
74
  shindo.gemspec
71
75
  tests/basic_tests.rb
72
76
  tests/bin_tests.rb
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 4
9
- version: 0.1.4
8
+ - 5
9
+ version: 0.1.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - geemus (Wesley Beary)
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-05-30 00:00:00 -05:00
17
+ date: 2010-06-14 00:00:00 -07:00
18
18
  default_executable: shindo
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -59,8 +59,12 @@ files:
59
59
  - README.rdoc
60
60
  - Rakefile
61
61
  - bin/shindo
62
+ - bin/shindont
62
63
  - lib/shindo.rb
64
+ - lib/shindo/bin.rb
63
65
  - lib/shindo/rake.rb
66
+ - lib/shindo/taciturn.rb
67
+ - lib/shindo/verbose.rb
64
68
  - shindo.gemspec
65
69
  - tests/basic_tests.rb
66
70
  - tests/bin_tests.rb