summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLes Hill and Robert Pitts <dev+leshill+rbxbx@hashrocket.com>2010-08-06 22:51:38 +0800
committerMichael Bleigh <michael@intridea.com>2010-08-10 22:57:12 +0800
commitf3a76923b259be19db0a7ed5a68ed45ac05f00d0 (patch)
treeb8fd134fc93f7f48795de69f4b89f719e2ace4fa
parent54b03e8aca856a924b718e826d6bffec4c54148e (diff)
downloadhashie-f3a76923b259be19db0a7ed5a68ed45ac05f00d0.tar.gz
Cleanup
-rw-r--r--lib/hashie/dash.rb8
-rw-r--r--spec/hashie/dash_spec.rb35
2 files changed, 21 insertions, 22 deletions
diff --git a/lib/hashie/dash.rb b/lib/hashie/dash.rb
index 6d4e6b5..3a149ae 100644
--- a/lib/hashie/dash.rb
+++ b/lib/hashie/dash.rb
@@ -44,7 +44,7 @@ module Hashie
# properties on this Dash.
def self.properties
properties = []
- ancestors.each do |elder|
+ ancestors.each do |elder|
if elder.instance_variable_defined?("@properties")
properties << elder.instance_variable_get("@properties")
end
@@ -67,7 +67,7 @@ module Hashie
properties.merge! elder.instance_variable_get("@defaults")
end
end
-
+
properties
end
@@ -94,8 +94,8 @@ module Hashie
def []=(property, value)
super if property_exists? property
end
-
- private
+
+ private
# Raises an NoMethodError if the property doesn't exist
#
def property_exists?(property)
diff --git a/spec/hashie/dash_spec.rb b/spec/hashie/dash_spec.rb
index 432e357..a3aba1d 100644
--- a/spec/hashie/dash_spec.rb
+++ b/spec/hashie/dash_spec.rb
@@ -14,68 +14,67 @@ describe Hashie::Dash do
it 'should be a subclass of Hashie::Hash' do
(Hashie::Dash < Hash).should be_true
end
-
+
it '#inspect should be ok!' do
dash = DashTest.new
dash.email = "abd@abc.com"
dash.inspect.should == "<#DashTest count=0 email=\"abd@abc.com\" first_name=nil>"
end
-
+
describe ' creating properties' do
it 'should add the property to the list' do
DashTest.property :not_an_att
DashTest.properties.include?('not_an_att').should be_true
end
-
+
it 'should create a method for reading the property' do
DashTest.new.respond_to?(:first_name).should be_true
end
-
+
it 'should create a method for writing the property' do
DashTest.new.respond_to?(:first_name=).should be_true
end
end
-
+
describe 'reading properties' do
- it 'should raise an error when reading a non-existent property' do
+ it 'should raise an error when reading a non-existent property' do
lambda{@dash['abc']}.should raise_error(NoMethodError)
end
end
-
+
describe ' writing to properties' do
before do
@dash = DashTest.new
end
-
+
it 'should not be able to write to a non-existent property using []=' do
lambda{@dash['abc'] = 123}.should raise_error(NoMethodError)
end
-
+
it 'should be able to write to an existing property using []=' do
lambda{@dash['first_name'] = 'Bob'}.should_not raise_error
end
-
+
it 'should be able to read/write to an existing property using a method call' do
@dash.first_name = 'Franklin'
@dash.first_name.should == 'Franklin'
end
end
-
+
describe ' initializing with a Hash' do
it 'should not be able to initialize non-existent properties' do
lambda{DashTest.new(:bork => 'abc')}.should raise_error(NoMethodError)
end
-
+
it 'should set properties that it is able to' do
DashTest.new(:first_name => 'Michael').first_name.should == 'Michael'
end
end
-
describe ' defaults' do
before do
@dash = DashTest.new
end
-
+
it 'should return the default value for defaulted' do
DashTest.property :defaulted, :default => 'abc'
DashTest.new.defaulted.should == 'abc'
@@ -87,17 +86,17 @@ describe Subclassed do
it "should inherit all properties from DashTest" do
Subclassed.properties.size.should == 6
end
-
+
it "should inherit all defaults from DashTest" do
Subclassed.defaults.size.should == 6
end
-
+
it "should init without raising" do
lambda { Subclassed.new }.should_not raise_error
lambda { Subclassed.new(:first_name => 'Michael') }.should_not raise_error
end
-
+
it "should share defaults from DashTest" do
Subclassed.new.count.should == 0
end
-end \ No newline at end of file
+end