filmaffinity 1.1.2 → 1.1.3
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.
- checksums.yaml +5 -5
- data/.github/workflows/ci.yml +34 -0
- data/.rubocop.yml +6 -3
- data/Gemfile +10 -2
- data/Gemfile.lock +50 -21
- data/README.md +3 -2
- data/Rakefile +2 -0
- data/filmaffinity.gemspec +25 -19
- data/lib/constants/constants.rb +52 -47
- data/lib/filmaffinity/configuration.rb +1 -0
- data/lib/filmaffinity/{json-movie-parser.rb → json_movie_parser.rb} +5 -2
- data/lib/filmaffinity/{json-movies-parser.rb → json_movies_parser.rb} +5 -7
- data/lib/filmaffinity/movie.rb +30 -34
- data/lib/filmaffinity/{poster-manager.rb → poster_manager.rb} +7 -4
- data/lib/filmaffinity/search.rb +17 -12
- data/lib/filmaffinity/top.rb +22 -14
- data/lib/filmaffinity/version.rb +5 -0
- data/lib/filmaffinity.rb +14 -11
- data/spec/filmaffinity/{json-movie-parser_spec.rb → json_movie_parser_spec.rb} +6 -3
- data/spec/filmaffinity/{json-movies-parser_spec.rb → json_movies_parser_spec.rb} +6 -3
- data/spec/filmaffinity/movie_spec.rb +65 -130
- data/spec/filmaffinity/search_spec.rb +13 -20
- data/spec/filmaffinity/top_spec.rb +65 -72
- data/spec/filmaffinity/version_spec.rb +15 -0
- data/spec/{filmaffinity/matchers/include-movie.rb → matchers/include_movie.rb} +3 -1
- data/spec/spec_helper.rb +8 -1
- data/spec/vcr/FilmAffinity_Movie/english_version/_cast/includes_the_passed_cast.yml +59 -0
- data/spec/vcr/FilmAffinity_Movie/english_version/_cast/returns_an_Array.yml +59 -0
- data/spec/vcr/FilmAffinity_Movie/english_version/_company/returns_Paramount_Pictures_Scott_Rudin_Productions_.yml +59 -0
- data/spec/vcr/FilmAffinity_Movie/english_version/_company/returns_a_String.yml +59 -0
- data/spec/vcr/FilmAffinity_Movie/english_version/_country/returns_United_States_.yml +59 -0
- data/spec/vcr/FilmAffinity_Movie/english_version/_country/returns_a_String.yml +59 -0
- data/spec/vcr/FilmAffinity_Movie/english_version/_director/returns_Peter_Weir_.yml +59 -0
- data/spec/vcr/FilmAffinity_Movie/english_version/_director/returns_a_String.yml +59 -0
- data/spec/vcr/FilmAffinity_Movie/english_version/_duration/returns_103.yml +59 -0
- data/spec/vcr/FilmAffinity_Movie/english_version/_duration/returns_an_Integer.yml +59 -0
- data/spec/vcr/FilmAffinity_Movie/english_version/_genres/includes_the_passed_genres.yml +59 -0
- data/spec/vcr/FilmAffinity_Movie/english_version/_genres/returns_an_Array.yml +59 -0
- data/spec/vcr/FilmAffinity_Movie/english_version/_poster/returns_a_String.yml +59 -0
- data/spec/vcr/FilmAffinity_Movie/english_version/_poster/returns_a_jpg_address.yml +59 -0
- data/spec/vcr/FilmAffinity_Movie/english_version/_rating/returns_an_Float.yml +59 -0
- data/spec/vcr/FilmAffinity_Movie/english_version/_script/returns_Andrew_Niccol_.yml +59 -0
- data/spec/vcr/FilmAffinity_Movie/english_version/_script/returns_a_String.yml +59 -0
- data/spec/vcr/FilmAffinity_Movie/english_version/_title/returns_an_valid_title_when_initializes_with_no_title.yml +59 -0
- data/spec/vcr/FilmAffinity_Movie/english_version/_year/returns_1998.yml +59 -0
- data/spec/vcr/FilmAffinity_Movie/english_version/_year/returns_an_Integer.yml +59 -0
- data/spec/vcr/FilmAffinity_Movie/spanish_version/_cast/includes_the_passed_cast.yml +59 -0
- data/spec/vcr/FilmAffinity_Movie/spanish_version/_cast/returns_an_Array.yml +59 -0
- data/spec/vcr/FilmAffinity_Movie/spanish_version/_company/returns_Paramount_Pictures_Scott_Rudin_Productions_.yml +59 -0
- data/spec/vcr/FilmAffinity_Movie/spanish_version/_company/returns_a_String.yml +59 -0
- data/spec/vcr/FilmAffinity_Movie/spanish_version/_country/returns_Estados_Unidos_.yml +59 -0
- data/spec/vcr/FilmAffinity_Movie/spanish_version/_country/returns_a_String.yml +59 -0
- data/spec/vcr/FilmAffinity_Movie/spanish_version/_director/returns_Peter_Weir_.yml +59 -0
- data/spec/vcr/FilmAffinity_Movie/spanish_version/_director/returns_a_String.yml +59 -0
- data/spec/vcr/FilmAffinity_Movie/spanish_version/_duration/returns_103.yml +59 -0
- data/spec/vcr/FilmAffinity_Movie/spanish_version/_duration/returns_an_Integer.yml +59 -0
- data/spec/vcr/FilmAffinity_Movie/spanish_version/_genres/includes_the_passed_genres.yml +59 -0
- data/spec/vcr/FilmAffinity_Movie/spanish_version/_genres/returns_an_Array.yml +59 -0
- data/spec/vcr/FilmAffinity_Movie/spanish_version/_poster/returns_a_String.yml +59 -0
- data/spec/vcr/FilmAffinity_Movie/spanish_version/_poster/returns_a_jpg_address.yml +59 -0
- data/spec/vcr/FilmAffinity_Movie/spanish_version/_rating/returns_an_Float.yml +59 -0
- data/spec/vcr/FilmAffinity_Movie/spanish_version/_script/returns_Andrew_Niccol_.yml +59 -0
- data/spec/vcr/FilmAffinity_Movie/spanish_version/_script/returns_a_String.yml +59 -0
- data/spec/vcr/FilmAffinity_Movie/spanish_version/_title/returns_an_valid_title_when_initializes_with_no_title.yml +59 -0
- data/spec/vcr/FilmAffinity_Movie/spanish_version/_year/returns_1998.yml +59 -0
- data/spec/vcr/FilmAffinity_Movie/spanish_version/_year/returns_an_Integer.yml +59 -0
- data/spec/vcr/FilmAffinity_Search/_movies/includes_the_The_Truman_Show_.yml +63 -0
- data/spec/vcr/FilmAffinity_Search/_movies/includes_the_Truman_Show_.yml +63 -0
- data/spec/vcr/FilmAffinity_Search/_movies/returns_FilmAffinity_Movie_objects_only.yml +63 -0
- data/spec/vcr/FilmAffinity_Search/_movies/returns_an_array.yml +63 -0
- data/spec/vcr/FilmAffinity_Search/_parse_movie/parses_the_id.yml +114 -0
- data/spec/vcr/FilmAffinity_Search/_parse_movie/parses_the_title.yml +114 -0
- data/spec/vcr/FilmAffinity_Top/_movies/no_options/includes_El_Padrino_.yml +63 -0
- data/spec/vcr/FilmAffinity_Top/_movies/no_options/includes_The_Godfather_.yml +63 -0
- data/spec/vcr/FilmAffinity_Top/_movies/no_options/returns_30_movies.yml +63 -0
- data/spec/vcr/FilmAffinity_Top/_movies/no_options/returns_FilmAffinity_Movie_objects_only.yml +63 -0
- data/spec/vcr/FilmAffinity_Top/_movies/no_options/returns_an_array.yml +63 -0
- data/spec/vcr/FilmAffinity_Top/_movies/with_options/only_with_limit/set_to_10/returns_10_movies.yml +63 -0
- data/spec/vcr/FilmAffinity_Top/_movies/with_options/only_with_limit/set_to_132/returns_132_movies.yml +303 -0
- data/spec/vcr/FilmAffinity_Top/_movies/with_options/only_with_limit/set_to_60/does_not_include_Con_la_muerte_en_los_talones_.yml +123 -0
- data/spec/vcr/FilmAffinity_Top/_movies/with_options/only_with_limit/set_to_60/includes_American_History_X_.yml +123 -0
- data/spec/vcr/FilmAffinity_Top/_movies/with_options/only_with_limit/set_to_60/returns_60_movies.yml +123 -0
- data/spec/vcr/FilmAffinity_Top/_movies/with_options/with_genre_BE_and_country_code_DE_/includes_Generation_War_TV_Miniseries_.yml +125 -0
- data/spec/vcr/FilmAffinity_Top/_movies/with_options/with_genre_BE_and_country_code_DE_/includes_Hijos_del_Tercer_Reich_Miniserie_de_TV_.yml +125 -0
- data/spec/vcr/FilmAffinity_Top/_movies/with_options/with_genre_BE_and_country_code_DE_/returns_FilmAffinity_Movie_objects_only.yml +125 -0
- data/spec/vcr/FilmAffinity_Top/_movies/with_options/with_genre_BE_and_country_code_DE_/returns_an_array.yml +125 -0
- data/spec/vcr/JsonMovieParser/_to_hash/returns_the_right_director_for_the_given_movie.yml +59 -0
- data/spec/vcr/JsonMoviesParser/_to_hashes/returns_some_valid_ids_for_a_given_search.yml +63 -0
- metadata +162 -31
- data/.rubocop_todo.yml +0 -48
- data/.travis.yml +0 -11
data/lib/filmaffinity/search.rb
CHANGED
@@ -1,17 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'cgi'
|
2
4
|
|
3
5
|
module FilmAffinity
|
4
|
-
# Class Search
|
5
6
|
class Search
|
6
7
|
def initialize(query)
|
7
8
|
@query = query
|
8
|
-
@json_parser = JsonMoviesParser.new
|
9
9
|
end
|
10
10
|
|
11
11
|
def movies
|
12
12
|
@movies ||= (exact_match? ? parse_movie : parse_movies)
|
13
13
|
end
|
14
14
|
|
15
|
+
def to_json(*_args)
|
16
|
+
@json_parser.to_json(movies)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def json_parser
|
22
|
+
@json_parser ||= JsonMoviesParser.new
|
23
|
+
end
|
24
|
+
|
15
25
|
def exact_match?
|
16
26
|
!document_html.at('.z-movie').nil?
|
17
27
|
end
|
@@ -21,28 +31,23 @@ module FilmAffinity
|
|
21
31
|
end
|
22
32
|
|
23
33
|
def generate_html
|
24
|
-
|
34
|
+
URI.parse(Constants.urls[:search_by_title] % CGI.escape(@query)).open
|
25
35
|
end
|
26
36
|
|
27
37
|
def parse_movie
|
28
38
|
id = document_html.at('meta[property="og:url"]')['content'][/\d+/].to_i
|
29
39
|
title = document_html.at('meta[property="og:title"]')['content']
|
40
|
+
|
30
41
|
[FilmAffinity::Movie.new(id, title)]
|
31
42
|
end
|
32
43
|
|
33
44
|
def parse_movies
|
34
|
-
|
35
|
-
document_html.search('.movie-card.movie-card-1').each do |movie_card|
|
45
|
+
document_html.search('.movie-card.movie-card-1').map do |movie_card|
|
36
46
|
id = movie_card['data-movie-id'].to_i
|
37
47
|
title = movie_card.search('.mc-title a').first.content.strip
|
38
|
-
movie = FilmAffinity::Movie.new id, title
|
39
|
-
movies << movie
|
40
|
-
end
|
41
|
-
movies
|
42
|
-
end
|
43
48
|
|
44
|
-
|
45
|
-
|
49
|
+
FilmAffinity::Movie.new(id, title)
|
50
|
+
end
|
46
51
|
end
|
47
52
|
end
|
48
53
|
end
|
data/lib/filmaffinity/top.rb
CHANGED
@@ -1,16 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module FilmAffinity
|
2
|
-
# Class Top
|
3
4
|
class Top
|
4
5
|
def initialize(options: {}, limit: 30)
|
5
6
|
@options = options
|
6
7
|
@limit = limit
|
7
|
-
@json_parser = JsonMoviesParser.new
|
8
8
|
end
|
9
9
|
|
10
10
|
def movies
|
11
11
|
@movies = movies_with_limit
|
12
12
|
end
|
13
13
|
|
14
|
+
def to_json(*_args)
|
15
|
+
@json_parser.to_json(movies)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def json_parser
|
21
|
+
@json_parser ||= JsonMoviesParser.new
|
22
|
+
end
|
23
|
+
|
14
24
|
def document_html(from)
|
15
25
|
@document_html = Nokogiri::HTML(generate_html(from))
|
16
26
|
end
|
@@ -23,8 +33,7 @@ module FilmAffinity
|
|
23
33
|
end
|
24
34
|
|
25
35
|
def query_options
|
26
|
-
query_options = ''
|
27
|
-
query_options += '?'
|
36
|
+
query_options = '?'
|
28
37
|
@options.each do |key, value|
|
29
38
|
query_options += Constants.query_params[key] % value
|
30
39
|
end
|
@@ -42,22 +51,21 @@ module FilmAffinity
|
|
42
51
|
response = yield(from)
|
43
52
|
collection += response
|
44
53
|
last_position = collection.size
|
45
|
-
|
54
|
+
|
55
|
+
if response.empty? || last_position >= @limit
|
56
|
+
collection.flatten[0..@limit - 1]
|
57
|
+
else
|
58
|
+
collect_from(collection, last_position, &block)
|
59
|
+
end
|
46
60
|
end
|
47
61
|
|
48
62
|
def parse_movies(document_html)
|
49
|
-
|
50
|
-
document_html.search('.movie-card.movie-card-0').each_with_index do |movie_card, _index|
|
63
|
+
document_html.search('.movie-card.movie-card-0').map do |movie_card|
|
51
64
|
id = movie_card['data-movie-id'].to_i
|
52
65
|
title = movie_card.search('.mc-title a').first.content.strip
|
53
|
-
movie = FilmAffinity::Movie.new id, title
|
54
|
-
movies << movie
|
55
|
-
end
|
56
|
-
movies
|
57
|
-
end
|
58
66
|
|
59
|
-
|
60
|
-
|
67
|
+
FilmAffinity::Movie.new(id, title)
|
68
|
+
end
|
61
69
|
end
|
62
70
|
end
|
63
71
|
end
|
data/lib/filmaffinity.rb
CHANGED
@@ -1,25 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'open-uri'
|
2
4
|
require 'nokogiri'
|
3
5
|
|
4
6
|
require_relative 'constants/constants'
|
5
7
|
require_relative 'filmaffinity/configuration'
|
6
|
-
require_relative 'filmaffinity/
|
7
|
-
require_relative 'filmaffinity/
|
8
|
-
require_relative 'filmaffinity/
|
8
|
+
require_relative 'filmaffinity/poster_manager'
|
9
|
+
require_relative 'filmaffinity/json_movies_parser'
|
10
|
+
require_relative 'filmaffinity/json_movie_parser'
|
9
11
|
require_relative 'filmaffinity/movie'
|
10
12
|
require_relative 'filmaffinity/search'
|
11
13
|
require_relative 'filmaffinity/top'
|
12
|
-
|
14
|
+
require_relative 'filmaffinity/version'
|
15
|
+
|
13
16
|
module FilmAffinity
|
14
17
|
class << self
|
15
|
-
|
16
|
-
end
|
18
|
+
attr_writer :configuration
|
17
19
|
|
18
|
-
|
19
|
-
|
20
|
-
|
20
|
+
def configuration
|
21
|
+
@configuration ||= Configuration.new
|
22
|
+
end
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
+
def configure
|
25
|
+
yield(configuration)
|
26
|
+
end
|
24
27
|
end
|
25
28
|
end
|
@@ -1,9 +1,12 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe JsonMovieParser, :vcr do
|
4
6
|
describe '#to_hash' do
|
5
7
|
subject { JsonMovieParser.new }
|
6
|
-
|
8
|
+
|
9
|
+
it 'returns the right director for the given movie' do
|
7
10
|
movie = FilmAffinity::Movie.new(504_889, 'El show de Truman (Una vida en directo)')
|
8
11
|
hash = subject.to_hash movie
|
9
12
|
expect(hash['director']).to eq('Peter Weir')
|
@@ -1,9 +1,12 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe JsonMoviesParser, :vcr do
|
4
6
|
describe '#to_hashes' do
|
5
7
|
subject { JsonMoviesParser.new }
|
6
|
-
|
8
|
+
|
9
|
+
it 'returns some valid ids for a given search' do
|
7
10
|
hashes = subject.to_hashes FilmAffinity::Search.new('truman').movies
|
8
11
|
expect(hashes.map { |hash| hash['id'] }).to include(193_232, 504_889)
|
9
12
|
end
|
@@ -1,93 +1,73 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe FilmAffinity::Movie, :vcr do
|
6
|
+
subject(:movie) do
|
7
|
+
FilmAffinity::Movie.new(504_889, 'El show de Truman (Una vida en directo)')
|
8
|
+
end
|
2
9
|
|
3
|
-
describe 'FilmAffinity::Movie' do
|
4
10
|
context 'english version' do
|
5
11
|
describe '#title' do
|
6
12
|
subject(:movie) do
|
7
13
|
FilmAffinity::Movie.new(504_889)
|
8
14
|
end
|
9
|
-
|
15
|
+
|
16
|
+
it 'returns an valid title when initializes with no title' do
|
10
17
|
expect(movie.title).to eq('The Truman Show')
|
11
18
|
end
|
12
19
|
end
|
13
|
-
|
14
20
|
describe '#rating' do
|
15
|
-
|
16
|
-
|
17
|
-
end
|
18
|
-
it 'should return an Float' do
|
21
|
+
|
22
|
+
it 'returns an Float' do
|
19
23
|
expect(movie.rating).to be_a(Float)
|
20
24
|
end
|
21
25
|
end
|
22
|
-
|
23
26
|
describe '#year' do
|
24
|
-
|
25
|
-
|
26
|
-
end
|
27
|
-
it 'should return an Fixnum' do
|
28
|
-
expect(movie.year).to be_an(Fixnum)
|
27
|
+
it 'returns an Integer' do
|
28
|
+
expect(movie.year).to be_an(Integer)
|
29
29
|
end
|
30
|
-
it '
|
30
|
+
it 'returns 1998' do
|
31
31
|
expect(movie.year).to eq(1998)
|
32
32
|
end
|
33
33
|
end
|
34
|
-
|
35
34
|
describe '#duration' do
|
36
|
-
|
37
|
-
|
38
|
-
end
|
39
|
-
it 'should return an Fixnum' do
|
40
|
-
expect(movie.duration).to be_a(Fixnum)
|
35
|
+
it 'returns an Integer' do
|
36
|
+
expect(movie.duration).to be_a(Integer)
|
41
37
|
end
|
42
|
-
it '
|
38
|
+
it 'returns 103' do
|
43
39
|
expect(movie.duration).to eq(103)
|
44
40
|
end
|
45
41
|
end
|
46
|
-
|
47
42
|
describe '#country' do
|
48
|
-
|
49
|
-
FilmAffinity::Movie.new(504_889, 'El show de Truman (Una vida en directo)')
|
50
|
-
end
|
51
|
-
it 'should return a String' do
|
43
|
+
it 'returns a String' do
|
52
44
|
expect(movie.country).to be_a(String)
|
53
45
|
end
|
54
|
-
it '
|
46
|
+
it 'returns "United States"' do
|
55
47
|
expect(movie.country).to eq('United States')
|
56
48
|
end
|
57
49
|
end
|
58
|
-
|
59
50
|
describe '#director' do
|
60
|
-
|
61
|
-
FilmAffinity::Movie.new(504_889, 'El show de Truman (Una vida en directo)')
|
62
|
-
end
|
63
|
-
it 'should return a String' do
|
51
|
+
it 'returns a String' do
|
64
52
|
expect(movie.director).to be_a(String)
|
65
53
|
end
|
66
|
-
it '
|
54
|
+
it 'returns "Peter Weir"' do
|
67
55
|
expect(movie.director).to eq('Peter Weir')
|
68
56
|
end
|
69
57
|
end
|
70
|
-
|
71
58
|
describe '#script' do
|
72
|
-
|
73
|
-
FilmAffinity::Movie.new(504_889, 'El show de Truman (Una vida en directo)')
|
74
|
-
end
|
75
|
-
it 'should return a String' do
|
59
|
+
it 'returns a String' do
|
76
60
|
expect(movie.script).to be_a(String)
|
77
61
|
end
|
78
|
-
it '
|
62
|
+
it 'returns "Andrew Niccol"' do
|
79
63
|
expect(movie.script).to eq('Andrew Niccol')
|
80
64
|
end
|
81
65
|
end
|
82
|
-
|
83
66
|
describe '#cast' do
|
84
|
-
|
85
|
-
FilmAffinity::Movie.new(504_889, 'El show de Truman (Una vida en directo)')
|
86
|
-
end
|
87
|
-
it 'should return an Array' do
|
67
|
+
it 'returns an Array' do
|
88
68
|
expect(movie.cast).to be_an(Array)
|
89
69
|
end
|
90
|
-
it '
|
70
|
+
it 'includes the passed cast' do
|
91
71
|
expected_cast = [
|
92
72
|
'Jim Carrey',
|
93
73
|
'Laura Linney',
|
@@ -97,138 +77,105 @@ describe 'FilmAffinity::Movie' do
|
|
97
77
|
expect(movie.cast).to include(*expected_cast)
|
98
78
|
end
|
99
79
|
end
|
100
|
-
|
101
80
|
describe '#company' do
|
102
|
-
|
103
|
-
FilmAffinity::Movie.new(504_889, 'El show de Truman (Una vida en directo)')
|
104
|
-
end
|
105
|
-
it 'should return a String' do
|
81
|
+
it 'returns a String' do
|
106
82
|
expect(movie.company).to be_a(String)
|
107
83
|
end
|
108
|
-
it '
|
109
|
-
expect(movie.company).to eq('Paramount Pictures
|
84
|
+
it 'returns "Paramount Pictures, Scott Rudin Productions"' do
|
85
|
+
expect(movie.company).to eq('Paramount Pictures, Scott Rudin Productions')
|
110
86
|
end
|
111
87
|
end
|
112
|
-
|
113
88
|
describe '#genres' do
|
114
|
-
|
115
|
-
FilmAffinity::Movie.new(504_889, 'El show de Truman (Una vida en directo)')
|
116
|
-
end
|
117
|
-
it 'should return an Array' do
|
89
|
+
it 'returns an Array' do
|
118
90
|
expect(movie.genres).to be_an(Array)
|
119
91
|
end
|
120
|
-
it '
|
92
|
+
it 'includes the passed genres' do
|
121
93
|
expected_genres = %w(Drama Comedy Satire)
|
122
94
|
expect(movie.genres).to include(*expected_genres)
|
123
95
|
end
|
124
96
|
end
|
125
|
-
|
126
97
|
describe '#poster' do
|
127
|
-
|
128
|
-
FilmAffinity::Movie.new(504_889, 'El show de Truman (Una vida en directo)')
|
129
|
-
end
|
130
|
-
it 'should return a String' do
|
98
|
+
it 'returns a String' do
|
131
99
|
expect(movie.poster).to be_a(String)
|
132
100
|
end
|
133
|
-
it '
|
101
|
+
it 'returns a .jpg address' do
|
134
102
|
expect(movie.poster).to include('.jpg')
|
135
103
|
end
|
136
104
|
end
|
137
105
|
end
|
138
106
|
|
139
107
|
context 'spanish version' do
|
140
|
-
before
|
108
|
+
before(:all) do
|
141
109
|
FilmAffinity.configure do |config|
|
142
110
|
config.language = 'ES'
|
143
111
|
end
|
144
112
|
end
|
145
113
|
|
114
|
+
after(:all) do
|
115
|
+
FilmAffinity.configure do |config|
|
116
|
+
config.language = 'EN'
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
146
120
|
describe '#title' do
|
147
121
|
subject(:movie) do
|
148
122
|
FilmAffinity::Movie.new(504_889)
|
149
123
|
end
|
150
|
-
|
124
|
+
|
125
|
+
it 'returns an valid title when initializes with no title' do
|
151
126
|
expect(movie.title).to eq('El show de Truman (Una vida en directo)')
|
152
127
|
end
|
153
128
|
end
|
154
|
-
|
155
129
|
describe '#rating' do
|
156
|
-
|
157
|
-
FilmAffinity::Movie.new(504_889, 'El show de Truman (Una vida en directo)')
|
158
|
-
end
|
159
|
-
it 'should return an Float' do
|
130
|
+
it 'returns an Float' do
|
160
131
|
expect(movie.rating).to be_a(Float)
|
161
132
|
end
|
162
133
|
end
|
163
|
-
|
164
134
|
describe '#year' do
|
165
|
-
|
166
|
-
|
167
|
-
end
|
168
|
-
it 'should return an Fixnum' do
|
169
|
-
expect(movie.year).to be_an(Fixnum)
|
135
|
+
it 'returns an Integer' do
|
136
|
+
expect(movie.year).to be_an(Integer)
|
170
137
|
end
|
171
|
-
it '
|
138
|
+
it 'returns 1998' do
|
172
139
|
expect(movie.year).to eq(1998)
|
173
140
|
end
|
174
141
|
end
|
175
|
-
|
176
142
|
describe '#duration' do
|
177
|
-
|
178
|
-
|
179
|
-
end
|
180
|
-
it 'should return an Fixnum' do
|
181
|
-
expect(movie.duration).to be_a(Fixnum)
|
143
|
+
it 'returns an Integer' do
|
144
|
+
expect(movie.duration).to be_a(Integer)
|
182
145
|
end
|
183
|
-
it '
|
146
|
+
it 'returns 103' do
|
184
147
|
expect(movie.duration).to eq(103)
|
185
148
|
end
|
186
149
|
end
|
187
|
-
|
188
150
|
describe '#country' do
|
189
|
-
|
190
|
-
FilmAffinity::Movie.new(504_889, 'El show de Truman (Una vida en directo)')
|
191
|
-
end
|
192
|
-
it 'should return a String' do
|
151
|
+
it 'returns a String' do
|
193
152
|
expect(movie.country).to be_a(String)
|
194
153
|
end
|
195
|
-
it '
|
154
|
+
it 'returns "Estados Unidos"' do
|
196
155
|
expect(movie.country).to eq('Estados Unidos')
|
197
156
|
end
|
198
157
|
end
|
199
|
-
|
200
158
|
describe '#director' do
|
201
|
-
|
202
|
-
FilmAffinity::Movie.new(504_889, 'El show de Truman (Una vida en directo)')
|
203
|
-
end
|
204
|
-
it 'should return a String' do
|
159
|
+
it 'returns a String' do
|
205
160
|
expect(movie.director).to be_a(String)
|
206
161
|
end
|
207
|
-
it '
|
162
|
+
it 'returns "Peter Weir"' do
|
208
163
|
expect(movie.director).to eq('Peter Weir')
|
209
164
|
end
|
210
165
|
end
|
211
|
-
|
212
166
|
describe '#script' do
|
213
|
-
|
214
|
-
FilmAffinity::Movie.new(504_889, 'El show de Truman (Una vida en directo)')
|
215
|
-
end
|
216
|
-
it 'should return a String' do
|
167
|
+
it 'returns a String' do
|
217
168
|
expect(movie.script).to be_a(String)
|
218
169
|
end
|
219
|
-
it '
|
170
|
+
it 'returns "Andrew Niccol"' do
|
220
171
|
expect(movie.script).to eq('Andrew Niccol')
|
221
172
|
end
|
222
173
|
end
|
223
|
-
|
224
174
|
describe '#cast' do
|
225
|
-
|
226
|
-
FilmAffinity::Movie.new(504_889, 'El show de Truman (Una vida en directo)')
|
227
|
-
end
|
228
|
-
it 'should return an Array' do
|
175
|
+
it 'returns an Array' do
|
229
176
|
expect(movie.cast).to be_an(Array)
|
230
177
|
end
|
231
|
-
it '
|
178
|
+
it 'includes the passed cast' do
|
232
179
|
expected_cast = [
|
233
180
|
'Jim Carrey',
|
234
181
|
'Laura Linney',
|
@@ -238,40 +185,28 @@ describe 'FilmAffinity::Movie' do
|
|
238
185
|
expect(movie.cast).to include(*expected_cast)
|
239
186
|
end
|
240
187
|
end
|
241
|
-
|
242
188
|
describe '#company' do
|
243
|
-
|
244
|
-
FilmAffinity::Movie.new(504_889, 'El show de Truman (Una vida en directo)')
|
245
|
-
end
|
246
|
-
it 'should return a String' do
|
189
|
+
it 'returns a String' do
|
247
190
|
expect(movie.company).to be_a(String)
|
248
191
|
end
|
249
|
-
it '
|
250
|
-
expect(movie.company).to eq('Paramount Pictures
|
192
|
+
it 'returns "Paramount Pictures, Scott Rudin Productions"' do
|
193
|
+
expect(movie.company).to eq('Paramount Pictures, Scott Rudin Productions')
|
251
194
|
end
|
252
195
|
end
|
253
|
-
|
254
196
|
describe '#genres' do
|
255
|
-
|
256
|
-
FilmAffinity::Movie.new(504_889, 'El show de Truman (Una vida en directo)')
|
257
|
-
end
|
258
|
-
it 'should return an Array' do
|
197
|
+
it 'returns an Array' do
|
259
198
|
expect(movie.genres).to be_an(Array)
|
260
199
|
end
|
261
|
-
it '
|
262
|
-
expected_genres = %w
|
200
|
+
it 'includes the passed genres' do
|
201
|
+
expected_genres = %w[Drama Comedia Sátira]
|
263
202
|
expect(movie.genres).to include(*expected_genres)
|
264
203
|
end
|
265
204
|
end
|
266
|
-
|
267
205
|
describe '#poster' do
|
268
|
-
|
269
|
-
FilmAffinity::Movie.new(504_889, 'El show de Truman (Una vida en directo)')
|
270
|
-
end
|
271
|
-
it 'should return a String' do
|
206
|
+
it 'returns a String' do
|
272
207
|
expect(movie.poster).to be_a(String)
|
273
208
|
end
|
274
|
-
it '
|
209
|
+
it 'returns a .jpg address' do
|
275
210
|
expect(movie.poster).to include('.jpg')
|
276
211
|
end
|
277
212
|
end
|
@@ -1,30 +1,23 @@
|
|
1
|
-
|
2
|
-
require_relative 'matchers/include-movie'
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
|
5
|
-
describe '#create_document_html' do
|
6
|
-
subject(:search) { FilmAffinity::Search.new('truman') }
|
7
|
-
|
8
|
-
it '#create_document_html' do
|
9
|
-
document_html = search.document_html
|
10
|
-
expect(document_html).to be_an(Nokogiri::HTML::Document)
|
11
|
-
end
|
12
|
-
end
|
3
|
+
require 'spec_helper'
|
13
4
|
|
5
|
+
describe FilmAffinity::Search, :vcr do
|
14
6
|
describe '#movies' do
|
15
7
|
subject(:search) { FilmAffinity::Search.new('truman') }
|
16
8
|
|
17
|
-
it '
|
9
|
+
it 'returns an array' do
|
18
10
|
movies = search.movies
|
19
11
|
expect(movies).to be_an(Array)
|
20
12
|
end
|
21
|
-
it '
|
22
|
-
|
23
|
-
movies.each { |movie| expect(movie).to be_an(FilmAffinity::Movie) }
|
13
|
+
it 'returns FilmAffinity::Movie objects only' do
|
14
|
+
expect(search.movies).to all(be_an(FilmAffinity::Movie))
|
24
15
|
end
|
25
|
-
it '
|
16
|
+
it 'includes the "The Truman Show"' do
|
26
17
|
movies = search.movies
|
27
|
-
truman_movie = FilmAffinity::Movie.new(
|
18
|
+
truman_movie = FilmAffinity::Movie.new(
|
19
|
+
504_889, 'The Truman Show'
|
20
|
+
)
|
28
21
|
expect(movies).to include_movie(truman_movie)
|
29
22
|
end
|
30
23
|
end
|
@@ -33,13 +26,13 @@ describe 'FilmAffinity::Search' do
|
|
33
26
|
# Get a direct result from a specific searchs
|
34
27
|
subject(:search) { FilmAffinity::Search.new('truman show') }
|
35
28
|
|
36
|
-
it '
|
29
|
+
it 'parses the id' do
|
37
30
|
id = 504_889
|
38
31
|
expect(id).to eq(search.movies.first.id)
|
39
32
|
end
|
40
33
|
|
41
|
-
it '
|
42
|
-
title = '
|
34
|
+
it 'parses the title' do
|
35
|
+
title = 'The Truman Show (1998)'
|
43
36
|
expect(title).to eq(search.movies.first.title)
|
44
37
|
end
|
45
38
|
end
|