zonebie 0.0.2 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +3 -0
- data/README.md +54 -0
- data/lib/zonebie.rb +6 -2
- data/lib/zonebie/extras.rb +1 -0
- data/lib/zonebie/extras/ascii_map.rb +72 -0
- data/lib/zonebie/version.rb +1 -1
- data/spec/fixtures/ascii_map.png +0 -0
- data/spec/lib/zonebie/extras/ascii_map_spec.rb +42 -0
- data/spec/lib/zonebie_spec.rb +7 -0
- data/zonebie.gemspec +3 -0
- metadata +38 -4
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -100,6 +100,60 @@ seems present in one zone), set the `TZ` environment variable:
|
|
100
100
|
TZ="Eastern Time (US & Canada)" rake
|
101
101
|
```
|
102
102
|
|
103
|
+
## For the Geographically Impaired
|
104
|
+
|
105
|
+
Zonebie can generate an ASCII map that shows where on the globe your tests are
|
106
|
+
running.
|
107
|
+
|
108
|
+
Note that this makes a request to Google Maps, so it's likely not a good idea
|
109
|
+
to run on each test run :)
|
110
|
+
|
111
|
+
```
|
112
|
+
..... ......
|
113
|
+
..... ........... .
|
114
|
+
. . .. ........... . .
|
115
|
+
. .. .. ........... . ..
|
116
|
+
.. .. . ........ . .......
|
117
|
+
..... .... . ... ....... .. . . ...................
|
118
|
+
............ ........ ... ... .. ..... ...............................
|
119
|
+
... ......... . .. ..... ............................ .
|
120
|
+
........... ... . .. ..................... ......
|
121
|
+
............. ........ .. ...................
|
122
|
+
........... .. . ..... ............... .
|
123
|
+
... . .............. ................
|
124
|
+
... ............. .. .. ... .
|
125
|
+
..... .. .......... . .
|
126
|
+
.......... ...... .
|
127
|
+
....... ..... . .....
|
128
|
+
..... ... .........
|
129
|
+
.... ..
|
130
|
+
..
|
131
|
+
.
|
132
|
+
|
133
|
+
.
|
134
|
+
.. .......... ...................
|
135
|
+
. .... .... ..........................................
|
136
|
+
............... . ............................................
|
137
|
+
.................. . .............................................
|
138
|
+
..................... .............................................
|
139
|
+
.........................................................................
|
140
|
+
...........................................................................
|
141
|
+
```
|
142
|
+
|
143
|
+
Enable the map by setting the `:ascii_map` option to `true`. Again, because it
|
144
|
+
makes an HTTP request, you likely only want to enable it in certain
|
145
|
+
circumstances (e.g., on a CI server or when you explicitly request it):
|
146
|
+
|
147
|
+
```ruby
|
148
|
+
Zonebie.set_random_timezone(:ascii_map => ENV['CI'] || ENV['MAP'])
|
149
|
+
```
|
150
|
+
|
151
|
+
And run with:
|
152
|
+
|
153
|
+
```ruby
|
154
|
+
MAP=1 rake
|
155
|
+
```
|
156
|
+
|
103
157
|
## Contributing
|
104
158
|
|
105
159
|
1. Fork it
|
data/lib/zonebie.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require File.expand_path("zonebie/version", File.dirname(__FILE__))
|
2
|
+
require File.expand_path("zonebie/extras", File.dirname(__FILE__))
|
2
3
|
|
3
4
|
module Zonebie
|
4
5
|
class << self
|
@@ -36,10 +37,13 @@ module Zonebie
|
|
36
37
|
@backends[backend.name] = backend
|
37
38
|
end
|
38
39
|
|
39
|
-
def set_random_timezone
|
40
|
+
def set_random_timezone(options = {})
|
40
41
|
zone = ENV['TZ'] || random_timezone
|
41
42
|
|
42
|
-
|
43
|
+
unless quiet
|
44
|
+
$stdout.puts("[Zonebie] Setting timezone to \"#{zone}\"")
|
45
|
+
$stdout.puts(Zonebie::Extras::AsciiMap.new(zone).to_s) if options[:ascii_map]
|
46
|
+
end
|
43
47
|
backend.zone = zone
|
44
48
|
end
|
45
49
|
|
@@ -0,0 +1 @@
|
|
1
|
+
require File.expand_path("extras/ascii_map", File.dirname(__FILE__))
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'open-uri'
|
3
|
+
require 'chunky_png'
|
4
|
+
require 'rainbow'
|
5
|
+
|
6
|
+
Sickill::Rainbow.enabled = true
|
7
|
+
|
8
|
+
module Zonebie
|
9
|
+
module Extras
|
10
|
+
class AsciiMap
|
11
|
+
attr_accessor :zone, :image, :ascii, :mark
|
12
|
+
|
13
|
+
def initialize(zone)
|
14
|
+
self.zone = zone
|
15
|
+
self.mark = false
|
16
|
+
self.ascii = map_to_ascii
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_s
|
20
|
+
ascii
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def disable_webmock
|
26
|
+
if defined? WebMock
|
27
|
+
allow_net_connect_was = WebMock::Config.instance.allow_net_connect
|
28
|
+
WebMock::Config.instance.allow_net_connect = true
|
29
|
+
yield
|
30
|
+
WebMock::Config.instance.allow_net_connect = allow_net_connect_was
|
31
|
+
else
|
32
|
+
yield
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def google_maps_request
|
37
|
+
"http://maps.googleapis.com/maps/api/staticmap?format=png8&zoom=1&maptype=roadmap&sensor=false¢er=0,0&size=500x500&markers=size:large%7Ccolor:red%7C#{URI.encode(zone)}&style=feature:all%7Celement:labels%7Cvisibility:off&style=feature:all%7Celement:geometry%7Clightness:100&style=feature:water%7Celement:geometry%7Clightness:-100"
|
38
|
+
end
|
39
|
+
|
40
|
+
def map_to_ascii
|
41
|
+
image = nil
|
42
|
+
|
43
|
+
disable_webmock do
|
44
|
+
open google_maps_request do |f|
|
45
|
+
image = ChunkyPNG::Image.from_blob(f.read)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
image.resample_nearest_neighbor!(80, 30)
|
50
|
+
dots = image.pixels.map{ |p| colored_dot(p) }
|
51
|
+
dots.each_slice(80).map{ |d| d.join }.join("\n")
|
52
|
+
end
|
53
|
+
|
54
|
+
def colored_dot(color)
|
55
|
+
if ChunkyPNG::Color.grayscale? color
|
56
|
+
if ChunkyPNG::Color.r(color) > (255 / 2)
|
57
|
+
'.'
|
58
|
+
else
|
59
|
+
' '
|
60
|
+
end
|
61
|
+
else
|
62
|
+
if mark
|
63
|
+
'.'
|
64
|
+
else
|
65
|
+
self.mark = true
|
66
|
+
'X'.color(:red)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
data/lib/zonebie/version.rb
CHANGED
Binary file
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Zonebie::Extras::AsciiMap do
|
4
|
+
describe "#to_s" do
|
5
|
+
it "prints a map of the world" do
|
6
|
+
map = File.open(File.expand_path('../../../fixtures/ascii_map.png', File.dirname(__FILE__)))
|
7
|
+
Zonebie::Extras::AsciiMap.any_instance.expects(:open).yields(map)
|
8
|
+
|
9
|
+
Zonebie::Extras::AsciiMap.new('International Date Line West').to_s.should ==
|
10
|
+
%{
|
11
|
+
..... ......
|
12
|
+
..... ........... .
|
13
|
+
. . .. ........... . .
|
14
|
+
. .. .. ........... . ..
|
15
|
+
.. .. . ........ . .......
|
16
|
+
..... .... . ... ....... .. . . ...................
|
17
|
+
............ ........ ... ... .. ..... ...............................
|
18
|
+
... ......... . .. ..... ............................ .
|
19
|
+
........... \e[31mX\e[0m.. . .. ..................... ......
|
20
|
+
............ ........ .. ...................
|
21
|
+
........... .. . ..... ............... .
|
22
|
+
... . .............. ................
|
23
|
+
... ............. .. .. ... .
|
24
|
+
..... .. .......... . .
|
25
|
+
.......... ...... .
|
26
|
+
....... ..... . .....
|
27
|
+
..... ... .........
|
28
|
+
.... ..
|
29
|
+
..
|
30
|
+
.
|
31
|
+
|
32
|
+
.
|
33
|
+
.. .......... ...................
|
34
|
+
. .... .... ..........................................
|
35
|
+
............... . ............................................
|
36
|
+
.................. . .............................................
|
37
|
+
..................... .............................................
|
38
|
+
.........................................................................
|
39
|
+
...........................................................................}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/spec/lib/zonebie_spec.rb
CHANGED
@@ -58,6 +58,13 @@ describe Zonebie do
|
|
58
58
|
Zonebie.set_random_timezone
|
59
59
|
end
|
60
60
|
|
61
|
+
it "outputs the ascii map to STDOUT if the option is present" do
|
62
|
+
Zonebie::Extras::AsciiMap.any_instance.stubs(:to_s).returns('ascii map')
|
63
|
+
$stdout.expects(:puts).with("[Zonebie] Setting timezone to \"Eastern Time (US & Canada)\"")
|
64
|
+
$stdout.expects(:puts).with('ascii map')
|
65
|
+
Zonebie.set_random_timezone(:ascii_map => true)
|
66
|
+
end
|
67
|
+
|
61
68
|
it "does not output the timezone to STDOUT if quiet mode is enabled" do
|
62
69
|
$stdout.expects(:puts).never
|
63
70
|
|
data/zonebie.gemspec
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zonebie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Andy Lindeman
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-03-
|
18
|
+
date: 2012-03-20 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
prerelease: false
|
@@ -92,6 +92,34 @@ dependencies:
|
|
92
92
|
requirement: *id005
|
93
93
|
type: :development
|
94
94
|
name: tzinfo
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
prerelease: false
|
97
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
hash: 3
|
103
|
+
segments:
|
104
|
+
- 0
|
105
|
+
version: "0"
|
106
|
+
requirement: *id006
|
107
|
+
type: :runtime
|
108
|
+
name: chunky_png
|
109
|
+
- !ruby/object:Gem::Dependency
|
110
|
+
prerelease: false
|
111
|
+
version_requirements: &id007 !ruby/object:Gem::Requirement
|
112
|
+
none: false
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
hash: 3
|
117
|
+
segments:
|
118
|
+
- 0
|
119
|
+
version: "0"
|
120
|
+
requirement: *id007
|
121
|
+
type: :runtime
|
122
|
+
name: rainbow
|
95
123
|
description: Runs your tests in a random timezone
|
96
124
|
email:
|
97
125
|
- alindeman@gmail.com
|
@@ -112,11 +140,15 @@ files:
|
|
112
140
|
- lib/zonebie/backends.rb
|
113
141
|
- lib/zonebie/backends/active_support.rb
|
114
142
|
- lib/zonebie/backends/tzinfo.rb
|
143
|
+
- lib/zonebie/extras.rb
|
144
|
+
- lib/zonebie/extras/ascii_map.rb
|
115
145
|
- lib/zonebie/rspec.rb
|
116
146
|
- lib/zonebie/version.rb
|
147
|
+
- spec/fixtures/ascii_map.png
|
117
148
|
- spec/integrations/activesupport_spec.rb
|
118
149
|
- spec/lib/zonebie/backends/active_support_spec.rb
|
119
150
|
- spec/lib/zonebie/backends/tzinfo_spec.rb
|
151
|
+
- spec/lib/zonebie/extras/ascii_map_spec.rb
|
120
152
|
- spec/lib/zonebie_spec.rb
|
121
153
|
- spec/spec_helper.rb
|
122
154
|
- zonebie.gemspec
|
@@ -154,8 +186,10 @@ signing_key:
|
|
154
186
|
specification_version: 3
|
155
187
|
summary: Zonebie prevents bugs in code that deals with timezones by randomly assigning a zone on every run
|
156
188
|
test_files:
|
189
|
+
- spec/fixtures/ascii_map.png
|
157
190
|
- spec/integrations/activesupport_spec.rb
|
158
191
|
- spec/lib/zonebie/backends/active_support_spec.rb
|
159
192
|
- spec/lib/zonebie/backends/tzinfo_spec.rb
|
193
|
+
- spec/lib/zonebie/extras/ascii_map_spec.rb
|
160
194
|
- spec/lib/zonebie_spec.rb
|
161
195
|
- spec/spec_helper.rb
|