Skip to content

Commit

Permalink
add reset! and improve errors when no label set
Browse files Browse the repository at this point in the history
  • Loading branch information
phoet committed Sep 23, 2012
1 parent df61de4 commit 4a6f2e9
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .rspec
@@ -1,2 +1,2 @@
--color
--format progress
--format documentation
2 changes: 1 addition & 1 deletion .travis.yml
@@ -1,4 +1,4 @@
script: "bundle exec rake"
script: "bundle exec rspec"
rvm:
- 1.8.7
- 1.9.2
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
whitelabel (0.1.0)
whitelabel (0.2.0)

GEM
remote: https://rubygems.org/
Expand Down
5 changes: 5 additions & 0 deletions lib/whitelabel.rb
Expand Up @@ -37,7 +37,12 @@ def with_label(tmp=nil)
end

def [](accessor)
raise "set a label before calling '#{accessor}'" if self.label.nil?
self.label.send :"#{accessor}"
end

def reset!
Thread.current[:whitelabel] = nil
end
end
end
2 changes: 1 addition & 1 deletion lib/whitelabel/version.rb
@@ -1,3 +1,3 @@
module Whitelabel
VERSION = "0.1.1"
VERSION = "0.2.0"
end
22 changes: 19 additions & 3 deletions spec/lib/whitelabel_spec.rb
Expand Up @@ -3,9 +3,11 @@

describe Whitelabel do
let(:path) { fixture_path("whitelabel.yml") }
let(:dummy) { Dummy.new('some_id', 'some_name') }

before(:each) do
Whitelabel.labels = []
Whitelabel.reset!
end

context "initialization" do
Expand Down Expand Up @@ -50,13 +52,27 @@
Whitelabel.label.should eql(label)
end

it "should throw a meaningfull error when no label is set" do
expect { Whitelabel[:blame] }.to raise_error("set a label before calling 'blame'")
end

context "with current label" do
before(:each) do
Whitelabel.label = Dummy.new('some_id', 'some_name')
Whitelabel.label = dummy
end

context "resetting" do
it "should reset the current label" do
Whitelabel.label.should be(dummy)
Whitelabel.reset!
Whitelabel.label.should be_nil
end
end

it "should access a label property via []" do
Whitelabel[:name].should eql('some_name')
context "accessing values" do
it "should access a label property via []" do
Whitelabel[:name].should eql('some_name')
end
end
end
end
Expand Down

0 comments on commit 4a6f2e9

Please sign in to comment.