Skip to content

Commit

Permalink
refactored 'info_object_spec.rb'
Browse files Browse the repository at this point in the history
  • Loading branch information
semmons99 committed Feb 9, 2010
1 parent 9a7d955 commit 1a813b6
Showing 1 changed file with 79 additions and 62 deletions.
141 changes: 79 additions & 62 deletions spec/info_object_spec.rb
Expand Up @@ -4,114 +4,131 @@
module BOSDK
describe InfoObject do
before(:each) do
# mocks
@infoobject = mock("IInfoObject").as_null_object

@obj = InfoObject.new(@infoobject)
end

describe "#docid" do
it "should call #getID and return the result" do
before(:each) do
@infoobject.should_receive(:getID).once.with.and_return(1)
end

it "should call #getID and return the result" do
@obj.docid.should == 1
end

it "should only call #getID once" do
@infoobject.should_receive(:getID).once.with.and_return(1)

2.times{@obj.docid.should == 1}
end
end

describe "#is_root?" do
it "should return true when #parent_id is nil" do
@infoobject.should_receive(:parent_id).once.with.and_return(nil)
context "when #parent_id == nil" do
before(:each) do
@infoobject.should_receive(:parent_id).once.with.and_return(nil)
end

@obj.is_root?.should be_true
it "should return true" do
@obj.is_root?.should be_true
end
end

it "should return true when #parent_id is '0'" do
@infoobject.should_receive(:parent_id).once.with.and_return(0)
context "when #parent_id == 0" do
before(:each) do
@infoobject.should_receive(:parent_id).once.with.and_return(0)
end

@obj.is_root?.should be_true
it "should return true" do
@obj.is_root?.should be_true
end
end

it "should return true when #parent_id == #getID" do
@infoobject.should_receive(:parent_id).once.with.and_return(1)
@infoobject.should_receive(:getID).once.with.and_return(1)
context "when #parent_id == #getID" do
before(:each) do
@infoobject.should_receive(:parent_id).once.with.and_return(1)
@infoobject.should_receive(:getID).once.with.and_return(1)
end

@obj.is_root?.should be_true
it "should return true" do
@obj.is_root?.should be_true
end
end

it "should return false when #parent_id is not: nil, '0' or #getID" do
@infoobject.should_receive(:parent_id).once.with.and_return(1)
@infoobject.should_receive(:getID).once.with.and_return(2)
context "when #parent_id != nil, 0 or #getID" do
before(:each) do
@infoobject.should_receive(:parent_id).once.with.and_return(1)
@infoobject.should_receive(:getID).once.with.and_return(2)
end

@obj.is_root?.should be_false
it "should return false" do
@obj.is_root?.should be_false
end
end
end

describe "#parent" do
it "should return nil if #is_root? == true" do
@infoobject.should_receive(:parent_id).once.with.and_return(nil)
context "when #is_root? == true" do
before(:each) do
@infoobject.should_receive(:parent_id).once.with.and_return(nil)
end

@obj.parent.should be_nil
it "should return nil" do
@obj.parent.should be_nil
end
end

it "should return results of #getParent if #is_root? == false" do
parent_obj = mock("IInfoObject").as_null_object
@infoobject.should_receive(:parent_id).once.with.and_return(1)
@infoobject.should_receive(:getID).once.with.and_return(2)
@infoobject.should_receive(:getParent).once.with.and_return(parent_obj)

parent = @obj.parent
parent.should be_instance_of InfoObject
parent.obj.should == parent_obj
end
context "when #is_root? == false" do
before(:each) do
@parent_obj = mock("IInfoObject").as_null_object
@infoobject.should_receive(:parent_id).once.with.and_return(1)
@infoobject.should_receive(:getID).once.with.and_return(2)
@infoobject.should_receive(:getParent).once.with.and_return(@parent_obj)
end

it "should only call the underlying #getParent once" do
parent_obj = mock("IInfoObject").as_null_object
@infoobject.should_receive(:parent_id).once.with.and_return(1)
@infoobject.should_receive(:getID).once.with.and_return(2)
@infoobject.should_receive(:getParent).once.with.and_return(parent_obj)
it "should return results of #getParent" do
parent = @obj.parent
parent.should be_instance_of InfoObject
parent.obj.should == @parent_obj
end

2.times{@obj.parent}
it "should only call the underlying #getParent once" do
2.times{@obj.parent}
end
end
end

describe "#path" do
it "should return /#title if #is_root? == true" do
@infoobject.should_receive(:parent_id).once.with.and_return(nil)
@infoobject.should_receive(:title).once.with.and_return('test obj')
context "when #is_root? == true" do
before(:each) do
@infoobject.should_receive(:parent_id).once.with.and_return(nil)
@infoobject.should_receive(:title).once.with.and_return('test obj')
end

@obj.path.should == '/test obj'
it "should return /#title" do
@obj.path.should == '/test obj'
end
end

it "should return #parent_title/../#title if #is_root? == false" do
parent_obj = mock("IInfoObject").as_null_object
parent_obj.should_receive(:parent_id).once.with.and_return(nil)
parent_obj.should_receive(:title).once.with.and_return('test parent')

@infoobject.should_receive(:parent_id).once.with.and_return(1)
@infoobject.should_receive(:getID).once.with.and_return(2)
@infoobject.should_receive(:title).once.with.and_return('test obj')
@infoobject.should_receive(:getParent).once.with.and_return(parent_obj)

@obj.path.should == '/test parent/test obj'
end
context "when #is_root? == false" do
before(:each) do
@parent_obj = mock("IInfoObject").as_null_object
@parent_obj.should_receive(:parent_id).once.with.and_return(nil)
@parent_obj.should_receive(:title).once.with.and_return('test parent')

it "should only call the underlying #title, #parent#path, etc. once" do
parent_obj = mock("IInfoObject").as_null_object
parent_obj.should_receive(:parent_id).once.with.and_return(nil)
parent_obj.should_receive(:title).once.with.and_return('test parent')
@infoobject.should_receive(:parent_id).once.with.and_return(1)
@infoobject.should_receive(:getID).once.with.and_return(2)
@infoobject.should_receive(:title).once.with.and_return('test obj')
@infoobject.should_receive(:getParent).once.with.and_return(@parent_obj)
end

@infoobject.should_receive(:parent_id).once.with.and_return(1)
@infoobject.should_receive(:getID).once.with.and_return(2)
@infoobject.should_receive(:title).once.with.and_return('test obj')
@infoobject.should_receive(:getParent).once.with.and_return(parent_obj)
it "should return #parent_title/../#title" do
@obj.path.should == '/test parent/test obj'
end

2.times{@obj.path}
it "should only call the underlying #title, #parent#path, etc. once" do
2.times{@obj.path}
end
end
end

Expand Down

0 comments on commit 1a813b6

Please sign in to comment.