require 'spec_helper' describe Fetcher::Microdata::Twitter::PersonUser do describe '.new' do before do @argument = stub 'argument' end it 'should accept an argument' do Fetcher::Microdata::Twitter::PersonUser.any_instance.stub :coerce Fetcher::Microdata::Twitter::PersonUser.new @argument end it 'should set the _type to schema.org/Person/User' do Fetcher::Microdata::Twitter::PersonUser.any_instance.stub :coerce person = Fetcher::Microdata::Twitter::PersonUser.new @argument person._type.should == "http://schema.org/Person/User" end it 'should call coerce with the argument' do Fetcher::Microdata::Twitter::PersonUser.any_instance.should_receive(:coerce).with @argument Fetcher::Microdata::Twitter::PersonUser.new @argument end end describe '#coerce' do context 'a valid twitter user hash is passed' do before do @user = JSON.parse File.read 'spec/user.json' @person_user = Fetcher::Microdata::Twitter::PersonUser.new @user end it 'should initialize the additionalType as getfetcher.net/Item' do @person_user.additionalType.should == "http://getfetcher.net/Item" end it 'should assign to :id the "id"' do @person_user.id.should == @user["id"] end it 'should assign to :name the "name"' do @person_user.name.should == @user["name"] end it 'should assign to :dateRegistered the timestamp corresponding to "created_at"' do @person_user.dateRegistered.should == 1249685355 end it 'should assign to :description the "description"' do @person_user.description.should == @user["description"] end it 'should assign to :url the "screen_name" after the twitter url' do @person_user.url.should == "https://twitter.com/#{@user["screen_name"]}" end end end it 'should include Discoverer::Writer' do Fetcher::Microdata::Twitter::PersonUser.ancestors.should include Discoverer::Writer end it 'should include Virtus' do Fetcher::Microdata::Twitter::PersonUser.ancestors.should include Virtus end describe 'attributes' do before do @argument_stub = stub 'argument' Fetcher::Microdata::Twitter::PersonUser.any_instance.stub :coerce end it 'should have the attribute additionalType' do Fetcher::Microdata::Twitter::PersonUser.new(@argument_stub).attributes.should have_key :additionalType end it 'should have the attribute id' do Fetcher::Microdata::Twitter::PersonUser.new(@argument_stub).attributes.should have_key :id end it 'should have the attribute name' do Fetcher::Microdata::Twitter::PersonUser.new(@argument_stub).attributes.should have_key :name end it 'should have the attribute dateRegistered' do Fetcher::Microdata::Twitter::PersonUser.new(@argument_stub).attributes.should have_key :dateRegistered end it 'should have the attribute description' do Fetcher::Microdata::Twitter::PersonUser.new(@argument_stub).attributes.should have_key :description end it 'should have the attribute url' do Fetcher::Microdata::Twitter::PersonUser.new(@argument_stub).attributes.should have_key :url end end end