require 'spec_helper' require 'xiv_lodestone/lodestone_character_gear' describe XIVLodestone::GearList do let (:valid) { XIVLodestone::GearList.new(Nokogiri::HTML(open(LOCAL_FILE)). xpath("(//div[@class='item_detail_box'])[position() < 13]")) } let (:invalid) { XIVLodestone::GearList.new(Nokogiri::HTML(open(INVALID_FILE)). xpath("(//div[@class='item_detail_box'])[position() < 13]")) } it 'Dump json of items' do expect(valid.to_json).to eq("{\"weapon\":\"#\",\"head\":\"#\",\"body\":\"#\",\"hands\":\"#\",\"waist\":\"#\",\"legs\":\"#\",\"feet\":\"#\",\"necklace\":\"#\",\"earrings\":\"#\",\"bracelets\":\"#\",\"ring1\":\"#\",\"ring2\":\"#\"}") expect(invalid.to_json).to eq("{}") expect(valid.to_json.is_a?(String)).to eq(true) end it 'calculate ilevel' do expect(valid.ilevel).to eq(108) end it 'method missing check' do expect(valid.method_missing(:head).is_a?(XIVLodestone::GearList::Gear)).to eql(true) expect(valid.method_missing(:weapon).is_a?(XIVLodestone::GearList::Gear)).to eql(true) expect(valid.method_missing(:ring1).is_a?(XIVLodestone::GearList::Gear)).to eql(true) end it 'Build a Gear' do d = XIVLodestone::GearList::Gear.new("Sword", 100, "Two Hand", "http") expect(d.name).to eq("Sword") expect(d.ilevel).to eq(100) expect(d.slot).to eq("Two Hand") expect(d.url).to eq("http") end end