diff options
author | Michael Bleigh <michael@intridea.com> | 2010-07-28 20:02:12 -0500 |
---|---|---|
committer | Michael Bleigh <michael@intridea.com> | 2010-07-28 20:02:12 -0500 |
commit | 97135789e63644140599b353beee8f9f1084cfe0 (patch) | |
tree | a6f4e1acd0e46bf5b859abed9732c89f502485a0 | |
parent | ec359f4bd9f975d4c7add2d67e3f3095a2eaa07c (diff) | |
download | hashie-97135789e63644140599b353beee8f9f1084cfe0.tar.gz |
Changed up spec_helper a bit, added respond_to? on Mash
-rw-r--r-- | Gemfile | 3 | ||||
-rw-r--r-- | Gemfile.lock | 49 | ||||
-rw-r--r-- | lib/hashie/mash.rb | 8 | ||||
-rw-r--r-- | spec/hashie/clash_spec.rb | 2 | ||||
-rw-r--r-- | spec/hashie/dash_spec.rb | 2 | ||||
-rw-r--r-- | spec/hashie/hash_spec.rb | 2 | ||||
-rw-r--r-- | spec/hashie/mash_spec.rb | 12 |
7 files changed, 47 insertions, 31 deletions
@@ -1,9 +1,10 @@ # A sample Gemfile -source :gemcutter +source 'http://rubygems.org' group :development do gem 'rake' gem 'json' + gem 'jeweler' end group :test do diff --git a/Gemfile.lock b/Gemfile.lock index 36cc596..115aad2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,25 +1,24 @@ ---- -dependencies: - rake: - group: - - :development - version: ">= 0" - rspec: - group: - - :test - version: ">= 0" - json: - group: - - :development - version: ">= 0" -specs: -- rake: - version: 0.8.7 -- json: - version: 1.4.3 -- rspec: - version: 1.3.0 -hash: d9c314ac1790a9ac25dfdaf7574b86d62b88f1d5 -sources: -- Rubygems: - uri: http://gemcutter.org +GEM + remote: http://rubygems.org/ + specs: + gemcutter (0.6.1) + git (1.2.5) + jeweler (1.4.0) + gemcutter (>= 0.1.0) + git (>= 1.2.5) + rubyforge (>= 2.0.0) + json (1.4.3) + json_pure (1.4.3) + rake (0.8.7) + rspec (1.3.0) + rubyforge (2.0.4) + json_pure (>= 1.1.7) + +PLATFORMS + ruby + +DEPENDENCIES + jeweler + json + rake + rspec diff --git a/lib/hashie/mash.rb b/lib/hashie/mash.rb index 4a196d6..7904202 100644 --- a/lib/hashie/mash.rb +++ b/lib/hashie/mash.rb @@ -111,7 +111,13 @@ module Hashie alias_method :update, :deep_update alias_method :merge!, :update - + # Will return true if the Mash has had a key + # set in addition to normal respond_to? functionality. + def respond_to?(method_name) + return true if key?(method_name) + super + end + def method_missing(method_name, *args, &blk) return self[method_name] if key?(method_name) match = method_name.to_s.match(/(.*?)([?=!]?)$/) diff --git a/spec/hashie/clash_spec.rb b/spec/hashie/clash_spec.rb index 6363d5d..6797a4a 100644 --- a/spec/hashie/clash_spec.rb +++ b/spec/hashie/clash_spec.rb @@ -1,4 +1,4 @@ -require File.dirname(__FILE__) + '/../spec_helper' +require 'spec_helper' describe Hashie::Clash do before do diff --git a/spec/hashie/dash_spec.rb b/spec/hashie/dash_spec.rb index b7971f9..432e357 100644 --- a/spec/hashie/dash_spec.rb +++ b/spec/hashie/dash_spec.rb @@ -1,4 +1,4 @@ -require File.dirname(__FILE__) + '/../spec_helper' +require 'spec_helper' class DashTest < Hashie::Dash property :first_name diff --git a/spec/hashie/hash_spec.rb b/spec/hashie/hash_spec.rb index 78d44be..30571d2 100644 --- a/spec/hashie/hash_spec.rb +++ b/spec/hashie/hash_spec.rb @@ -1,4 +1,4 @@ -require File.dirname(__FILE__) + '/../spec_helper' +require 'spec_helper' describe Hash do it "should be convertible to a Hashie::Mash" do diff --git a/spec/hashie/mash_spec.rb b/spec/hashie/mash_spec.rb index 70d1f6f..64b30ef 100644 --- a/spec/hashie/mash_spec.rb +++ b/spec/hashie/mash_spec.rb @@ -1,4 +1,4 @@ -require File.dirname(__FILE__) + '/../spec_helper' +require 'spec_helper' describe Hashie::Mash do before(:each) do @@ -82,6 +82,16 @@ describe Hashie::Mash do record.son = MyMash.new record.son.class.should == MyMash end + + describe '#respond_to?' do + it 'should respond to a normal method' do + Hashie::Mash.new.should be_respond_to(:key?) + end + + it 'should respond to a set key' do + Hashie::Mash.new(:abc => 'def').should be_respond_to(:abc) + end + end context "#initialize" do it "should convert an existing hash to a Hashie::Mash" do |