spec/writer/fetcher/microdata/article_small_spec.rb in fetcher-microdata-0.0.10 vs spec/writer/fetcher/microdata/article_small_spec.rb in fetcher-microdata-0.0.11

- old
+ new

@@ -4,20 +4,47 @@ 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 stub('the hash', :[] => @author_stub) + @schema_stub.should_receive(:attributes).and_return @attr_stub writer = Writer::Fetcher::Microdata::ArticleSmall.new @schema_stub writer.hash.should include final_hash end @@ -30,99 +57,96 @@ @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 + @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 - @schema_stub.should_receive(:attributes) - .and_return :id => 234536234, :author => @author_stub, :viewer => @viewer_stub + 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 :articleBody => "some body", :author => @author_stub, :viewer => @viewer_stub + @schema_stub.should_receive(:attributes).and_return @attr_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 + @author_stub.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 + @schema_stub.should_receive(:attributes).and_return @attr_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 + @viewer_stub.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 + @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 :dateCreated => 23456235, :author => @author_stub, :viewer => @viewer_stub + @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 :provider => ["twitter", "fetcher"], :author => @author_stub, :viewer => @viewer_stub + @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 :url => "http://myurl.info", :author => @author_stub, :viewer => @viewer_stub + @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 \ No newline at end of file