spec/depth/enumerable_spec.rb in depth-0.0.2 vs spec/depth/enumerable_spec.rb in depth-0.1.0

- old
+ new

@@ -35,9 +35,35 @@ expected = ['something', '#weather', 'thing', '#otherfeed', '$or', '$and'] expect(keys).to eq expected end end + describe '#select' do + let(:hash) do + { 'x' => 1, '$c' => 2, 'v' => { '$x' => :a }, '$f' => { 'a' => 3, '$l' => 4 }} + end + it 'keeps only that which you desire' do + onlydollars = subject.select do |key, fragment| + key =~ /^\$/ + end + expected = {"$c"=>2, "$f"=>{'$l'=>4}} + expect(onlydollars.base).to eq expected + end + end + + describe '#reject' do + let(:hash) do + { 'x' => 1, '$c' => 2, 'v' => { '$x' => :a }, '$f' => { 'a' => 3 }} + end + it 'reject that which you is not your desire' do + onlydollars = subject.reject do |key, fragment| + key =~ /^\$/ + end + expected = {"x"=>1, "v"=>{}} + expect(onlydollars.base).to eq expected + end + end + describe '#reduce' do it "performs as you'd expect reduce to" do keys = subject.reduce(0) do |sum, key, fragment| sum += (key.is_a?(String) ? 1 : 0) end