Skip to content

Commit

Permalink
category_spec refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
m16a1 committed Aug 25, 2012
1 parent 0643f73 commit b460f62
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions spec/rspec/category_spec.rb
Expand Up @@ -2,23 +2,25 @@
require 'spec_helper'

describe Taobao::Category do

it 'should have name' do
category = Taobao::Category.new(28)
category.id.should == 28

fixture = 'category.json'.json_fixture
args = {
method: 'taobao.itemcats.get',
fields: 'cid,parent_cid,name,is_parent',
cids: 28
}
Taobao.stub(:api_request).with(args).and_return(fixture)
category.name.should == 'ZIPPO/瑞士军刀/眼镜'
describe '#id' do
it 'should returns ID of the category' do
category = Taobao::Category.new(28)
category.id.should == 28
end
end

describe 'with incorrect id' do
it 'should throws an exception' do
describe '#name' do
it 'should returns the name of the category' do
category = Taobao::Category.new(28)
fixture = 'category.json'.json_fixture
args = {
method: 'taobao.itemcats.get',
fields: 'cid,parent_cid,name,is_parent',
cids: 28
}
Taobao.stub(:api_request).with(args).and_return(fixture)
category.name.should == 'ZIPPO/瑞士军刀/眼镜'
end
it 'should throws an exception if the category ID is incorrect' do
fixture = 'incorrect_category.json'.json_fixture
args = {
method: 'taobao.itemcats.get',
Expand All @@ -33,34 +35,33 @@
end
end

describe 'subcategories' do
describe '#subcategories' do
category = Taobao::Category.new(28)

fixture = 'subcategories.json'.json_fixture
args = {
method: 'taobao.itemcats.get',
fields: 'cid,parent_cid,name,is_parent',
parent_cid: 28
}
it 'top level category should contains a few subcategories' do
it 'should returns subcategories if they are exists' do
Taobao.stub(:api_request).with(args).and_return(fixture)
category.subcategories.should have_at_least(1).subcategory
end
it 'each subcategory must be an object of Taobao::Category class' do
it 'each subcategory should be an object of Taobao::Category class' do
Taobao.stub(:api_request).with(args).and_return(fixture)
category.subcategories[0].should be_a_kind_of(Taobao::Category)
end
end

describe 'properties' do
it 'should return empty array for top level category' do
describe '#properties' do
it 'should return a PropertyList object' do
category = Taobao::Category.new(0)
category.properties.should be_a_kind_of(Taobao::PropertyList)
category.properties.should be_a_kind_of(Taobao::PropertyList)
end
end

describe 'products' do
it 'should return ProductList object' do
describe '#products' do
it 'should return a ProductList object' do
category = Taobao::Category.new(28)
category.products.should be_a_kind_of(Taobao::ProductList)
end
Expand Down

0 comments on commit b460f62

Please sign in to comment.