require 'spec_helper' describe Writer::Fetcher::Microdata::ArticleSmall do describe '#hash' do before do @schema_stub = stub 'schema' @author_stub = stub 'author', :to => stub( :hash => nil) @viewer_stub = stub 'viewer', :to => stub( :hash => nil) @attr_stub = stub 'attr stub' stub1 = stub 'coment1', :to => "hola1" stub2 = stub 'coment2', :to => "hola2" @attr_stub.stub(:[]) do |simbol| if simbol == :author @author_stub elsif simbol == :viewer @viewer_stub elsif simbol == :comments [stub1,stub2] elsif simbol == :additionalType "http://getfetcher.net/Item" elsif simbol == :id 234536234 elsif simbol == :articleBody "some body" elsif simbol == :dateCreated 23456235 elsif simbol == :provider ["twitter", "fetcher"] elsif simbol == :url "http://myurl.info" else stub('the hash', :[] => @attr_stub) end end end it 'should return a hash with the type' do final_hash = { "type" => [ 'the type' ] } @schema_stub.should_receive(:_type).and_return "the type" @schema_stub.should_receive(:attributes).and_return @attr_stub writer = Writer::Fetcher::Microdata::ArticleSmall.new @schema_stub writer.hash.should include final_hash end describe 'properties hash' do before do @schema_stub.should_receive(:_type).and_return nil end it 'should include the additionalType' do @properties_hash = { "additionalType" => [ "http://getfetcher.net/Item" ] } @schema_stub.should_receive(:attributes).and_return @attr_stub end it 'should include the Item#id' do @properties_hash = { "Item#id" => [ 234536234 ] } @schema_stub.should_receive(:attributes).and_return @attr_stub end it 'should include the UserComments' do a = "hola1".hash b = "hola2".hash @properties_hash = { "UserComments" => [ a,b ] } @schema_stub.should_receive(:attributes).and_return @attr_stub end it 'should include the articleBody' do @properties_hash = { "articleBody" => [ "some body" ] } @schema_stub.should_receive(:attributes).and_return @attr_stub end it 'should include the author' do @author_writer = stub 'author writer' @author_writer.should_receive(:hash).and_return "hi Im the author" @author_stub.should_receive(:to).and_return @author_writer @properties_hash = { "author" => [ "hi Im the author" ] } @schema_stub.should_receive(:attributes).and_return @attr_stub end it 'should include the viewer' do @viewer_writer = stub 'viewer writer' @viewer_writer.should_receive(:hash).and_return "hi Im the viewer" @viewer_stub.should_receive(:to).and_return @viewer_writer @properties_hash = { "Item#viewer" => [ "hi Im the viewer" ] } @schema_stub.should_receive(:attributes).and_return @attr_stub end it 'should include the dateCreated' do @properties_hash = { "dateCreated" => [ 23456235 ] } @schema_stub.should_receive(:attributes).and_return @attr_stub end it 'should include the provider' do @properties_hash = { "provider" => [ "twitter", "fetcher" ] } @schema_stub.should_receive(:attributes).and_return @attr_stub end it 'should include the url' do @properties_hash = { "url" => [ "http://myurl.info" ] } @schema_stub.should_receive(:attributes).and_return @attr_stub end after :each do writer = Writer::Fetcher::Microdata::ArticleSmall.new @schema_stub writer.hash["properties"].should include @properties_hash end end end end