skooby 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +56 -0
- data/Rakefile +9 -0
- data/lib/skooby/book.rb +46 -0
- data/lib/skooby/request.rb +14 -0
- data/lib/skooby/search.rb +27 -0
- data/lib/skooby/version.rb +3 -0
- data/lib/skooby.rb +9 -0
- data/skooby.gemspec +24 -0
- data/test/fixtures/cassettes/fetch_movie.yml +1217 -0
- data/test/fixtures/cassettes/search_movie_multiple_results.yml +579 -0
- data/test/fixtures/cassettes/search_movie_one_result.yml +744 -0
- data/test/helper.rb +9 -0
- data/test/unit/test_book.rb +102 -0
- data/test/unit/test_request.rb +19 -0
- data/test/unit/test_search.rb +48 -0
- metadata +150 -0
data/test/helper.rb
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
require_relative '../helper'
|
2
|
+
|
3
|
+
class TestBook < MiniTest::Unit::TestCase
|
4
|
+
def test_initialization_of_attributes
|
5
|
+
subject = Skooby::Book.new(id: 108)
|
6
|
+
assert_equal 108, subject.id, 'should allow initialization of id'
|
7
|
+
subject = Skooby::Book.new(title: 'Harry Potter e a Pedra Filosofal')
|
8
|
+
assert_equal 'Harry Potter e a Pedra Filosofal', subject.title,
|
9
|
+
'should allow initialization of id'
|
10
|
+
subject = Skooby::Book.new(author: 'J. K. Rowling')
|
11
|
+
assert_equal 'J. K. Rowling', subject.author,
|
12
|
+
'should allow initialization of author'
|
13
|
+
subject = Skooby::Book.new(rating: 0.88)
|
14
|
+
assert_equal 0.88, subject.rating, 'should allow initialization of rating'
|
15
|
+
subject = Skooby::Book.new(votes: 123)
|
16
|
+
assert_equal 123, subject.votes, 'should allow initialization of votes'
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_initialization_should_not_trigger_fetch_method
|
20
|
+
Skooby::Book.any_instance.expects(:fetch).never
|
21
|
+
Skooby::Book.new(id: 108)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_url_method_should_return_a_valid_url
|
25
|
+
URI.parse(Skooby::Book.new(id: 108).url)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_url_method_raises_exception_when_called_without_an_id
|
29
|
+
assert_raises(ArgumentError) do
|
30
|
+
Skooby::Book.new(id: nil).url
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_asking_for_the_author_should_trigger_fetch_method
|
35
|
+
Skooby::Book.any_instance.expects(:fetch).returns(stub(author: 'J. K. Rowling'))
|
36
|
+
Skooby::Book.new(id: 108).author
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_asking_for_the_rating_should_trigger_fetch_method
|
40
|
+
Skooby::Book.any_instance.expects(:fetch).returns(stub(rating: 1))
|
41
|
+
Skooby::Book.new(id: 108).rating
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_asking_for_the_votes_should_trigger_fetch_method
|
45
|
+
Skooby::Book.any_instance.expects(:fetch).returns(stub(votes: 1))
|
46
|
+
Skooby::Book.new(id: 108).votes
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_fetch_method_shouldnt_be_triggered_when_asking_for_a_already_assigned_author
|
50
|
+
Skooby::Book.any_instance.expects(:fetch).never
|
51
|
+
Skooby::Book.new(id: 108, author: 'J. K. Rowling')
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_fetch_method_shouldnt_be_triggered_when_asking_for_a_already_assigned_rating
|
55
|
+
Skooby::Book.any_instance.expects(:fetch).never
|
56
|
+
Skooby::Book.new(id: 108, rating: 0.88)
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_fetch_method_shouldnt_be_triggered_when_asking_for_a_already_assigned_votes
|
60
|
+
Skooby::Book.any_instance.expects(:fetch).never
|
61
|
+
Skooby::Book.new(id: 108, votes: 0.88)
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_fetch_method_populates_author_attribute
|
65
|
+
subject = Skooby::Book.new(id: 108)
|
66
|
+
VCR.use_cassette('fetch_movie') do
|
67
|
+
subject.fetch
|
68
|
+
end
|
69
|
+
refute_nil subject.author
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_fetch_method_populates_rating_attribute
|
73
|
+
subject = Skooby::Book.new(id: 108)
|
74
|
+
VCR.use_cassette('fetch_movie') do
|
75
|
+
subject.fetch
|
76
|
+
end
|
77
|
+
refute_nil subject.rating
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_fetch_method_populates_votes_attribute
|
81
|
+
subject = Skooby::Book.new(id: 108)
|
82
|
+
VCR.use_cassette('fetch_movie') do
|
83
|
+
subject.fetch
|
84
|
+
end
|
85
|
+
refute_nil subject.votes
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_fetch_method_returns_a_reloaded_instance_of_self
|
89
|
+
subject = Skooby::Book.new(id: 108)
|
90
|
+
VCR.use_cassette('fetch_movie') do
|
91
|
+
assert subject.fetch.is_a?(Skooby::Book), 'should be a instance of Skooby::Book'
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_fetch_method_gets_the_page_of_the_book
|
96
|
+
subject = Skooby::Book.new(id: 108)
|
97
|
+
Nokogiri::HTML.stubs(:parse).returns(stub(css: [stub_everything]))
|
98
|
+
Regexp.any_instance.stubs(:match).returns([])
|
99
|
+
Skooby::Request.any_instance.expects(:get).with('/livro/108')
|
100
|
+
subject.fetch
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative '../helper'
|
2
|
+
|
3
|
+
class TestRequest < MiniTest::Unit::TestCase
|
4
|
+
def test_defines_skoobs_base_uri
|
5
|
+
assert_equal 'http://skoob.com.br', Skooby::Request.base_uri
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_post_method_delegates_itself_to_a_class_method
|
9
|
+
Skooby::Request.expects(:post).with('/', bla: :foo).
|
10
|
+
returns(stub('response', :body))
|
11
|
+
Skooby::Request.new.post('/', bla: :foo)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_get_method_delegates_itself_to_a_class_method
|
15
|
+
Skooby::Request.expects(:get).with('/', bla: :foo).
|
16
|
+
returns(stub('response', :body))
|
17
|
+
Skooby::Request.new.get('/', bla: :foo)
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require_relative '../helper'
|
2
|
+
|
3
|
+
class TestSearch < MiniTest::Unit::TestCase
|
4
|
+
def subject
|
5
|
+
Skooby::Search.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_book_method_returns_a_collection_of_Skooby_Book_instances_when_find_more_than_one_book
|
9
|
+
result = nil
|
10
|
+
VCR.use_cassette('search_movie_multiple_results') do
|
11
|
+
result = subject.book('Harry Potter e a Pedra Filosofal')
|
12
|
+
end
|
13
|
+
assert result.is_a?(Enumerable), 'should be a collection'
|
14
|
+
result.each { |book| assert book.is_a?(Skooby::Book), 'should be a Skooby::Book' }
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_book_method_returned_collection_must_have_ids
|
18
|
+
result = nil
|
19
|
+
VCR.use_cassette('search_movie_multiple_results') do
|
20
|
+
result = subject.book('Harry Potter e a Pedra Filosofal')
|
21
|
+
end
|
22
|
+
result.each { |book| refute_nil book.id }
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_book_method_returned_collection_must_have_titles
|
26
|
+
result = nil
|
27
|
+
VCR.use_cassette('search_movie_multiple_results') do
|
28
|
+
result = subject.book('Harry Potter e a Pedra Filosofal')
|
29
|
+
end
|
30
|
+
result.each { |book| refute_nil book.title }
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_book_method_returned_collection_must_have_authors
|
34
|
+
result = nil
|
35
|
+
VCR.use_cassette('search_movie_multiple_results') do
|
36
|
+
result = subject.book('Harry Potter e a Pedra Filosofal')
|
37
|
+
end
|
38
|
+
result.each { |book| refute_nil book.author }
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_book_method_returns_a_Skooby_Book_when_find_just_one_book
|
42
|
+
result = nil
|
43
|
+
VCR.use_cassette('search_movie_one_result') do
|
44
|
+
result = subject.book('Exceptional Ruby')
|
45
|
+
end
|
46
|
+
assert result.is_a?(Skooby::Book), 'should be a Skooby::Book'
|
47
|
+
end
|
48
|
+
end
|
metadata
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: skooby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Irio Irineu Musskopf Junior
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-18 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: minitest
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: mocha
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: vcr
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: httparty
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: nokogiri
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
description: API like interface to provide information about books available at Skoob.
|
95
|
+
email:
|
96
|
+
- irio.musskopf@caixadeideias.com.br
|
97
|
+
executables: []
|
98
|
+
extensions: []
|
99
|
+
extra_rdoc_files: []
|
100
|
+
files:
|
101
|
+
- .gitignore
|
102
|
+
- Gemfile
|
103
|
+
- LICENSE.txt
|
104
|
+
- README.md
|
105
|
+
- Rakefile
|
106
|
+
- lib/skooby.rb
|
107
|
+
- lib/skooby/book.rb
|
108
|
+
- lib/skooby/request.rb
|
109
|
+
- lib/skooby/search.rb
|
110
|
+
- lib/skooby/version.rb
|
111
|
+
- skooby.gemspec
|
112
|
+
- test/fixtures/cassettes/fetch_movie.yml
|
113
|
+
- test/fixtures/cassettes/search_movie_multiple_results.yml
|
114
|
+
- test/fixtures/cassettes/search_movie_one_result.yml
|
115
|
+
- test/helper.rb
|
116
|
+
- test/unit/test_book.rb
|
117
|
+
- test/unit/test_request.rb
|
118
|
+
- test/unit/test_search.rb
|
119
|
+
homepage: https://github.com/Irio/skooby
|
120
|
+
licenses: []
|
121
|
+
post_install_message:
|
122
|
+
rdoc_options: []
|
123
|
+
require_paths:
|
124
|
+
- lib
|
125
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
126
|
+
none: false
|
127
|
+
requirements:
|
128
|
+
- - ! '>='
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
|
+
none: false
|
133
|
+
requirements:
|
134
|
+
- - ! '>='
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
requirements: []
|
138
|
+
rubyforge_project:
|
139
|
+
rubygems_version: 1.8.24
|
140
|
+
signing_key:
|
141
|
+
specification_version: 3
|
142
|
+
summary: Gives you some API like's methods to access Skoob data.
|
143
|
+
test_files:
|
144
|
+
- test/fixtures/cassettes/fetch_movie.yml
|
145
|
+
- test/fixtures/cassettes/search_movie_multiple_results.yml
|
146
|
+
- test/fixtures/cassettes/search_movie_one_result.yml
|
147
|
+
- test/helper.rb
|
148
|
+
- test/unit/test_book.rb
|
149
|
+
- test/unit/test_request.rb
|
150
|
+
- test/unit/test_search.rb
|