require 'spec_helper' describe Writer::Fetcher::Microdata::UserComments do describe '#hash' do before do @schema_stub = stub 'schema' @creator_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 == :creator @creator_stub elsif simbol == :additionalType "http://getfetcher.net/Item" elsif simbol == :id "234536234_12345_1234567" elsif simbol == :commentText "some body" elsif simbol == :creator ["twitter", "fetcher"] elsif simbol == :commentTime 23456235 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::UserComments.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_12345_1234567" ] } @schema_stub.should_receive(:attributes).and_return @attr_stub end it 'should include the commentText' do @properties_hash = { "commentText" => [ "some body" ] } @schema_stub.should_receive(:attributes).and_return @attr_stub end it 'should include the creator' do @creator_writer = stub 'creator writer' @creator_writer.should_receive(:hash).and_return "hi Im the creator" @creator_stub.should_receive(:to).and_return @creator_writer @properties_hash = { "creator" => [ "hi Im the creator" ] } @schema_stub.should_receive(:attributes).and_return @attr_stub end it 'should include the commentTime' do @properties_hash = { "commentTime" => [ 23456235 ] } @schema_stub.should_receive(:attributes).and_return @attr_stub end it 'should include the url' do @properties_hash = { "url" => [ "https://www.facebook.com/12345?comment_id=1234567" ] } @schema_stub.should_receive(:attributes).and_return @attr_stub end after :each do writer = Writer::Fetcher::Microdata::UserComments.new @schema_stub writer.hash["properties"].should include @properties_hash end end end end