Skip to content
Browse files

spec/libcdb/reader_spec.rb: Added some more examples.

  • Loading branch information...
1 parent c694c75 commit dc39ebf88cd2e54f9c5ba4174b37d33aa7cb576f @blackwinter committed
Showing with 54 additions and 0 deletions.
  1. +54 −0 spec/libcdb/reader_spec.rb
View
54 spec/libcdb/reader_spec.rb
@@ -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
@@ -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
@@ -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
@@ -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.
Something went wrong with that request. Please try again.