dots 0.0.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/History.rdoc +5 -0
- data/Manifest.txt +16 -0
- data/README.rdoc +89 -0
- data/Rakefile +40 -0
- data/cucumber.yml +1 -0
- data/dots.gemspec +26 -0
- data/features/dots.feature +49 -0
- data/features/step_definitions/dots_steps.rb +59 -0
- data/features/support/env.rb +4 -0
- data/lib/dots.rb +169 -0
- data/lib/dots/kaoemoji.rb +5 -0
- data/lib/dots/rainbows.rb +5 -0
- data/lib/dots/redgreen.rb +14 -0
- data/spec/dots_spec.rb +131 -0
- metadata +72 -0
data/History.rdoc
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
History.rdoc
|
2
|
+
Manifest.txt
|
3
|
+
Rakefile
|
4
|
+
README.rdoc
|
5
|
+
cucumber.yml
|
6
|
+
dots.gemspec
|
7
|
+
features
|
8
|
+
features/dots.feature
|
9
|
+
features/step_definitions/dots_steps.rb
|
10
|
+
features/support/env.rb
|
11
|
+
lib
|
12
|
+
lib/dots/kaoemoji.rb
|
13
|
+
lib/dots/rainbows.rb
|
14
|
+
lib/dots/redgreen.rb
|
15
|
+
lib/dots.rb
|
16
|
+
spec/dots_spec.rb
|
data/README.rdoc
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
RDoc.......................................................................
|
2
|
+
........................FFF................FFF.........F...................
|
3
|
+
........................FF.................FF...........E..................
|
4
|
+
..................FFFFF.FF....FFFFFF....FEFFFEF...FEEFFEE..................
|
5
|
+
................FF....FFFF...FE....FFF....FFF....FEF.......................
|
6
|
+
................FFF....FFF...FEF....FF.....FF......FFEEF...................
|
7
|
+
..................FEEEF.FFF....EEEEEF.......FEF........FFF.................
|
8
|
+
...................................................FFEEFF..................
|
9
|
+
................FFFFFEEEEEFFFFF.F..F.FFFFFEEEEEEFFFFF......................
|
10
|
+
..............F........F.FFFFEEEEEEEEEEFFFFF.F.............................
|
11
|
+
.....................................................................ready!
|
12
|
+
|
13
|
+
Free progress dots for your scripts. <tt>Test::Unit</tt>-style.
|
14
|
+
|
15
|
+
http://github.com/stephencelis/dots
|
16
|
+
|
17
|
+
|
18
|
+
== Example
|
19
|
+
|
20
|
+
% ruby -rubygems
|
21
|
+
require "dots"
|
22
|
+
require "open-uri"
|
23
|
+
require "hpricot"
|
24
|
+
|
25
|
+
File.open("alts.txt", "w") do |f|
|
26
|
+
(1..10).each.with_dots do |n|
|
27
|
+
doc = Hpricot open("http://www.qwantz.com/archive/%06d.html" % n)
|
28
|
+
alt = (doc / "font img").pop["title"]
|
29
|
+
raise "No alt text found!" if alt.nil?
|
30
|
+
f.puts "%3d. %s" % [n, alt]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
^D
|
34
|
+
..........
|
35
|
+
Finished in 6.225932 seconds.
|
36
|
+
|
37
|
+
10 total, 10 passed, 0 failed, 0 erred
|
38
|
+
|
39
|
+
|
40
|
+
== Usage
|
41
|
+
|
42
|
+
Swap out +each+ for +each_with_dots+, or, with enumerators, just add
|
43
|
+
+with_dots+; if you don't want to write to standard output, specify the IO as
|
44
|
+
an argument for +each_with_dots+ (or +with_dots+).
|
45
|
+
|
46
|
+
Raise nameless (i.e., +RuntimeError+) exceptions for potential failures.
|
47
|
+
|
48
|
+
|
49
|
+
== Extras
|
50
|
+
|
51
|
+
* <tt>require "dots/redgreen"</tt>
|
52
|
+
* <tt>require "dots/rainbows"</tt>
|
53
|
+
* <tt>require "dots/kaoemoji"</tt>
|
54
|
+
|
55
|
+
Oh, and for heavy, non-iterative processing:
|
56
|
+
|
57
|
+
dots do
|
58
|
+
# ...
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
== Install
|
63
|
+
|
64
|
+
% sudo gem install stephencelis-dots --source=http://gems.github.com
|
65
|
+
|
66
|
+
|
67
|
+
== License
|
68
|
+
|
69
|
+
(The MIT License)
|
70
|
+
|
71
|
+
(c) 2009-* Stephen Celis, stephen@stephencelis.com.
|
72
|
+
|
73
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
74
|
+
of this software and associated documentation files (the "Software"), to deal
|
75
|
+
in the Software without restriction, including without limitation the rights
|
76
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
77
|
+
copies of the Software, and to permit persons to whom the Software is
|
78
|
+
furnished to do so, subject to the following conditions:
|
79
|
+
|
80
|
+
The above copyright notice and this permission notice shall be included in all
|
81
|
+
copies or substantial portions of the Software.
|
82
|
+
|
83
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
84
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
85
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
86
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
87
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
88
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
89
|
+
SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
defaults = [:requirements]
|
2
|
+
required = []
|
3
|
+
required << "* Ruby 1.8.7 or greater is required" if RUBY_VERSION < "1.8.7"
|
4
|
+
|
5
|
+
desc "Show any uninstalled requirements to run the full test suite"
|
6
|
+
task :requirements do
|
7
|
+
puts required
|
8
|
+
end
|
9
|
+
|
10
|
+
begin
|
11
|
+
require "spec/rake/spectask"
|
12
|
+
|
13
|
+
desc "Run all specs"
|
14
|
+
Spec::Rake::SpecTask.new :spec do |t|
|
15
|
+
t.ruby_opts = ["-Ilib"]
|
16
|
+
t.spec_opts = ["--color"]
|
17
|
+
t.spec_files = FileList["spec/**/*_spec.rb"]
|
18
|
+
end
|
19
|
+
|
20
|
+
defaults << :spec
|
21
|
+
rescue LoadError
|
22
|
+
required << "* RSpec is required."
|
23
|
+
end
|
24
|
+
|
25
|
+
begin
|
26
|
+
require "cucumber/rake/task"
|
27
|
+
|
28
|
+
desc "Run all features"
|
29
|
+
Cucumber::Rake::Task.new :features do |t|
|
30
|
+
t.cucumber_opts = "--no-source --format=progress features"
|
31
|
+
end
|
32
|
+
|
33
|
+
defaults << :features
|
34
|
+
rescue LoadError
|
35
|
+
required << "* Cucumber is required"
|
36
|
+
end
|
37
|
+
|
38
|
+
defaults << :requirements if defaults.empty?
|
39
|
+
|
40
|
+
task :default => defaults
|
data/cucumber.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
default: --no-source features
|
data/dots.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{dots}
|
5
|
+
s.version = "0.0.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Stephen Celis"]
|
9
|
+
s.date = %q{2009-05-10}
|
10
|
+
s.description = %q{Free progress dots for your scripts.}
|
11
|
+
s.email = ["stephen@stephencelis.com"]
|
12
|
+
s.extra_rdoc_files = ["History.rdoc", "Manifest.txt", "README.rdoc"]
|
13
|
+
s.files = ["History.rdoc", "Manifest.txt", "Rakefile", "README.rdoc", "cucumber.yml", "dots.gemspec", "features", "features/dots.feature", "features/step_definitions/dots_steps.rb", "features/support/env.rb", "lib", "lib/dots/kaoemoji.rb", "lib/dots/rainbows.rb", "lib/dots/redgreen.rb", "lib/dots.rb", "spec/dots_spec.rb"]
|
14
|
+
s.has_rdoc = true
|
15
|
+
s.rdoc_options = ["--main", "README.rdoc"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = %q{dots}
|
18
|
+
s.rubygems_version = %q{1.3.2}
|
19
|
+
s.summary = %q{Free progress dots for your scripts}
|
20
|
+
s.homepage = "http://github.com/stephencelis/dots"
|
21
|
+
|
22
|
+
if s.respond_to? :specification_version then
|
23
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
24
|
+
s.specification_version = 3
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
Feature: dot progress
|
2
|
+
In order to keep track of long-running tasks
|
3
|
+
As a task-runner
|
4
|
+
I want to see the progress visually
|
5
|
+
|
6
|
+
Scenario: Display dots
|
7
|
+
Given an array [1, 2, 3, 4, 5]
|
8
|
+
When I run it with dots
|
9
|
+
Then I should see 5 "." dots
|
10
|
+
And I should see 0 "F" dots
|
11
|
+
And I should see 0 "E" dots
|
12
|
+
And I should see how long it took
|
13
|
+
And I should not see "Failure"
|
14
|
+
And I should not see "Error"
|
15
|
+
And I should see "5 total, 5 passed, 0 failed, 0 erred"
|
16
|
+
|
17
|
+
Scenario: Display failures
|
18
|
+
Given an array [1, 2, 3, 4, 5]
|
19
|
+
When I don't want 3s
|
20
|
+
And I run it with dots
|
21
|
+
Then I should see 4 "." dots
|
22
|
+
And I should see 1 "F" dot
|
23
|
+
And I should see 0 "E" dots
|
24
|
+
And I should see how long it took
|
25
|
+
And I should see ") Failure" 1 time
|
26
|
+
And I should not see ") Error"
|
27
|
+
And I should see "No threes!"
|
28
|
+
And I should see the exception's line number
|
29
|
+
And I should see "<3>"
|
30
|
+
And I should see "5 total, 4 passed, 1 failed, 0 erred"
|
31
|
+
|
32
|
+
Scenario: Display errors
|
33
|
+
Given an array [1, 2, 3, 4, 5]
|
34
|
+
When I divide each by zero
|
35
|
+
And I run it with dots
|
36
|
+
Then I should see 5 "E" dots
|
37
|
+
And I should see 0 "." dots
|
38
|
+
And I should see 0 "F" dots
|
39
|
+
And I should see how long it took
|
40
|
+
And I should see ") Error" 5 times
|
41
|
+
And I should see "ZeroDivisionError: divided by 0" 5 times
|
42
|
+
And I should see the exception's line number
|
43
|
+
And I should not see "Failure"
|
44
|
+
And I should see "5 total, 0 passed, 0 failed, 5 erred"
|
45
|
+
|
46
|
+
Scenario: Constant dots
|
47
|
+
Given a task that takes 5 seconds
|
48
|
+
When I run it in a dots block
|
49
|
+
Then I should see 5 "." dots
|
@@ -0,0 +1,59 @@
|
|
1
|
+
Given(/^an \w+ (.+)$/) do |object|
|
2
|
+
@enumerable = eval(object)
|
3
|
+
end
|
4
|
+
|
5
|
+
Given(/^a task that takes (\d+) seconds$/) do |number|
|
6
|
+
short_second = 1 / 100
|
7
|
+
short_seconds = number.to_i / 100
|
8
|
+
@proc = Proc.new { |io| dots(short_second, io) { sleep short_seconds } }
|
9
|
+
end
|
10
|
+
|
11
|
+
When(/^I run it with dots$/) do
|
12
|
+
@proc ||= Proc.new { |each| each }
|
13
|
+
@io = StringIO.new
|
14
|
+
@enumerable.each_with_dots(@io, &@proc)
|
15
|
+
@io.rewind
|
16
|
+
@content = @io.read
|
17
|
+
end
|
18
|
+
|
19
|
+
When(/^I run it in a dots block$/) do
|
20
|
+
@io = StringIO.new ""
|
21
|
+
@proc.call(@io)
|
22
|
+
@io.rewind
|
23
|
+
@content = @io.read
|
24
|
+
end
|
25
|
+
|
26
|
+
When(/^I don't want (\d+)s$/) do |number|
|
27
|
+
@proc = Proc.new { |each| raise "No threes!" if each == number.to_i }
|
28
|
+
@line = __LINE__ - 1
|
29
|
+
end
|
30
|
+
|
31
|
+
When(/^I divide each by zero$/) do
|
32
|
+
@proc = Proc.new { |each| each / 0 }
|
33
|
+
@line = __LINE__ - 1
|
34
|
+
end
|
35
|
+
|
36
|
+
Then(/^I should see (\d+) "([^\"])" dots?$/) do |dot, number|
|
37
|
+
length = @enumerable.nil? ? -1 : @enumerable.length
|
38
|
+
@content[0..length].count(dot).should be(number.to_i)
|
39
|
+
end
|
40
|
+
|
41
|
+
Then(/^I should see how long it took$/) do
|
42
|
+
@content.should match(/Finished in \d+\.\d+ seconds/)
|
43
|
+
end
|
44
|
+
|
45
|
+
Then(/^I should see "([^\"]*)" (\d+) times?$/) do |message, number|
|
46
|
+
@content.split(message).length.should be(number.to_i + 1)
|
47
|
+
end
|
48
|
+
|
49
|
+
Then(/^I should see "([^\"]*)"$/) do |message|
|
50
|
+
@content.should include(message)
|
51
|
+
end
|
52
|
+
|
53
|
+
Then(/^I should not see "([^\"]*)"$/) do |message|
|
54
|
+
@content.should_not include(message)
|
55
|
+
end
|
56
|
+
|
57
|
+
Then(/^I should see the exception's line number$/) do
|
58
|
+
@content.should include("#{File.basename(__FILE__)}:#@line")
|
59
|
+
end
|
data/lib/dots.rb
ADDED
@@ -0,0 +1,169 @@
|
|
1
|
+
# Dots makes dots.
|
2
|
+
module Dots
|
3
|
+
VERSION = "0.0.1"
|
4
|
+
|
5
|
+
class InvalidDot < StandardError
|
6
|
+
end
|
7
|
+
|
8
|
+
#--
|
9
|
+
# Allows us direct access to +Enumerator+, ensuring compatibility with 1.8.7
|
10
|
+
# and 1.9.
|
11
|
+
#++
|
12
|
+
include Enumerable
|
13
|
+
|
14
|
+
#--
|
15
|
+
# How dots appear.
|
16
|
+
#++
|
17
|
+
@@dots = { "." => ".", "F" => "F", "E" => "E" }
|
18
|
+
|
19
|
+
# Access how a dot should appear.
|
20
|
+
def [](key)
|
21
|
+
raise InvalidDot unless @@dots.keys.include? key.to_s
|
22
|
+
dot = @@dots[key.to_s]
|
23
|
+
dot.respond_to?(:call) ? dot.call : dot
|
24
|
+
end
|
25
|
+
|
26
|
+
# Configure how dots appear. For red and green:
|
27
|
+
#
|
28
|
+
# Dots["."] = "\e[32m.\e[0m"
|
29
|
+
# Dots["F"] = "\e[31mF\e[0m"
|
30
|
+
# Dots["E"] = "\e[31mE\e[0m"
|
31
|
+
#
|
32
|
+
# Or, just <tt>require "dots/redgreen"</tt>.
|
33
|
+
#
|
34
|
+
# For a random rainbow, <tt>require "dots/rainbow"</tt>, or use a procedure:
|
35
|
+
#
|
36
|
+
# Dots["."] = Proc.new { \e[%dm.\e[0m" % [rand(10) + 30] }
|
37
|
+
def []=(key, value)
|
38
|
+
raise InvalidDot unless @@dots.keys.include? key.to_s
|
39
|
+
@@dots[key.to_s] = value
|
40
|
+
end
|
41
|
+
|
42
|
+
Enumerable.module_eval do
|
43
|
+
# Sends a dot to standard output (or designated IO) after each iteration.
|
44
|
+
#
|
45
|
+
# If an exception is raised during an iteration, an "E" or "F" will be
|
46
|
+
# sent in dot's stead: "F" for instances of +RuntimeError+, which may be
|
47
|
+
# raised blankly in an iteration, and "E" otherwise, assuming
|
48
|
+
# unanticipated errors.
|
49
|
+
#
|
50
|
+
# Example:
|
51
|
+
#
|
52
|
+
# >> require "dots"
|
53
|
+
# => true
|
54
|
+
# >> (0..5).each_with_dots do |n|
|
55
|
+
# ?> 100 / n
|
56
|
+
# ?> raise "No fours!" if n == 4
|
57
|
+
# ?> end
|
58
|
+
# E...F.
|
59
|
+
# Finished in 0.000430 seconds.
|
60
|
+
#
|
61
|
+
# 1) Error
|
62
|
+
# ZeroDivisionError: divided by 0
|
63
|
+
# with <0>
|
64
|
+
# (irb):3:in `/'
|
65
|
+
# (irb):3:in `irb_binding'
|
66
|
+
# (irb):2:in `irb_binding'
|
67
|
+
# /usr/local/lib/ruby/1.8/irb/workspace.rb:52:in `irb_binding'
|
68
|
+
# /usr/local/lib/ruby/1.8/irb/workspace.rb:52
|
69
|
+
#
|
70
|
+
# 2) Failure
|
71
|
+
# No fours!
|
72
|
+
# with <4>
|
73
|
+
# [(irb):4]
|
74
|
+
def each_with_dots(io = $stdout)
|
75
|
+
old_sync, io.sync = io.sync, true
|
76
|
+
exceptions, passed, start = [], 0, Time.now
|
77
|
+
trap("INT") { return io.puts "abort!" }
|
78
|
+
each do |object|
|
79
|
+
begin
|
80
|
+
yield object
|
81
|
+
io.print Dots["."]
|
82
|
+
passed += 1
|
83
|
+
rescue => e
|
84
|
+
if e.is_a? RuntimeError
|
85
|
+
io.print Dots["F"]
|
86
|
+
else
|
87
|
+
io.print Dots["E"]
|
88
|
+
end
|
89
|
+
exceptions << [object, e] unless exceptions.nil?
|
90
|
+
end
|
91
|
+
end
|
92
|
+
ensure
|
93
|
+
Dots.report exceptions, passed, start, io
|
94
|
+
io.sync = old_sync
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
Enumerator.class_eval do
|
99
|
+
# Returns an <tt>Enumerator</tt> for <tt>Enumerable#each_with_dots</tt>.
|
100
|
+
def with_dots(io = $stdout, &block)
|
101
|
+
enum = enum_for :each_with_dots, io
|
102
|
+
block_given? ? enum.each(&block) : enum
|
103
|
+
end
|
104
|
+
end if RUBY_VERSION >= "1.8.7"
|
105
|
+
|
106
|
+
Kernel.module_eval do
|
107
|
+
private
|
108
|
+
# Sends dots to standard output (or designated IO) on an interval for the
|
109
|
+
# duration of the block.
|
110
|
+
#
|
111
|
+
# Example:
|
112
|
+
#
|
113
|
+
# >> dots do
|
114
|
+
# ?> sleep 5
|
115
|
+
# ?> end
|
116
|
+
# .....=> 5
|
117
|
+
def dots(interval = 1, io = $stdout)
|
118
|
+
old_sync, io.sync = io.sync, true
|
119
|
+
|
120
|
+
thread = Thread.new do
|
121
|
+
dot = lambda do
|
122
|
+
io.print Dots["."]
|
123
|
+
sleep interval and dot.call
|
124
|
+
end
|
125
|
+
dot.call
|
126
|
+
end
|
127
|
+
|
128
|
+
yield
|
129
|
+
ensure
|
130
|
+
io.sync = old_sync
|
131
|
+
thread.kill
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
# Formats reports for +each_with_dots+.
|
136
|
+
def report(exceptions, passed = 0, start = nil, io = $stdout)
|
137
|
+
failed = erred = 0
|
138
|
+
|
139
|
+
io.puts
|
140
|
+
io.puts "Finished in #{Time.now - start} seconds." unless start.nil?
|
141
|
+
exceptions.each_with_index do |(o, e), i|
|
142
|
+
io.puts
|
143
|
+
if e.is_a? RuntimeError
|
144
|
+
failed += 1
|
145
|
+
io.puts "%3d) Failure" % [i + 1]
|
146
|
+
io.puts "#{e.message} " unless e.message.empty?
|
147
|
+
io.puts "with <#{o.inspect}>"
|
148
|
+
io.puts "[#{e.backtrace.first[/.+\d+/]}]"
|
149
|
+
else
|
150
|
+
erred += 1
|
151
|
+
io.puts "%3d) Error" % [i + 1]
|
152
|
+
io.puts "#{e.class.name}: #{e.message}"
|
153
|
+
io.puts "with <#{o.inspect}>"
|
154
|
+
io.puts e.backtrace.select { |l| l !~ /dots.rb/ }.map { |l| "\t#{l}" }
|
155
|
+
end
|
156
|
+
end
|
157
|
+
io.puts
|
158
|
+
io.puts summary(passed, failed, erred)
|
159
|
+
end
|
160
|
+
|
161
|
+
private
|
162
|
+
|
163
|
+
def summary(passed, failed, erred)
|
164
|
+
"%d total, %d passed, %d failed, %d erred" %
|
165
|
+
[passed + failed + erred, passed, failed, erred]
|
166
|
+
end
|
167
|
+
|
168
|
+
extend self
|
169
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# Require this file to add some red and green flair to your iterations.
|
2
|
+
|
3
|
+
Dots["."] = "\e[32m#{Dots["."]}\e[0m"
|
4
|
+
Dots["F"] = "\e[31m#{Dots["F"]}\e[0m"
|
5
|
+
Dots["E"] = "\e[31m#{Dots["E"]}\e[0m"
|
6
|
+
|
7
|
+
Dots.module_eval do
|
8
|
+
# Overrides Dots#summary with some red and green flair.
|
9
|
+
def summary(passed, failed, erred)
|
10
|
+
code = failed + erred == 0 ? "2" : "1"
|
11
|
+
"\e[3%dm%d total, %d passed, %d failed, %d erred\e[0m" %
|
12
|
+
[code, passed + failed + erred, passed, failed, erred]
|
13
|
+
end
|
14
|
+
end
|
data/spec/dots_spec.rb
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
require "spec/mocks"
|
2
|
+
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/../lib")
|
3
|
+
require "dots"
|
4
|
+
include Enumerable # To bring 1.8.7's Enumerator top-level.
|
5
|
+
|
6
|
+
def enumerator?
|
7
|
+
RUBY_VERSION >= "1.8.7"
|
8
|
+
end
|
9
|
+
|
10
|
+
describe Dots do
|
11
|
+
it 'should be configurable for "."' do
|
12
|
+
Dots["."].should == "."
|
13
|
+
proc { Dots["."] = ":)" }.should_not raise_error
|
14
|
+
Dots["."].should == ":)"
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should be configurable for "F"' do
|
18
|
+
Dots["F"].should == "F"
|
19
|
+
proc { Dots["F"] = ":|" }.should_not raise_error
|
20
|
+
Dots["F"].should == ":|"
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should be configurable for "E"' do
|
24
|
+
Dots["E"].should == "E"
|
25
|
+
proc { Dots["E"] = ":(" }.should_not raise_error
|
26
|
+
Dots["E"].should == ":("
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should not be configurable for anything else' do
|
30
|
+
proc { Dots["A"] }.should raise_error(Dots::InvalidDot)
|
31
|
+
proc { Dots["A"] = ":D" }.should raise_error(Dots::InvalidDot)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "Monkey-patched" do
|
36
|
+
describe "Enumerable.instance_methods" do
|
37
|
+
it do
|
38
|
+
Enumerable.instance_methods.should include("each_with_dots")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "Enumerator.instance_methods" do
|
43
|
+
it do
|
44
|
+
Enumerator.instance_methods.should include("with_dots")
|
45
|
+
end
|
46
|
+
end if enumerator?
|
47
|
+
|
48
|
+
describe "Kernel.methods" do
|
49
|
+
it do
|
50
|
+
Kernel.private_instance_methods.should include("dots")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "each_with_dots" do
|
56
|
+
before :each do
|
57
|
+
@enumerated = 1..5
|
58
|
+
@io = StringIO.new
|
59
|
+
@proc = Proc.new {}
|
60
|
+
end
|
61
|
+
|
62
|
+
after :each do
|
63
|
+
@enumerated.each_with_dots @io, &@proc
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should synchronize standard output" do
|
67
|
+
@io.should_receive(:sync=).twice
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'should receive print dots' do
|
71
|
+
Dots.should_receive(:[]).exactly(5).times.with "."
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should receive print Fs' do
|
75
|
+
@proc = Proc.new { |n| raise }
|
76
|
+
Dots.should_receive(:[]).exactly(5).times.with "F"
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should receive print Es' do
|
80
|
+
@proc = Proc.new { |n| n / 0 }
|
81
|
+
Dots.should_receive(:[]).exactly(5).times.with "E"
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should track the time" do
|
85
|
+
Time.should_receive :now
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'should receive "report"' do
|
89
|
+
Dots.should_receive :report
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe "each.with_dots" do
|
94
|
+
before :each do
|
95
|
+
@it = (1..5).each
|
96
|
+
end
|
97
|
+
|
98
|
+
it do
|
99
|
+
@it.with_dots.should be_an(Enumerator)
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'should receive "enum_for" with "each_with_dots"' do
|
103
|
+
@io = StringIO.new
|
104
|
+
@it.should_receive(:enum_for).with(:each_with_dots, @io).and_return @it
|
105
|
+
@it.with_dots(@io) {}.should == (1..5)
|
106
|
+
end
|
107
|
+
end if enumerator?
|
108
|
+
|
109
|
+
describe "with_dots" do
|
110
|
+
it "should print dots" do
|
111
|
+
Dots.should_receive(:[]).with "."
|
112
|
+
dots(1, StringIO.new) {}
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should require a block" do
|
116
|
+
proc { dots }.should raise_error(LocalJumpError)
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should synchronize standard output" do
|
120
|
+
io = StringIO.new
|
121
|
+
io.should_receive(:sync=).twice
|
122
|
+
dots(1, io) {}
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should spin up and kill a thread" do
|
126
|
+
thread = mock "thread"
|
127
|
+
Thread.should_receive(:new).and_return thread
|
128
|
+
thread.should_receive :kill
|
129
|
+
dots(1, StringIO.new) {}
|
130
|
+
end
|
131
|
+
end
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dots
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Stephen Celis
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-05-10 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Free progress dots for your scripts.
|
17
|
+
email:
|
18
|
+
- stephen@stephencelis.com
|
19
|
+
executables: []
|
20
|
+
|
21
|
+
extensions: []
|
22
|
+
|
23
|
+
extra_rdoc_files:
|
24
|
+
- History.rdoc
|
25
|
+
- Manifest.txt
|
26
|
+
- README.rdoc
|
27
|
+
files:
|
28
|
+
- History.rdoc
|
29
|
+
- Manifest.txt
|
30
|
+
- Rakefile
|
31
|
+
- README.rdoc
|
32
|
+
- cucumber.yml
|
33
|
+
- dots.gemspec
|
34
|
+
- features/dots.feature
|
35
|
+
- features/step_definitions/dots_steps.rb
|
36
|
+
- features/support/env.rb
|
37
|
+
- lib/dots/kaoemoji.rb
|
38
|
+
- lib/dots/rainbows.rb
|
39
|
+
- lib/dots/redgreen.rb
|
40
|
+
- lib/dots.rb
|
41
|
+
- spec/dots_spec.rb
|
42
|
+
has_rdoc: true
|
43
|
+
homepage: http://github.com/stephencelis/dots
|
44
|
+
licenses: []
|
45
|
+
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options:
|
48
|
+
- --main
|
49
|
+
- README.rdoc
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
version:
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: "0"
|
63
|
+
version:
|
64
|
+
requirements: []
|
65
|
+
|
66
|
+
rubyforge_project: dots
|
67
|
+
rubygems_version: 1.3.5
|
68
|
+
signing_key:
|
69
|
+
specification_version: 3
|
70
|
+
summary: Free progress dots for your scripts
|
71
|
+
test_files: []
|
72
|
+
|