Skip to content
This repository has been archived by the owner on Dec 17, 2021. It is now read-only.

Commit

Permalink
Registry: an API for shared state in cucumber steps
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephen Caudill committed Jan 27, 2011
1 parent 4704247 commit 90f79e8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
14 changes: 14 additions & 0 deletions features/support/registry.rb
@@ -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
23 changes: 23 additions & 0 deletions spec/features/support/registry_spec.rb
@@ -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

0 comments on commit 90f79e8

Please sign in to comment.