Skip to content

Commit

Permalink
Zonebie can cough up a random timezone too
Browse files Browse the repository at this point in the history
  • Loading branch information
alindeman committed Mar 5, 2012
1 parent 69c2914 commit 0abf8c3
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
26 changes: 15 additions & 11 deletions README.md
Expand Up @@ -13,20 +13,16 @@ Tests must run green against:
* JRuby 1.6 (1.8 and 1.9 mode) * JRuby 1.6 (1.8 and 1.9 mode)
* Rubinius 1.2 and 2.0 (1.8 and 1.9 mode) * Rubinius 1.2 and 2.0 (1.8 and 1.9 mode)


A gem that adds timezone support; currently supported is:

* `activesupport` >= 2.3 (compatible with Rails 2.3, 3.0, 3.1, 3.2) * `activesupport` >= 2.3 (compatible with Rails 2.3, 3.0, 3.1, 3.2)


OR

* **Unimplemented** `tzinfo`

## Installation ## Installation


If using Bundler (recommended), add to Gemfile: If using Bundler (recommended), add to Gemfile:


gem 'zonebie' gem 'zonebie'


## Usage with Rails & ActiveSupport

### Test::Unit & Minitest ### Test::Unit & Minitest


Add to `test/test_helper.rb`: Add to `test/test_helper.rb`:
Expand All @@ -38,19 +34,27 @@ Add to `test/test_helper.rb`:
Add to `spec/spec_helper.rb` after `require "rspec"` or `require Add to `spec/spec_helper.rb` after `require "rspec"` or `require
"rspec/rails"`: "rspec/rails"`:


require "zonebie/rspec" Zonebie.set_random_timezone


### Cucumber ### Cucumber


Add a file `features/support/zonebie.rb` with the following contents: Add a file `features/support/zonebie.rb` with the following contents:


Zonebie.set_random_timezone Zonebie.set_random_timezone


## Usage ## Other Usage

If you simply need a random timezone for some other part of your tests,
Zonebie can help as well.

# e.g. with Rails
zone = ActiveSupport::TimeZone[Zonebie.random_timezone]
puts zone.now

## Reproducing Bugs


When `Zonebie.set_random_timezone` is called (if using RSpec, this call is When `Zonebie.set_random_timezone` is called, Zonebie assigns a timezone and
automatically setup for you), Zonebie assigns a timezone and prints a message prints a message to STDOUT:
to STDOUT:


[Zonebie] Setting timezone to "Eastern Time (US & Canada)" [Zonebie] Setting timezone to "Eastern Time (US & Canada)"


Expand Down
10 changes: 7 additions & 3 deletions lib/zonebie.rb
Expand Up @@ -33,11 +33,15 @@ def add_backend(backend)
end end


def set_random_timezone def set_random_timezone
zones = backend.zones zone = random_timezone
zone = zones[rand(zones.length)]


$stdout.puts("[Zonebie] Setting timezone to \"#{zone}\"") unless quiet $stdout.puts("[Zonebie] Setting timezone to \"#{zone}\"") unless quiet
@backend.zone = zones[rand(zones.length)] @backend.zone = zone
end

def random_timezone
zones = backend.zones
zones[rand(zones.length)]
end end
end end
end end
Expand Down
16 changes: 16 additions & 0 deletions spec/lib/zonebie_spec.rb
Expand Up @@ -62,4 +62,20 @@
end end
end end
end end

describe "#random_timezone" do
let(:backend) {
stub_everything(:name => :my_awesome_backend,
:zones => ["Eastern Time (US & Canada)"])
}

before do
Zonebie.add_backend(backend)
Zonebie.backend = :my_awesome_backend
end

it "returns a random timezone" do
Zonebie.random_timezone.should == "Eastern Time (US & Canada)"
end
end
end end

0 comments on commit 0abf8c3

Please sign in to comment.