This repository has been archived by the owner on Dec 17, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Registry: an API for shared state in cucumber steps
- Loading branch information
Stephen Caudill
committed
Jan 27, 2011
1 parent
4704247
commit 90f79e8
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class Registry | ||
def self.[](key) | ||
registry[key] | ||
end | ||
|
||
def self.[]=(key,value) | ||
registry[key] = value | ||
end | ||
|
||
private | ||
def self.registry | ||
@registry ||= {} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper') | ||
require File.join(File.dirname(__FILE__), '..', '..', '..', 'features', 'support', 'registry') | ||
|
||
describe Registry do | ||
describe ".[]" do | ||
subject { Registry[arg] } | ||
context "when there is an associated key" do | ||
let(:arg) { 'foo' } | ||
before{ Registry.instance_variable_set('@registry', { 'foo' => 'bar' }) } | ||
it { should == 'bar' } | ||
end | ||
context "when there is no associated key" do | ||
let(:arg) { 'bar' } | ||
it { should be_nil } | ||
end | ||
end | ||
|
||
describe ".[]=" do | ||
subject{ Registry['foo'] } | ||
before { Registry['foo'] = 'bar' } | ||
it { should == 'bar' } | ||
end | ||
end |