Skip to content

Commit

Permalink
spec/libcdb/reader_spec.rb: Added some more examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
blackwinter committed Jan 20, 2012
1 parent c694c75 commit dc39ebf
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions spec/libcdb/reader_spec.rb
Expand Up @@ -55,6 +55,18 @@
@db.size.should == 0
end

it "should know its total" do
@db.total.should == 0
end

it "should know its keys" do
@db.keys.should == []
end

it "should know its values" do
@db.values.should == []
end

it "should know if it doesn't have a key" do
@db.should_not have_key('key3')
end
Expand All @@ -63,6 +75,18 @@
@db.should_not have_value('value3.2')
end

it "should dump itself" do
@db.dump.should == ''
end

it "should convert itself into a hash" do
@db.to_h.should == {}
end

it "should convert itself into an array" do
@db.to_a.should == []
end

end

describe "non-empty" do
Expand All @@ -87,6 +111,18 @@
@db.size.should == 11
end

it "should know its total" do
@db.total.should == 56
end

it "should know its keys" do
@db.keys.should == TEST_DATA.map { |k, _| k }.uniq
end

it "should know its values" do
@db.values.should == TEST_DATA.map { |_, v| v }.flatten
end

it "should know if it has a key" do
@db.should have_key('key3')
end
Expand Down Expand Up @@ -137,6 +173,24 @@
@db.key('value33.22').should be_nil
end

it "should dump records for key" do
d = []
@db.each_dump('key3') { |e| d << e }
d.should == %w[+4,8:key3->value3.1 +4,8:key3->value3.2 +4,8:key3->value3.3]
end

it "should convert itself into a hash" do
h = {}
TEST_DATA.each { |k, v| h[k] = v.size > 1 ? v : v.first }
@db.to_h.should == h
end

it "should convert itself into an array" do
a = []
TEST_DATA.each { |k, v| v.each { |w| a << [k, w] } }
@db.to_a.should == a
end

end

end

0 comments on commit dc39ebf

Please sign in to comment.