require 'spec_helper' describe Writer::Fetcher::Microdata::Twitter::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) 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 stub('the hash', :[] => @author_stub) writer = Writer::Fetcher::Microdata::Twitter::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 :additionalType => "http://getfetcher.net/Item", :author => @author_stub, :viewer => @viewer_stub end it 'should include the Item#id' do @properties_hash = { "Item#id" => [ 234536234 ] } @schema_stub.should_receive(:attributes) .and_return :id => 234536234, :author => @author_stub, :viewer => @viewer_stub end it 'should include the articleBody' do @properties_hash = { "articleBody" => [ "some body" ] } @schema_stub.should_receive(:attributes) .and_return :articleBody => "some body", :author => @author_stub, :viewer => @viewer_stub end it 'should include the author' do @author = stub 'author' @author_writer = stub 'author writer' @author_writer.should_receive(:hash).and_return "hi Im the author" @author.should_receive(:to).and_return @author_writer @properties_hash = { "author" => [ "hi Im the author" ] } @schema_stub.should_receive(:attributes) .and_return :author => @author, :viewer => @viewer_stub end it 'should include the viewer' do @viewer = stub 'viewer' @viewer_writer = stub 'viewer writer' @viewer_writer.should_receive(:hash).and_return "hi Im the viewer" @viewer.should_receive(:to).and_return @viewer_writer @properties_hash = { "Item#viewer" => [ "hi Im the viewer" ] } @schema_stub.should_receive(:attributes) .and_return :viewer => @viewer, :author => @author_stub end it 'should include the dateCreated' do @properties_hash = { "dateCreated" => [ 23456235 ] } @schema_stub.should_receive(:attributes) .and_return :dateCreated => 23456235, :author => @author_stub, :viewer => @viewer_stub end it 'should include the provider' do @properties_hash = { "provider" => [ "twitter", "fetcher" ] } @schema_stub.should_receive(:attributes) .and_return :provider => ["twitter", "fetcher"], :author => @author_stub, :viewer => @viewer_stub end it 'should include the url' do @properties_hash = { "url" => [ "http://myurl.info" ] } @schema_stub.should_receive(:attributes) .and_return :url => "http://myurl.info", :author => @author_stub, :viewer => @viewer_stub end after :each do writer = Writer::Fetcher::Microdata::Twitter::ArticleSmall.new @schema_stub writer.hash["properties"].should include @properties_hash end end end end