neopets 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Rakefile +1 -0
- data/autotest/discover.rb +1 -0
- data/lib/neopets.rb +5 -0
- data/lib/neopets/pet.rb +48 -0
- data/lib/neopets/user.rb +62 -0
- data/lib/neopets/version.rb +3 -0
- data/neopets.gemspec +25 -0
- data/spec/_samples/userlookup/account_disabled.html +589 -0
- data/spec/_samples/userlookup/dirtside.html +962 -0
- data/spec/_samples/userlookup/not_found.html +731 -0
- data/spec/neopets/pet_spec.rb +43 -0
- data/spec/neopets/user_spec.rb +78 -0
- data/spec/spec_helper.rb +4 -0
- metadata +93 -0
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'neopets/pet'
|
3
|
+
|
4
|
+
describe Neopets::Pet do
|
5
|
+
it 'initializes with name' do
|
6
|
+
pet = Neopets::Pet.new('matts_bat')
|
7
|
+
pet.name.should == 'matts_bat'
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'initializer optionally accepts gender, image url' do
|
11
|
+
pet = Neopets::Pet.new('matts_bat', :gender => :male,
|
12
|
+
:image_url => 'http://pets.neopets.com/cp/2gcmf37c/1/2.png')
|
13
|
+
|
14
|
+
pet.gender.should == :male
|
15
|
+
pet.image_url.should == 'http://pets.neopets.com/cp/2gcmf37c/1/2.png'
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'supports #male?, #female? gender helpers' do
|
19
|
+
pet = Neopets::Pet.new('matts_bat', :gender => :male)
|
20
|
+
pet.male?.should == true
|
21
|
+
pet.female?.should == false
|
22
|
+
|
23
|
+
pet = Neopets::Pet.new('matts_bat', :gender => :female)
|
24
|
+
pet.male?.should == false
|
25
|
+
pet.female?.should == true
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'parses cp, mood from image url' do
|
29
|
+
pet = Neopets::Pet.new('matts_bat')
|
30
|
+
|
31
|
+
pet.image_url = 'http://pets.neopets.com/cp/2gcmf37c/1/2.png'
|
32
|
+
pet.cp.should == '2gcmf37c'
|
33
|
+
pet.mood.should == :happy
|
34
|
+
|
35
|
+
pet.image_url = 'http://pets.neopets.com/cp/h47bjc9g/2/2.png'
|
36
|
+
pet.cp.should == 'h47bjc9g'
|
37
|
+
pet.mood.should == :sad
|
38
|
+
|
39
|
+
pet.image_url = 'http://pets.neopets.com/cp/s6twjtxq/4/2.png'
|
40
|
+
pet.cp.should == 's6twjtxq'
|
41
|
+
pet.mood.should == :sick
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'neopets/pet'
|
3
|
+
require 'neopets/user'
|
4
|
+
require 'webmock/rspec'
|
5
|
+
|
6
|
+
describe Neopets::User do
|
7
|
+
describe '.new' do
|
8
|
+
it 'initializes with username' do
|
9
|
+
user = Neopets::User.new('dirtside')
|
10
|
+
user.username.should == 'dirtside'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#pets' do
|
15
|
+
it 'has pets' do
|
16
|
+
stub_request(:get, 'http://www.neopets.com/userlookup.phtml?user=dirtside').
|
17
|
+
to_return(:status => 200, :body => web_sample('userlookup/dirtside.html'))
|
18
|
+
|
19
|
+
user = Neopets::User.new('dirtside')
|
20
|
+
|
21
|
+
# stub dirtside's pets
|
22
|
+
pets = [double('enkerethor'), double('gelbon'), double('rohane2000'), double('teramenor')]
|
23
|
+
|
24
|
+
Neopets::Pet.stub(:new).with(
|
25
|
+
'Enkerethor',
|
26
|
+
:gender => :male,
|
27
|
+
:image_url => 'http://pets.neopets.com/cp/2gcmf37c/1/2.png'
|
28
|
+
).and_return(pets[0])
|
29
|
+
|
30
|
+
Neopets::Pet.stub(:new).with(
|
31
|
+
'Gelbon',
|
32
|
+
:gender => :male,
|
33
|
+
:image_url => 'http://pets.neopets.com/cp/mb4mcwj5/1/2.png'
|
34
|
+
).and_return(pets[1])
|
35
|
+
|
36
|
+
Neopets::Pet.stub(:new).with(
|
37
|
+
'Rohane2000',
|
38
|
+
:gender => :female,
|
39
|
+
:image_url => 'http://pets.neopets.com/cp/wbz2n3f8/1/2.png'
|
40
|
+
).and_return(pets[2])
|
41
|
+
|
42
|
+
Neopets::Pet.stub(:new).with(
|
43
|
+
'Teramenor',
|
44
|
+
:gender => :male,
|
45
|
+
:image_url => 'http://pets.neopets.com/cp/gbwflsho/2/2.png'
|
46
|
+
).and_return(pets[3])
|
47
|
+
|
48
|
+
user.pets.should == pets
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'raises NotFoundError when user does not exist' do
|
52
|
+
stub_request(:get, 'http://www.neopets.com/userlookup.phtml?user=jlkjglkejsklrajfdoi').
|
53
|
+
to_return(:status => 200, :body => web_sample('userlookup/not_found.html'))
|
54
|
+
|
55
|
+
user = Neopets::User.new('jlkjglkejsklrajfdoi')
|
56
|
+
lambda { user.pets }.should raise_error(Neopets::User::NotFoundError)
|
57
|
+
lambda { user.pets }.should raise_error(Neopets::User::Error) # ensure properly subclassed
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'raises AccountDisabledError when user has been frozen' do
|
61
|
+
stub_request(:get, 'http://www.neopets.com/userlookup.phtml?user=poop').
|
62
|
+
to_return(:status => 200, :body => web_sample('userlookup/account_disabled.html'))
|
63
|
+
|
64
|
+
user = Neopets::User.new('poop')
|
65
|
+
lambda { user.pets }.should raise_error(Neopets::User::AccountDisabledError)
|
66
|
+
lambda { user.pets }.should raise_error(Neopets::User::Error) # ensure properly subclassed
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'raises ConnectionError when userlookup request fails' do
|
70
|
+
stub_request(:get, 'http://www.neopets.com/userlookup.phtml?user=dirtside')
|
71
|
+
.to_return(:status => 503, :body => 'Down for Maintenance')
|
72
|
+
|
73
|
+
user = Neopets::User.new('dirtside')
|
74
|
+
lambda { user.pets }.should raise_error(Neopets::User::ConnectionError)
|
75
|
+
lambda { user.pets }.should raise_error(Neopets::User::Error) # ensure properly subclassed
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: neopets
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Matchu
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-05-21 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: nokogiri
|
16
|
+
requirement: &21026240 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.5.2
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *21026240
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &21025640 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.10.0
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *21025640
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: webmock
|
38
|
+
requirement: &21025000 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.8.7
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *21025000
|
47
|
+
description:
|
48
|
+
email:
|
49
|
+
- matchu1993@gmail.com
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- .gitignore
|
55
|
+
- Gemfile
|
56
|
+
- Rakefile
|
57
|
+
- autotest/discover.rb
|
58
|
+
- lib/neopets.rb
|
59
|
+
- lib/neopets/pet.rb
|
60
|
+
- lib/neopets/user.rb
|
61
|
+
- lib/neopets/version.rb
|
62
|
+
- neopets.gemspec
|
63
|
+
- spec/_samples/userlookup/account_disabled.html
|
64
|
+
- spec/_samples/userlookup/dirtside.html
|
65
|
+
- spec/_samples/userlookup/not_found.html
|
66
|
+
- spec/neopets/pet_spec.rb
|
67
|
+
- spec/neopets/user_spec.rb
|
68
|
+
- spec/spec_helper.rb
|
69
|
+
homepage: ''
|
70
|
+
licenses: []
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ! '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ! '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
requirements: []
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 1.8.10
|
90
|
+
signing_key:
|
91
|
+
specification_version: 3
|
92
|
+
summary: access public information on Neopets.com
|
93
|
+
test_files: []
|