Permalink
Browse files

Adds quiet mode; removes helpers that would not have worked with quie…

…t mode
  • Loading branch information...
1 parent cecad9f commit c4c8873e195da85188ab8651397969583dfdf666 @alindeman alindeman committed Mar 5, 2012
Showing with 28 additions and 14 deletions.
  1. +13 −7 README.md
  2. +3 −1 lib/zonebie.rb
  3. +0 −3 lib/zonebie/cucumber.rb
  4. +0 −3 lib/zonebie/test_unit.rb
  5. +12 −0 spec/lib/zonebie_spec.rb
View
@@ -31,28 +31,34 @@ If using Bundler (recommended), add to Gemfile:
Add to `test/test_helper.rb`:
- require "zonebie/test_unit"
+ Zonebie.set_random_timezone
### 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"
### 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
-When `Zonebie.assign_random_timezone` is called (if using RSpec or Cucumber,
-this call is automatically setup for you), Zonebie assigns a timezone and
-prints a message to STDOUT:
+When `Zonebie.set_random_timezone` is called (if using RSpec, this call is
+automatically setup for you), Zonebie assigns a timezone and prints a message
+to STDOUT:
[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
seems present in one zone), set the `TZ` environment variable:
View
@@ -2,6 +2,8 @@
module Zonebie
class << self
+ attr_accessor :quiet
+
def backend
unless @backend
self.backend = :activesupport
@@ -34,7 +36,7 @@ def set_random_timezone
zones = backend.zones
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)]
end
end
View
@@ -1,3 +0,0 @@
-require File.expand_path("../zonebie", File.dirname(__FILE__))
-
-Zonebie.set_random_timezone
View
@@ -1,3 +0,0 @@
-require File.expand_path("../zonebie", File.dirname(__FILE__))
-
-Zonebie.set_random_timezone
View
@@ -43,5 +43,17 @@
backend.expects(:zone=).with("Eastern Time (US & Canada)")
Zonebie.set_random_timezone
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

0 comments on commit c4c8873

Please sign in to comment.