Skip to content

Commit

Permalink
Adds quiet mode; removes helpers that would not have worked with quie…
Browse files Browse the repository at this point in the history
…t mode
  • Loading branch information
alindeman committed Mar 5, 2012
1 parent cecad9f commit c4c8873
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 14 deletions.
20 changes: 13 additions & 7 deletions README.md
Expand Up @@ -31,28 +31,34 @@ If using Bundler (recommended), add to Gemfile:


Add to `test/test_helper.rb`: Add to `test/test_helper.rb`:


require "zonebie/test_unit" Zonebie.set_random_timezone


### RSpec ### RSpec


Add to `spec/spec_helper.rb` after `require "rspec"` or `require "rspec/rails"`: Add to `spec/spec_helper.rb` after `require "rspec"` or `require
"rspec/rails"`:


require "zonebie/rspec" require "zonebie/rspec"


### Cucumber ### Cucumber


Add to `features/support/env.rb` after `require "cucumber"` or `require "cucumber/rails"`: Add a file `features/support/zonebie.rb` with the following contents:


require "zonebie/cucumber" Zonebie.set_random_timezone


## Usage ## Usage


When `Zonebie.assign_random_timezone` is called (if using RSpec or Cucumber, When `Zonebie.set_random_timezone` is called (if using RSpec, this call is
this call is automatically setup for you), 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)"


If you would rather that Zonebie not print out this information during your tests,
put Zonebie in quiet mode before calling `set_random_timezone`:

Zonebie.quiet = true

To rerun tests with a specific timezone (e.g., to reproduce a bug that only To rerun tests with a specific timezone (e.g., to reproduce a bug that only
seems present in one zone), set the `TZ` environment variable: seems present in one zone), set the `TZ` environment variable:


Expand Down
4 changes: 3 additions & 1 deletion lib/zonebie.rb
Expand Up @@ -2,6 +2,8 @@


module Zonebie module Zonebie
class << self class << self
attr_accessor :quiet

def backend def backend
unless @backend unless @backend
self.backend = :activesupport self.backend = :activesupport
Expand Down Expand Up @@ -34,7 +36,7 @@ def set_random_timezone
zones = backend.zones zones = backend.zones
zone = zones[rand(zones.length)] zone = zones[rand(zones.length)]


$stdout.puts("[Zonebie] Setting timezone to \"#{zone}\"") $stdout.puts("[Zonebie] Setting timezone to \"#{zone}\"") unless quiet
@backend.zone = zones[rand(zones.length)] @backend.zone = zones[rand(zones.length)]
end end
end end
Expand Down
3 changes: 0 additions & 3 deletions lib/zonebie/cucumber.rb

This file was deleted.

3 changes: 0 additions & 3 deletions lib/zonebie/test_unit.rb

This file was deleted.

12 changes: 12 additions & 0 deletions spec/lib/zonebie_spec.rb
Expand Up @@ -43,5 +43,17 @@
backend.expects(:zone=).with("Eastern Time (US & Canada)") backend.expects(:zone=).with("Eastern Time (US & Canada)")
Zonebie.set_random_timezone Zonebie.set_random_timezone
end end

it "outputs the timezone to STDOUT" do
$stdout.expects(:puts).with("[Zonebie] Setting timezone to \"Eastern Time (US & Canada)\"")
Zonebie.set_random_timezone
end

it "does not output the timezone to STDOUT if quiet mode is enabled" do
$stdout.expects(:puts).never

Zonebie.quiet = true
Zonebie.set_random_timezone
end
end end
end end

0 comments on commit c4c8873

Please sign in to comment.