shindo 0.0.7 → 0.0.8

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.
Files changed (5) hide show
  1. data/Rakefile +2 -1
  2. data/VERSION +1 -1
  3. data/lib/shindo.rb +52 -93
  4. data/shindo.gemspec +8 -5
  5. metadata +13 -3
data/Rakefile CHANGED
@@ -4,7 +4,6 @@ require 'rake'
4
4
  begin
5
5
  require 'jeweler'
6
6
  Jeweler::Tasks.new do |gem|
7
- gem.add_dependency('annals')
8
7
  gem.name = "shindo"
9
8
  gem.summary = %Q{ruby testing}
10
9
  gem.description = %Q{Simple depth first ruby testing}
@@ -12,6 +11,8 @@ begin
12
11
  gem.homepage = "http://github.com/geemus/shindo"
13
12
  gem.authors = ["geemus (Wesley Beary)"]
14
13
  gem.rubyforge_project = "shindo"
14
+ gem.add_dependency('annals', '>=0.0.2')
15
+ gem.add_dependency('formatador', '>=0.0.2')
15
16
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
17
  end
17
18
  rescue LoadError
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.7
1
+ 0.0.8
@@ -1,5 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'annals'
3
+ require 'formatador'
3
4
 
4
5
  module Shindo
5
6
 
@@ -16,7 +17,10 @@ module Shindo
16
17
  @afters = []
17
18
  @annals = Annals.new
18
19
  @befores = []
19
- @description_stack = []
20
+ @formatador = Formatador.new
21
+ @success = true
22
+ @tag_stack = []
23
+ Thread.current[:reload] = false;
20
24
  Thread.current[:tags] ||= []
21
25
  @if_tagged = Thread.current[:tags].
22
26
  select {|tag| tag.match(/^\+/)}.
@@ -24,18 +28,10 @@ module Shindo
24
28
  @unless_tagged = Thread.current[:tags].
25
29
  select {|tag| tag.match(/^\-/)}.
26
30
  map {|tag| tag[1..-1]}
27
- @indent = 1
28
- @success = true
29
- @tag_stack = []
30
- Thread.current[:reload] = false
31
- print("\n")
31
+ @formatador.display_line('')
32
32
  tests(header, tags, &block)
33
- print("\n")
34
- if @success
35
- Thread.current[:success] = true
36
- else
37
- Thread.current[:success] = false
38
- end
33
+ @formatador.display_line('')
34
+ Thread.current[:success] = @success
39
35
  end
40
36
 
41
37
  def after(&block)
@@ -46,58 +42,33 @@ module Shindo
46
42
  @befores[-1].push(block)
47
43
  end
48
44
 
49
- def full_description
50
- "#{@description_stack.compact.join(' ')}#{full_tags}"
51
- end
52
-
53
- def full_tags
45
+ def tags
54
46
  unless @tag_stack.flatten.empty?
55
47
  " [#{@tag_stack.flatten.join(', ')}]"
56
48
  end
57
49
  end
58
50
 
59
- def green_line(content)
60
- print_line(content, "\e[32m")
61
- end
62
-
63
- def indent(&block)
64
- @indent += 1
65
- yield
66
- @indent -= 1
67
- end
68
-
69
- def indentation
70
- ' ' * @indent
71
- end
72
-
73
- def print_line(content, color = nil)
74
- if color && STDOUT.tty?
75
- content = "#{color}#{content}\e[0m"
76
- end
77
- print("#{indentation}#{content}\n")
78
- end
79
-
80
- def prompt(&block)
81
- print("#{indentation}Action? [c,i,q,r,t,#,?]? ")
51
+ def prompt(description, &block)
52
+ @formatador.display("#{@formatador.indentation}Action? [c,i,q,r,t,#,?]? ")
82
53
  choice = STDIN.gets.strip
83
- print("\n")
54
+ @formatador.display_line("")
84
55
  case choice
85
56
  when 'c'
86
57
  return
87
58
  when 'i'
88
- print_line('Starting interactive session...')
59
+ @formatador.display_line('Starting interactive session...')
89
60
  if @irb.nil?
90
61
  require 'irb'
91
62
  ARGV.clear # Avoid passing args to IRB
92
63
  IRB.setup(nil)
93
64
  @irb = IRB::Irb.new(nil)
94
65
  IRB.conf[:MAIN_CONTEXT] = @irb.context
95
- IRB.conf[:PROMPT][:TREST] = {}
66
+ IRB.conf[:PROMPT][:SHINDO] = {}
96
67
  end
97
68
  for key, value in IRB.conf[:PROMPT][:SIMPLE]
98
- IRB.conf[:PROMPT][:TREST][key] = "#{indentation}#{value}"
69
+ IRB.conf[:PROMPT][:SHINDO][key] = "#{@formatador.indentation}#{value}"
99
70
  end
100
- @irb.context.prompt_mode = :TREST
71
+ @irb.context.prompt_mode = :SHINDO
101
72
  @irb.context.workspace = IRB::WorkSpace.new(block.binding)
102
73
  begin
103
74
  @irb.eval_input
@@ -107,37 +78,35 @@ module Shindo
107
78
  Thread.current[:success] = false
108
79
  Thread.exit
109
80
  when 'r'
110
- print("Reloading...\n")
81
+ @formatador.display_line("Reloading...")
111
82
  Thread.current[:reload] = true
112
83
  Thread.exit
113
84
  when 't'
114
- indent {
85
+ @formatador.indent do
115
86
  if @annals.lines.empty?
116
- print_line('no backtrace available')
87
+ @formatador.display_line('no backtrace available')
117
88
  else
118
- index = 1
119
- for line in @annals.lines
120
- print_line("#{' ' * (2 - index.to_s.length)}#{index} #{line}")
121
- index += 1
89
+ @annals.lines.each_with_index do |line, index|
90
+ @formatador.display_line("#{' ' * (2 - index.to_s.length)}#{index} #{line}")
122
91
  end
123
92
  end
124
- }
125
- print("\n")
93
+ end
94
+ @formatador.display_line('')
126
95
  when '?'
127
- print_line('c - ignore this error and continue')
128
- print_line('i - interactive mode')
129
- print_line('q - quit Shindo')
130
- print_line('r - reload and run the tests again')
131
- print_line('t - display backtrace')
132
- print_line('# - enter a number of a backtrace line to see its context')
133
- print_line('? - display help')
96
+ @formatador.display_line('c - ignore this error and continue')
97
+ @formatador.display_line('i - interactive mode')
98
+ @formatador.display_line('q - quit Shindo')
99
+ @formatador.display_line('r - reload and run the tests again')
100
+ @formatador.display_line('t - display backtrace')
101
+ @formatador.display_line('# - enter a number of a backtrace line to see its context')
102
+ @formatador.display_line('? - display help')
134
103
  when /\d/
135
104
  index = choice.to_i - 1
136
105
  if @annals.lines[index]
137
- indent {
138
- print_line("#{@annals.lines[index]}: ")
139
- indent {
140
- print("\n")
106
+ @formatador.indent do
107
+ @formatador.display_line("#{@annals.lines[index]}: ")
108
+ @formatador.indent do
109
+ @formatador.display("\n")
141
110
  current_line = @annals.buffer[index]
142
111
  File.open(current_line[:file], 'r') do |file|
143
112
  data = file.readlines
@@ -145,38 +114,34 @@ module Shindo
145
114
  min = [0, current - (@annals.max / 2)].max
146
115
  max = [current + (@annals.max / 2), data.length].min
147
116
  min.upto(current - 1) do |line|
148
- print_line("#{line} #{data[line].rstrip}")
117
+ @formatador.display_line("#{line} #{data[line].rstrip}")
149
118
  end
150
- yellow_line("#{current} #{data[current].rstrip}")
119
+ @formatador.display_line("[yellow]#{current} #{data[current].rstrip}[/]")
151
120
  (current + 1).upto(max - 1) do |line|
152
- print_line("#{line} #{data[line].rstrip}")
121
+ @formatador.display_line("#{line} #{data[line].rstrip}")
153
122
  end
154
123
  end
155
- print("\n")
156
- }
157
- }
124
+ @formatador.display_line('')
125
+ end
126
+ end
158
127
  else
159
- red_line("#{choice} is not a valid backtrace line, please try again.")
128
+ @formatador.display_line("[red]#{choice} is not a valid backtrace line, please try again.[/]")
160
129
  end
161
130
  else
162
- red_line("#{choice} is not a valid choice, please try again.")
131
+ @formatador.display_line("[red]#{choice} is not a valid choice, please try again.[/]")
163
132
  end
164
- red_line("- #{full_description}")
133
+ @formatador.display_line("[red]- #{description}[/]")
165
134
  prompt(&block)
166
135
  end
167
136
 
168
- def red_line(content)
169
- print_line(content, "\e[31m")
170
- end
171
-
172
137
  def tests(description, tags = [], &block)
173
138
  @tag_stack.push([*tags])
174
139
  @befores.push([])
175
140
  @afters.push([])
176
141
 
177
- print_line(description || 'Shindo.tests')
142
+ @formatador.display_line(description || 'Shindo.tests')
178
143
  if block_given?
179
- indent { instance_eval(&block) }
144
+ @formatador.indent { instance_eval(&block) }
180
145
  end
181
146
 
182
147
  @afters.pop
@@ -185,10 +150,9 @@ module Shindo
185
150
  end
186
151
 
187
152
  def test(description, tags = [], &block)
188
- @description_stack.push(description)
189
153
  @tag_stack.push([*tags])
190
154
 
191
- # if the test includes tags and discludes ^tags, evaluate it
155
+ # if the test includes +tags and discludes -tags, evaluate it
192
156
  if (@if_tagged.empty? || !(@if_tagged & @tag_stack.flatten).empty?) &&
193
157
  (@unless_tagged.empty? || (@unless_tagged & @tag_stack.flatten).empty?)
194
158
  if block_given?
@@ -201,6 +165,7 @@ module Shindo
201
165
  success = instance_eval(&block)
202
166
  @annals.stop
203
167
  rescue => error
168
+ @annals.stop
204
169
  success = false
205
170
  file, line, method = error.backtrace.first.split(':')
206
171
  if method
@@ -209,16 +174,15 @@ module Shindo
209
174
  method = ''
210
175
  end
211
176
  method << "! #{error.message} (#{error.class})"
212
- @annals.stop
213
177
  @annals.unshift(:file => file, :line => line.to_i, :method => method)
214
178
  end
215
179
  @success = @success && success
216
180
  if success
217
- green_line("+ #{full_description}")
181
+ @formatador.display_line("[green]+ #{description}#{tags}[/]")
218
182
  else
219
- red_line("- #{full_description}")
183
+ @formatador.display_line("[red]- #{description}#{tags}[/]")
220
184
  if STDOUT.tty?
221
- prompt(&block)
185
+ prompt(description, &block)
222
186
  end
223
187
  end
224
188
 
@@ -226,18 +190,13 @@ module Shindo
226
190
  after.call
227
191
  end
228
192
  else
229
- yellow_line("* #{full_description}")
193
+ @formatador.display_line("[yellow]* #{description}[/]")
230
194
  end
231
195
  else
232
- print_line("_ #{full_description}")
196
+ @formatador.display_line("_ #{description}")
233
197
  end
234
198
 
235
199
  @tag_stack.pop
236
- @description_stack.pop
237
- end
238
-
239
- def yellow_line(content)
240
- print_line(content, "\e[33m")
241
200
  end
242
201
 
243
202
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{shindo}
8
- s.version = "0.0.7"
8
+ s.version = "0.0.8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["geemus (Wesley Beary)"]
12
- s.date = %q{2009-11-23}
12
+ s.date = %q{2009-12-01}
13
13
  s.default_executable = %q{shindo}
14
14
  s.description = %q{Simple depth first ruby testing}
15
15
  s.email = %q{me@geemus.com}
@@ -43,12 +43,15 @@ Gem::Specification.new do |s|
43
43
  s.specification_version = 3
44
44
 
45
45
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
46
- s.add_runtime_dependency(%q<annals>, [">= 0"])
46
+ s.add_runtime_dependency(%q<annals>, [">= 0.0.2"])
47
+ s.add_runtime_dependency(%q<formatador>, [">= 0.0.2"])
47
48
  else
48
- s.add_dependency(%q<annals>, [">= 0"])
49
+ s.add_dependency(%q<annals>, [">= 0.0.2"])
50
+ s.add_dependency(%q<formatador>, [">= 0.0.2"])
49
51
  end
50
52
  else
51
- s.add_dependency(%q<annals>, [">= 0"])
53
+ s.add_dependency(%q<annals>, [">= 0.0.2"])
54
+ s.add_dependency(%q<formatador>, [">= 0.0.2"])
52
55
  end
53
56
  end
54
57
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shindo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - geemus (Wesley Beary)
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-23 00:00:00 -08:00
12
+ date: 2009-12-01 00:00:00 -08:00
13
13
  default_executable: shindo
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -20,7 +20,17 @@ dependencies:
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: "0"
23
+ version: 0.0.2
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: formatador
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.0.2
24
34
  version:
25
35
  description: Simple depth first ruby testing
26
36
  email: me@geemus.com