shindo 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/bin/shindo +18 -2
  2. data/lib/shindo.rb +35 -34
  3. data/shindo.gemspec +2 -2
  4. metadata +3 -3
data/bin/shindo CHANGED
@@ -1,4 +1,16 @@
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
+
2
14
  require File.join(File.dirname(__FILE__), '..', 'lib', 'shindo')
3
15
 
4
16
  helpers = Dir.glob(File.join(Dir.pwd, 'tests', '**', '*helper.rb')).sort_by {|helper| helper.count(File::SEPARATOR)}
@@ -31,10 +43,14 @@ def run_in_thread(helpers, tests, tags)
31
43
  shindo = Thread.new {
32
44
  Thread.current[:tags] = tags
33
45
  for file in helpers
34
- load(file)
46
+ unless Thread.main[:exit]
47
+ load(file)
48
+ end
35
49
  end
36
50
  for file in tests
37
- load(file)
51
+ unless Thread.main[:exit]
52
+ load(file)
53
+ end
38
54
  end
39
55
  }
40
56
  shindo.join
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.3'
8
+ VERSION = '0.1.4'
9
9
  end
10
10
 
11
11
  def self.tests(description = nil, tags = [], &block)
@@ -18,8 +18,8 @@ module Shindo
18
18
  def initialize(description, tags = [], &block)
19
19
  @afters = []
20
20
  @befores = []
21
- @formatador = Formatador.new
22
21
  @tag_stack = []
22
+ Thread.current[:formatador] = Formatador.new
23
23
  Thread.current[:reload] = false
24
24
  Thread.current[:tags] ||= []
25
25
  Thread.current[:totals] ||= { :failed => 0, :pending => 0, :skipped => 0, :succeeded => 0 }
@@ -33,9 +33,9 @@ module Shindo
33
33
  @unless_tagged << tag[1..-1]
34
34
  end
35
35
  end
36
- @formatador.display_line
36
+ Thread.current[:formatador].display_line
37
37
  tests(description, tags, &block)
38
- @formatador.display_line
38
+ Thread.current[:formatador].display_line
39
39
  end
40
40
 
41
41
  def after(&block)
@@ -47,7 +47,7 @@ module Shindo
47
47
  end
48
48
 
49
49
  def tests(description, tags = [], &block)
50
- return self if @exit || Thread.current[:reload]
50
+ return self if Thread.main[:exit] || Thread.current[:reload]
51
51
 
52
52
  tags = [*tags]
53
53
  @tag_stack.push(tags)
@@ -66,8 +66,8 @@ module Shindo
66
66
  (@unless_tagged.empty? || (@unless_tagged & @tag_stack.flatten).empty?)
67
67
  if block_given?
68
68
  begin
69
- @formatador.display_line(description)
70
- @formatador.indent { instance_eval(&block) }
69
+ Thread.current[:formatador].display_line(description)
70
+ Thread.current[:formatador].indent { instance_eval(&block) }
71
71
  rescue => error
72
72
  display_error(error)
73
73
  end
@@ -75,14 +75,14 @@ module Shindo
75
75
  @description = description
76
76
  end
77
77
  else
78
- @formatador.display_line("[light_black]#{description}[/]")
78
+ Thread.current[:formatador].display_line("[light_black]#{description}[/]")
79
79
  end
80
80
 
81
81
  @afters.pop
82
82
  @befores.pop
83
83
  @tag_stack.pop
84
84
 
85
- Thread.exit if @exit || Thread.current[:reload]
85
+ Thread.exit if Thread.current[:exit] || Thread.current[:reload]
86
86
  self
87
87
  end
88
88
 
@@ -101,10 +101,10 @@ module Shindo
101
101
  private
102
102
 
103
103
  def assert(type, expectation, description, &block)
104
- return if @exit || Thread.current[:reload]
104
+ return if Thread.main[:exit] || Thread.current[:reload]
105
105
  description = [@description, description].compact.join(' ')
106
106
  success = nil
107
- @gestalt = Gestalt.new({'formatador' => @formatador})
107
+ @gestalt = Gestalt.new({'formatador' => Thread.current[:formatador]})
108
108
  if block_given?
109
109
  begin
110
110
  for before in @befores.flatten.compact
@@ -136,8 +136,8 @@ module Shindo
136
136
  "expected => #{expectation.inspect}",
137
137
  "returned => #{value.inspect}"
138
138
  ]
139
- @formatador.indent do
140
- @formatador.display_lines([*@message].map {|message| "[red]#{message}[/]"})
139
+ Thread.current[:formatador].indent do
140
+ Thread.current[:formatador].display_lines([*@message].map {|message| "[red]#{message}[/]"})
141
141
  end
142
142
  @message = nil
143
143
  end
@@ -152,30 +152,31 @@ module Shindo
152
152
  end
153
153
 
154
154
  def display_error(error)
155
- @formatador.display_line("[red]#{error.message} (#{error.class})[/]")
155
+ Thread.current[:formatador].display_line("[red]#{error.message} (#{error.class})[/]")
156
156
  unless error.backtrace.empty?
157
- @formatador.indent do
158
- @formatador.display_lines(error.backtrace.map {|line| "[red]#{line}[/]"})
157
+ Thread.current[:formatador].indent do
158
+ Thread.current[:formatador].display_lines(error.backtrace.map {|line| "[red]#{line}[/]"})
159
159
  end
160
160
  end
161
161
  end
162
162
 
163
163
  def failure(description, &block)
164
164
  Thread.current[:totals][:failed] += 1
165
- @formatador.display_line("[red]- #{description}[/]")
165
+ Thread.current[:formatador].display_line("[red]- #{description}[/]")
166
166
  end
167
167
 
168
168
  def pending(description, &block)
169
169
  Thread.current[:totals][:pending] += 1
170
- @formatador.display_line("[yellow]# #{description}[/]")
170
+ Thread.current[:formatador].display_line("[yellow]# #{description}[/]")
171
171
  end
172
172
 
173
173
  def prompt(description, &block)
174
- @formatador.display("Action? [c,e,i,q,r,t,?]? ")
174
+ return if Thread.main[:exit] || Thread.current[:reload]
175
+ Thread.current[:formatador].display("Action? [c,e,i,q,r,t,?]? ")
175
176
  choice = STDIN.gets.strip
176
177
  continue = false
177
- @formatador.display_line
178
- @formatador.indent do
178
+ Thread.current[:formatador].display_line
179
+ Thread.current[:formatador].indent do
179
180
  case choice
180
181
  when 'c', 'continue'
181
182
  continue = true
@@ -185,12 +186,12 @@ module Shindo
185
186
  if value.nil?
186
187
  value = 'nil'
187
188
  end
188
- @formatador.display_line(value)
189
+ Thread.current[:formatador].display_line(value)
189
190
  rescue => error
190
191
  display_error(error)
191
192
  end
192
193
  when 'i', 'interactive', 'irb'
193
- @formatador.display_line('Starting interactive session...')
194
+ Thread.current[:formatador].display_line('Starting interactive session...')
194
195
  if @irb.nil?
195
196
  require 'irb'
196
197
  ARGV.clear # Avoid passing args to IRB
@@ -200,7 +201,7 @@ module Shindo
200
201
  IRB.conf[:PROMPT][:SHINDO] = {}
201
202
  end
202
203
  for key, value in IRB.conf[:PROMPT][:SIMPLE]
203
- IRB.conf[:PROMPT][:SHINDO][key] = "#{@formatador.indentation}#{value}"
204
+ IRB.conf[:PROMPT][:SHINDO][key] = "#{Thread.current[:formatador].indentation}#{value}"
204
205
  end
205
206
  @irb.context.prompt_mode = :SHINDO
206
207
  @irb.context.workspace = IRB::WorkSpace.new(@gestalt.bindings.last)
@@ -209,19 +210,19 @@ module Shindo
209
210
  rescue SystemExit
210
211
  end
211
212
  when 'q', 'quit', 'exit'
212
- @formatador.display_line("Exiting...")
213
- @exit = true
213
+ Thread.current[:formatador].display_line("Exiting...")
214
+ Thread.current[:exit] = true
214
215
  when 'r', 'reload'
215
- @formatador.display_line("Reloading...")
216
+ Thread.current[:formatador].display_line("Reloading...")
216
217
  Thread.current[:reload] = true
217
218
  when 't', 'backtrace', 'trace'
218
219
  if @gestalt.calls.empty?
219
- @formatador.display_line("[red]No methods were called, so no backtrace was captured.[/]")
220
+ Thread.current[:formatador].display_line("[red]No methods were called, so no backtrace was captured.[/]")
220
221
  else
221
222
  @gestalt.display_calls
222
223
  end
223
224
  when '?', 'help'
224
- @formatador.display_lines([
225
+ Thread.current[:formatador].display_lines([
225
226
  'c - ignore this error and continue',
226
227
  'i - interactive mode',
227
228
  'q - quit Shindo',
@@ -230,19 +231,19 @@ module Shindo
230
231
  '? - display help'
231
232
  ])
232
233
  else
233
- @formatador.display_line("[red]#{choice} is not a valid choice, please try again.[/]")
234
+ Thread.current[:formatador].display_line("[red]#{choice} is not a valid choice, please try again.[/]")
234
235
  end
235
- @formatador.display_line
236
+ Thread.current[:formatador].display_line
236
237
  end
237
- unless continue || @exit
238
- @formatador.display_line("[red]- #{description}[/]")
238
+ unless continue || Thread.current[:exit]
239
+ Thread.current[:formatador].display_line("[red]- #{description}[/]")
239
240
  prompt(description, &block)
240
241
  end
241
242
  end
242
243
 
243
244
  def success(description, &block)
244
245
  Thread.current[:totals][:succeeded] += 1
245
- @formatador.display_line("[green]+ #{description}[/]")
246
+ Thread.current[:formatador].display_line("[green]+ #{description}[/]")
246
247
  end
247
248
 
248
249
  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.3'
17
- s.date = '2010-05-24'
16
+ s.version = '0.1.4'
17
+ s.date = '2010-05-30'
18
18
  s.rubyforge_project = 'shindo'
19
19
 
20
20
  ## Make sure your summary is short. The description may be as long
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 3
9
- version: 0.1.3
8
+ - 4
9
+ version: 0.1.4
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-24 00:00:00 -07:00
17
+ date: 2010-05-30 00:00:00 -05:00
18
18
  default_executable: shindo
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency