ratebeer 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c70ddcf6fcf1333ec57e5850602c692b568af608
4
+ data.tar.gz: 038beefda93b5cfef61bcb659612fe3cc6a77542
5
+ SHA512:
6
+ metadata.gz: fa2c44b45bf4bd24122daf95a8fd51e77eec9e582ee39b3eac4704cc4e7bec40ce3f89eaa4d5bbe825fedab60f62c8cb721a6aad494c49b3769e549134a7383d
7
+ data.tar.gz: 9efcfd028583c5fbde0584098ddb551e99ab663854621f5a5d3c29b603da40cec8c3729ae4d190ce4bc8b66f4a3073d0129ba7eb8cd10da42d4ee5cd701360c4
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "https://rubygems.org"
2
+ ruby "2.2.1"
3
+
4
+ gemspec
5
+
6
+ gem "i18n"
7
+ gem "nokogiri"
8
+
9
+ group :test do
10
+ gem "rspec"
11
+ gem "rake"
12
+ gem "codeclimate-test-reporter"
13
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,50 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ratebeer (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ codeclimate-test-reporter (0.4.8)
10
+ simplecov (>= 0.7.1, < 1.0.0)
11
+ diff-lcs (1.2.5)
12
+ docile (1.1.5)
13
+ i18n (0.7.0)
14
+ json (1.8.3)
15
+ mini_portile (0.6.2)
16
+ nokogiri (1.6.6.2)
17
+ mini_portile (~> 0.6.0)
18
+ rake (10.4.2)
19
+ rspec (3.3.0)
20
+ rspec-core (~> 3.3.0)
21
+ rspec-expectations (~> 3.3.0)
22
+ rspec-mocks (~> 3.3.0)
23
+ rspec-core (3.3.2)
24
+ rspec-support (~> 3.3.0)
25
+ rspec-expectations (3.3.1)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.3.0)
28
+ rspec-mocks (3.3.2)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.3.0)
31
+ rspec-support (3.3.0)
32
+ simplecov (0.10.0)
33
+ docile (~> 1.1.0)
34
+ json (~> 1.8)
35
+ simplecov-html (~> 0.10.0)
36
+ simplecov-html (0.10.0)
37
+
38
+ PLATFORMS
39
+ ruby
40
+
41
+ DEPENDENCIES
42
+ codeclimate-test-reporter
43
+ i18n
44
+ nokogiri
45
+ rake
46
+ ratebeer!
47
+ rspec
48
+
49
+ BUNDLED WITH
50
+ 1.10.6
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Dan Meakin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,64 @@
1
+ # RateBeer [![Build Status](https://travis-ci.org/DanMeakin/ratebeer.svg?branch=master)](https://travis-ci.org/DanMeakin/ratebeer) [![Code Climate](https://codeclimate.com/github/DanMeakin/ratebeer/badges/gpa.svg)](https://codeclimate.com/github/DanMeakin/ratebeer) [![Test Coverage](https://codeclimate.com/github/DanMeakin/ratebeer/badges/coverage.svg)](https://codeclimate.com/github/DanMeakin/ratebeer/coverage)
2
+ A Ruby scraper for RateBeer.com
3
+
4
+ ## Introduction
5
+
6
+ RateBeer is a scraper for RateBeer.com. At present, the library can be used to access data on beers, breweries, styles, countries and regions which are listed at RateBeer.com.
7
+
8
+ This library has been influenced by the [great Python RateBeer scraper by ajila](https://github.com/alilja/ratebeer).
9
+
10
+ ## Usage
11
+
12
+ The library provides access to a REPL which can be used to query RateBeer.com for the information accessible through this library. This is found at `/bin/ratebeer`. Alternatively, you can `require 'lib/ratebeer'` to use the library in your code.
13
+
14
+ A number of classes are provided by the library:-
15
+
16
+ * Beer;
17
+ * Brewery;
18
+ * Style;
19
+ * Country;
20
+ * Region; and
21
+ * Search.
22
+
23
+ The first five classes represent a details of that particular thing as provided by RateBeer.com. Each of these is lazy and will only retrieve data from the site when that data is requested (and where that data is not already present within the object - it is possible to pass known data to the constructor).
24
+
25
+ The search class represents a search conducted at the site, and will return beers and breweries which are matched.
26
+
27
+ ## Example
28
+
29
+ To conduct a search:-
30
+
31
+ ```ruby
32
+ > s = RateBeer::Search.new("punk ipa")
33
+ > s.beers
34
+ => [#<RateBeer::Beer #98939 - Berwick Atomic Punk IPA>,
35
+ #<RateBeer::Beer #72423 - BrewDog Punk IPA (6%)>,
36
+ #<RateBeer::Beer #135361 - BrewDog Punk IPA (5.6%)>,
37
+ #<RateBeer::Beer #81110 - BrewDog Punk IPA Speyside>,
38
+ #<RateBeer::Beer #193916 - Flying Dog / Brewdog / Push Brewing Punk Bitch IPA>,
39
+ #<RateBeer::Beer #132795 - Founders Hop Spit Punk Rock IPA>,
40
+ #<RateBeer::Beer #309419 - Fuggles & Warlock Draft Punk Rye IPA>,
41
+ #<RateBeer::Beer #218936 - Pateros Creek Punk Rock IPA>,
42
+ #<RateBeer::Beer #191045 - Push Brewing Knob Creek Punk Bitch IPA>,
43
+ #<RateBeer::Beer #100638 - Berwick Atomic Punk IPL (India Pale Lager)>,
44
+ #<RateBeer::Beer #209258 - Dieselpunk India Pale Ale>]
45
+ > s.breweries
46
+ => nil
47
+ > s.query = "brewdog"
48
+ > s.breweries
49
+ => [#<RateBeer::Brewery #8534 - BrewDog>]
50
+ ```
51
+
52
+ To use a beer instance, you can obtain one from a search or create one from a known beer ID:-
53
+
54
+ ```ruby
55
+ > b = RateBeer::Beer.new(72423)
56
+ > b.name
57
+ => "BrewDog Punk IPA (6%)"
58
+ > b.abv
59
+ => 6.0
60
+ > b.brewery
61
+ => #<RateBeer::Brewery #8534 - BrewDog>
62
+ ```
63
+
64
+ Accessible data keys can be found in the .data_keys method in each class.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ task :default => [:spec]
4
+
5
+ desc "Run the specs."
6
+ RSpec::Core::RakeTask.new do |t|
7
+ t.pattern = "spec/**/*_spec.rb"
8
+ end
data/bin/ratebeer ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ require 'irb'
3
+ require_relative '../lib/ratebeer'
4
+
5
+ puts
6
+ puts "########################"
7
+ puts "### RateBeer console ###"
8
+ puts "########################"
9
+ puts
10
+ puts "You can begin by looking-up a beer, brewery, or style by ID#, "\
11
+ "or by searching for a beer or brewery, using any of the 'beer', "\
12
+ "'brewery', 'style', or 'search' methods."
13
+ puts
14
+
15
+ include RateBeer
16
+ IRB.start
data/lib/ratebeer.rb ADDED
@@ -0,0 +1,51 @@
1
+ # RateBeer.com scraper
2
+ #
3
+ # Scrapes required information on beers, breweries, ratings, etc. from the
4
+ # RateBeer.com beer database.
5
+ #
6
+ Dir[File.expand_path("../ratebeer/*.rb", __FILE__)].each { |f| require f }
7
+
8
+ module RateBeer
9
+
10
+ # Create new beer instance, using ID and name passed as arguments.
11
+ #
12
+ # @param [Integer, String] id ID# of beer to retrieve
13
+ # @param [String] name Name of the beer to which ID# relates if known
14
+ # @return [RateBeer::Beer] beer with passed ID#
15
+ #
16
+ def beer(id, name=nil)
17
+ Beer.new(id, name: name)
18
+ end
19
+
20
+ # Create new brewery instance, using ID and name passed as arguments.
21
+ #
22
+ # @param [Integer, String] id ID# of brewery to retrieve
23
+ # @param [String] name Name of the brewery to which ID# relates if known
24
+ # @return [RateBeer::Brewery] brewery with passed ID#
25
+ #
26
+ def brewery(id, name=nil)
27
+ Brewery.new(id, name: name)
28
+ end
29
+
30
+ # Create new style instance, using ID and name passed as arguments.
31
+ #
32
+ # @param [Integer, String] id ID# of style to retrieve
33
+ # @param [String] name Name of the style to which ID# relates if known
34
+ # @return [RateBeer::Style] style with passed ID#
35
+ #
36
+ def style(id, name=nil)
37
+ Style.new(id, name: name)
38
+ end
39
+
40
+ # Search for a particulary beer or brewery.
41
+ #
42
+ # @param [String] query Search parameters to use
43
+ # @return [Hash<Array>] Hash containing Arrays containing RateBeer::Beer and
44
+ # RateBeer::Brewery instances matching search parameters
45
+ #
46
+ def search(query)
47
+ Search.search(query)
48
+ end
49
+
50
+ [:beer, :brewery, :style, :search].each { |f| module_function f }
51
+ end
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+
3
+ describe RateBeer::Beer do
4
+ before :all do
5
+ @valid = RateBeer::Beer.new(1411) # ID for Tennents Lager (sorry...)
6
+ @retired = RateBeer::Beer.new(213225) # ID for BrewDog Vice Bier
7
+ @with_name = RateBeer::Beer.new(422, name: "Stone IPA")
8
+ end
9
+
10
+ describe "#new" do
11
+ it "creates a beer instance" do
12
+ expect(@valid).to be_a RateBeer::Beer
13
+ end
14
+
15
+ it "requires an ID# as parameter" do
16
+ expect { RateBeer::Beer.new }.to raise_error(ArgumentError)
17
+ end
18
+
19
+ it "accepts a name parameter" do
20
+ expect(@with_name).to be_a RateBeer::Beer
21
+ end
22
+ end
23
+
24
+ describe "#name" do
25
+ it "retrieves name details from RateBeer if not present" do
26
+ expect(@valid.name).to eq "Tennents Lager"
27
+ end
28
+
29
+ it "uses name details if passed as parameter" do
30
+ expect(@with_name.name).to eq "Stone IPA"
31
+ end
32
+ end
33
+
34
+ describe "#retired" do
35
+ it "states that beer is retired when this is the case" do
36
+ expect(@valid.retired).to be false
37
+ expect(@retired.retired).to be true
38
+ end
39
+ end
40
+
41
+ describe "#full_details" do
42
+ it "returns full information about the beer" do
43
+ expect(@valid.full_details).to include(:id,
44
+ :name,
45
+ :brewery,
46
+ :url,
47
+ :style,
48
+ :glassware,
49
+ :availability,
50
+ :abv,
51
+ :calories,
52
+ :description,
53
+ :retired,
54
+ :rating)
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+
3
+ describe RateBeer::Brewery do
4
+ before :all do
5
+ @valid = RateBeer::Brewery.new(8534) # ID for BrewDog
6
+ @with_name = RateBeer::Brewery.new(1069, name: "Cantillon Brewery")
7
+ end
8
+
9
+ describe "#new" do
10
+ it "creates a brewery instance" do
11
+ expect(@valid).to be_a RateBeer::Brewery
12
+ end
13
+
14
+ it "requires an ID# as parameter" do
15
+ expect { RateBeer::Brewery.new }.to raise_error(ArgumentError)
16
+ end
17
+
18
+ it "accepts a name parameter" do
19
+ expect(@with_name).to be_a RateBeer::Brewery
20
+ end
21
+ end
22
+
23
+ describe "#name" do
24
+ it "retrieves name from RateBeer if not passed as parameter" do
25
+ expect(@valid.name).to eq "BrewDog"
26
+ end
27
+
28
+ it "uses name details if passed as parameter" do
29
+ expect(@with_name.name).to eq "Cantillon Brewery"
30
+ end
31
+ end
32
+
33
+ describe "#beers" do
34
+ it "returns a non-empty array of beers produced by the brewery" do
35
+ expect(@valid.beers).to_not be_empty
36
+ end
37
+
38
+ it "returns an array of beer instances" do
39
+ @valid.beers.each { |b| expect(b).to be_a RateBeer::Beer }
40
+ end
41
+
42
+ it "returns a list of beers produced by brewery" do
43
+ beers = [215065, 98242, 172237, 76701, 178585, 162521, 87321, 118987,
44
+ 119594].map { |id| RateBeer::Beer.new(id) }
45
+ expect(@valid.beers).to include(*beers)
46
+ end
47
+ end
48
+
49
+ describe "#full_details" do
50
+ it "returns full information about the brewery" do
51
+ expect(@valid.full_details).to include(:id,
52
+ :name,
53
+ :url,
54
+ :type,
55
+ :address,
56
+ :telephone,
57
+ :beers)
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,68 @@
1
+ require 'spec_helper'
2
+
3
+ describe RateBeer::Country do
4
+ before :all do
5
+ @country = RateBeer::Country.new(241) # Scotland
6
+ @invalid = RateBeer::Country.new(12345) # Invalid
7
+ @with_name = RateBeer::Country.new(14, name: "Oceania - Australia") # Australia
8
+ end
9
+
10
+ describe "#new" do
11
+ it "creates a new country instance" do
12
+ expect(@country).to be_a RateBeer::Country
13
+ end
14
+
15
+ it "requires an ID# as parameter" do
16
+ expect { RateBeer::Country.new }.to raise_error(ArgumentError)
17
+ end
18
+
19
+ it "accepts a name parameter" do
20
+ expect(@with_name).to be_a RateBeer::Country
21
+ end
22
+ end
23
+
24
+ describe "#name" do
25
+ it "retrives name from RateBeer if not passed as parameter" do
26
+ expect(@country.name).to eq "Scotland"
27
+ end
28
+
29
+ it "uses name details if passed as parameter" do
30
+ expect(@with_name.name).to eq "Oceania - Australia"
31
+ end
32
+ end
33
+
34
+ describe "#breweries" do
35
+ it "lists breweries within the country" do
36
+ expect(@country.breweries).to be_an Array
37
+ end
38
+
39
+ it "returns a series of RateBeer::Brewery instances" do
40
+ expected_breweries = [19163,
41
+ 2809,
42
+ 2878,
43
+ 11582,
44
+ 8031].map { |i| RateBeer::Brewery.new(i) }
45
+ expect(@country.breweries).to include(*expected_breweries)
46
+ end
47
+
48
+ end
49
+
50
+ describe "#full_details" do
51
+ it "raises error when invalid ID# passed" do
52
+ expect { @invalid.full_details }.to raise_error(RateBeer::Scraping::PageNotFoundError)
53
+ end
54
+
55
+ it "returns full information about this country" do
56
+ expect(@country.full_details).to_not be_empty
57
+ end
58
+
59
+ it "returns a hash with specified keys" do
60
+ expect(@country.full_details).to include(:id,
61
+ :name,
62
+ :url,
63
+ :top_styles,
64
+ :num_breweries,
65
+ :breweries)
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,68 @@
1
+ require 'spec_helper'
2
+
3
+ describe RateBeer::Region do
4
+ before :all do
5
+ @region = RateBeer::Region.new(5) # California
6
+ @invalid = RateBeer::Region.new(12345) # Invalid
7
+ @with_name = RateBeer::Region.new(79, name: "London") # Greater London
8
+ end
9
+
10
+ describe "#new" do
11
+ it "creates a new region instance" do
12
+ expect(@region).to be_a RateBeer::Region
13
+ end
14
+
15
+ it "requires an ID# as parameter" do
16
+ expect { RateBeer::Region.new }.to raise_error(ArgumentError)
17
+ end
18
+
19
+ it "accepts a name parameter" do
20
+ expect(@with_name).to be_a RateBeer::Region
21
+ end
22
+ end
23
+
24
+ describe "#name" do
25
+ it "retrives name from RateBeer if not passed as parameter" do
26
+ expect(@region.name).to eq "California"
27
+ end
28
+
29
+ it "uses name details if passed as parameter" do
30
+ expect(@with_name.name).to eq "London"
31
+ end
32
+ end
33
+
34
+ describe "#breweries" do
35
+ it "lists breweries within the region" do
36
+ expect(@region.breweries).to be_an Array
37
+ end
38
+
39
+ it "returns a series of RateBeer::Brewery instances" do
40
+ expected_breweries = [15430,
41
+ 108,
42
+ 19927,
43
+ 11855,
44
+ 8889].map { |i| RateBeer::Brewery.new(i) }
45
+ expect(@region.breweries).to include(*expected_breweries)
46
+ end
47
+
48
+ end
49
+
50
+ describe "#full_details" do
51
+ it "raises error when invalid ID# passed" do
52
+ expect { @invalid.full_details }.to raise_error(RateBeer::Scraping::PageNotFoundError)
53
+ end
54
+
55
+ it "returns full information about this region" do
56
+ expect(@region.full_details).to_not be_empty
57
+ end
58
+
59
+ it "returns a hash with specified keys" do
60
+ expect(@region.full_details).to include(:id,
61
+ :name,
62
+ :url,
63
+ :top_styles,
64
+ :num_breweries,
65
+ :breweries)
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,147 @@
1
+ require 'spec_helper'
2
+
3
+ describe RateBeer::Review do
4
+ before :all do
5
+ # Create Review instance with Beer instance
6
+ @beer = RateBeer::Beer.new(135361) # BrewDog Punk IPA
7
+ @constructed_params = { beer: @beer,
8
+ reviewer: "Johnny Tester",
9
+ reviewer_rank: 1234,
10
+ location: "The Moon",
11
+ date: Date.today,
12
+ rating: 4.00,
13
+ rating_breakdown: { overall: Rational(20, 20),
14
+ aroma: Rational(7, 10),
15
+ appearance: Rational(4, 5),
16
+ taste: Rational(9, 10),
17
+ palate: Rational(3, 5) },
18
+ comment: "Specimen review of this beer."}
19
+ @constructed = RateBeer::Review.new(@constructed_params)
20
+
21
+ # Create Review instance with beer ID#
22
+ @beer_id = 53
23
+ @params_with_beer_id = @constructed_params.dup.update(beer: @beer_id)
24
+ @constructed_with_beer_id = RateBeer::Review.new(@params_with_beer_id)
25
+ end
26
+
27
+ describe ".retrieve" do
28
+ before :all do
29
+
30
+ @retrieved = RateBeer::Review.retrieve(@beer)
31
+ @reviews_by_id = RateBeer::Review.retrieve(@beer_id)
32
+ # Test ordering
33
+ @recent = RateBeer::Review.retrieve(@beer, order: :most_recent)
34
+ @top_raters = RateBeer::Review.retrieve(@beer, order: :top_raters)
35
+ @highest_score = RateBeer::Review.retrieve(@beer, order: :highest_score)
36
+ # Test limit
37
+ @single_review = RateBeer::Review.retrieve(@beer, limit: 1)
38
+ @many_reviews = RateBeer::Review.retrieve(@beer, limit: 100)
39
+ end
40
+
41
+ it "retrieves reviews for the specified beer" do
42
+ @retrieved.each { |r| expect(r).to be_a RateBeer::Review }
43
+ end
44
+
45
+ it "recognises a beer specified by ID#" do
46
+ expect(@reviews_by_id.first.beer).to eq RateBeer::Beer.new(@beer_id)
47
+ end
48
+
49
+ it "retrieves reviews for beer specified by ID#" do
50
+ @reviews_by_id.each { |r| expect(r).to be_a RateBeer::Review }
51
+ end
52
+
53
+ it "retrieves ten reviews by default" do
54
+ expect(@retrieved.length).to eq 10
55
+ end
56
+
57
+ it "retrieves the most recent reviews by default" do
58
+ expect(@retrieved).to match_array @recent
59
+ end
60
+
61
+ it "retrieves the most recent reviews on request" do
62
+ @recent.each_cons(2).each { |r1, r2|
63
+ expect(r1.date).to be >= r2.date
64
+ }
65
+ end
66
+
67
+ it "retrieves reviews by the top raters on request" do
68
+ @top_raters.each_cons(2).each { |r1, r2|
69
+ expect(r1.reviewer_rank).to be >= r2.reviewer_rank
70
+ }
71
+ end
72
+
73
+ it "retrieves the highest rated reviews on request" do
74
+ @highest_score.each_cons(2).each { |r1, r2|
75
+ expect(r1.rating).to be >= r2.rating
76
+ }
77
+ end
78
+ end
79
+
80
+ describe ".url_suffix" do
81
+ it "returns a numerical suffix for valid ordering methods" do
82
+ { most_recent: "1",
83
+ top_raters: "2",
84
+ highest_score: "3" }.each { |k, v|
85
+ expect(RateBeer::Review.url_suffix(k)).to eq v
86
+ }
87
+ end
88
+
89
+ it "raises error when passed an invalid ordering method" do
90
+ invalid = :my_favourites
91
+ expect { RateBeer::Review.url_suffix(invalid) }.to raise_error(ArgumentError)
92
+ end
93
+ end
94
+
95
+ describe "#new" do
96
+ it "creates a review instance" do
97
+ expect(@constructed).to be_a RateBeer::Review
98
+ end
99
+
100
+ it "creates a review instance when passed a beer ID#" do
101
+ expect(@constructed_with_beer_id).to be_a RateBeer::Review
102
+ end
103
+
104
+ it "requires a full set of parameters" do
105
+ params = { beer: @beer,
106
+ reviewer: "Johnny Tester",
107
+ date: Date.today } # Rating & comment missing
108
+ expect { RateBeer::Review.new(params) }.to raise_error(ArgumentError)
109
+ end
110
+ end
111
+
112
+ describe "#reviewer" do
113
+ it "returns the name of the reviewer of the beer" do
114
+ expect(@constructed.reviewer).to eq @constructed_params[:reviewer]
115
+ end
116
+ end
117
+
118
+ describe "#beer" do
119
+ it "returns the beer reviewed" do
120
+ expect(@constructed.beer).to eq @constructed_params[:beer]
121
+ end
122
+ end
123
+
124
+ describe "#date" do
125
+ it "returns the date of the review" do
126
+ expect(@constructed.date).to eq @constructed_params[:date]
127
+ end
128
+ end
129
+
130
+ describe "#rating" do
131
+ it "returns the rating of the beer" do
132
+ expect(@constructed.rating).to eq @constructed_params[:rating]
133
+ end
134
+ end
135
+
136
+ describe "#rating_breakdown" do
137
+ it "returns the broken-down rating of the beer" do
138
+ expect(@constructed.rating_breakdown).to eq @constructed_params[:rating_breakdown]
139
+ end
140
+ end
141
+
142
+ describe "#comment" do
143
+ it "returns the comment attached to the review" do
144
+ expect(@constructed.comment).to eq @constructed_params[:comment]
145
+ end
146
+ end
147
+ end
@@ -0,0 +1,67 @@
1
+ require 'spec_helper'
2
+
3
+ describe RateBeer::Search do
4
+ describe "#new" do
5
+ before :all do
6
+ @search = RateBeer::Search.new("Testing Brewers Co Ltd")
7
+ end
8
+
9
+ it "creates a search instance" do
10
+ expect(@search).to be_a RateBeer::Search
11
+ end
12
+
13
+ it "removes generic terms from query parameter" do
14
+ expect(@search.query).to_not include("Brewers")
15
+ end
16
+ end
17
+
18
+ describe "#run_search" do
19
+ before :all do
20
+ @failed_search = RateBeer::Search.new("random parameter 1234").run_search
21
+ @successful_search = RateBeer::Search.new("heineken").run_search
22
+ end
23
+
24
+ it "executes a search using specified query parameter" do
25
+ expect(@failed_search).to_not be_nil
26
+ expect(@successful_search).to_not be_nil
27
+ end
28
+
29
+ it "returns nil for beers for non-matching query" do
30
+ expect(@failed_search.beers).to be_nil
31
+ end
32
+
33
+ it "returns nil for breweries for non-matching query" do
34
+ expect(@failed_search.breweries).to be_nil
35
+ end
36
+
37
+ it "returns a list of beers matching query parameter" do
38
+ expect(@successful_search.beers.count).to be > 0
39
+ end
40
+
41
+ it "returns a list of breweries matching query parameter" do
42
+ expect(@successful_search.breweries.count).to be > 0
43
+ end
44
+
45
+ it "returns a list of specific beers matching the query parameter" do
46
+ beers = @successful_search.beers
47
+ names = beers.map(&:name)
48
+ expect(names).to include("Heineken",
49
+ "Heineken Beer",
50
+ "Heineken Golden Fire Strong",
51
+ "Heineken Kylian",
52
+ "Heineken Oud Bruin",
53
+ "Heineken Tarwebok")
54
+
55
+ end
56
+
57
+ it "returns a list of specific breweries matching the query parameter" do
58
+ breweries = @successful_search.breweries
59
+ names = breweries.map(&:name)
60
+ expect(names).to include("Heineken UK",
61
+ "Heineken Italia",
62
+ "Al Ahram (Heineken)",
63
+ "Pivovar Corgon (Heineken)",
64
+ "Bralima (Heineken)")
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+
3
+ describe RateBeer::Style do
4
+ before :all do
5
+ @valid = RateBeer::Style.new(80)
6
+ @invalid = RateBeer::Style.new(12345)
7
+ @with_name = RateBeer::Style.new(11, name: "Barleywine")
8
+ @all_styles = RateBeer::Style.all_styles
9
+ end
10
+
11
+ describe ".all_styles" do
12
+ it "lists all styles" do
13
+ expect(@all_styles).to be_an Array
14
+ end
15
+
16
+ it "creates a list containing RateBeer::Style instances" do
17
+ @all_styles.each { |s| expect(s).to be_a RateBeer::Style }
18
+ end
19
+ end
20
+
21
+ describe "#new" do
22
+ it "creates a style instance" do
23
+ expect(@valid).to be_a RateBeer::Style
24
+ end
25
+
26
+ it "requires an ID# as parameter" do
27
+ expect { RateBeer::Style.new }.to raise_error(ArgumentError)
28
+ end
29
+
30
+ it "accepts a name parameter" do
31
+ expect(@with_name).to be_a RateBeer::Style
32
+ end
33
+ end
34
+
35
+ describe "#name" do
36
+ it "retrieves name from RateBeer if not passed as parameter" do
37
+ expect(@valid.name).to eq "Abt/Quadrupel"
38
+ end
39
+
40
+ it "uses name details if passed as parameter" do
41
+ expect(@with_name.name).to eq "Barleywine"
42
+ end
43
+ end
44
+
45
+ describe "#full_details" do
46
+ it "returns full information about the style" do
47
+ expect(@valid.full_details).to include(:id,
48
+ :name,
49
+ :description,
50
+ :glassware,
51
+ :beers)
52
+ end
53
+
54
+ it "raises error when invalid ID# passed" do
55
+ expect { @invalid.full_details }.to raise_error(RateBeer::Scraping::PageNotFoundError)
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe RateBeer do
4
+ describe ".beer" do
5
+ it "creates a new beer" do
6
+ beer = RateBeer.beer(1234, "Magic Lager")
7
+ expect(beer).to eq RateBeer::Beer.new(1234, name: "Magic Lager")
8
+ end
9
+ end
10
+
11
+ describe ".brewery" do
12
+ it "creates a new brewery" do
13
+ brewery = RateBeer.brewery(456, "Magic BrewCo")
14
+ expect(brewery).to eq RateBeer::Brewery.new(456, name: "Magic BrewCo")
15
+ end
16
+ end
17
+
18
+ describe ".style" do
19
+ it "creates a new style" do
20
+ style = RateBeer.style(99, "Butter Beer")
21
+ expect(style).to eq RateBeer::Style.new(99, name: "Butter Beer")
22
+ end
23
+ end
24
+
25
+ describe ".search" do
26
+ it "runs a new search query" do
27
+ search = RateBeer.search("pabst blue ribbon")
28
+ expect(search).to eq RateBeer::Search.search("pabst blue ribbon")
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,5 @@
1
+ require 'rspec'
2
+ require 'codeclimate-test-reporter'
3
+ CodeClimate::TestReporter.start
4
+
5
+ require_relative '../lib/ratebeer'
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ratebeer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Dan Meakin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-03 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: RateBeer provides a way to access beer & brewery data from RateBeer.com.
14
+ email: dan@danmeakin.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - Gemfile
20
+ - Gemfile.lock
21
+ - LICENSE
22
+ - README.md
23
+ - Rakefile
24
+ - bin/ratebeer
25
+ - lib/ratebeer.rb
26
+ - spec/lib/ratebeer/beer_spec.rb
27
+ - spec/lib/ratebeer/brewery_spec.rb
28
+ - spec/lib/ratebeer/country_spec.rb
29
+ - spec/lib/ratebeer/region_spec.rb
30
+ - spec/lib/ratebeer/review_spec.rb
31
+ - spec/lib/ratebeer/search_spec.rb
32
+ - spec/lib/ratebeer/style_spec.rb
33
+ - spec/lib/ratebeer_spec.rb
34
+ - spec/spec_helper.rb
35
+ homepage:
36
+ licenses: []
37
+ metadata: {}
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ requirements: []
53
+ rubyforge_project:
54
+ rubygems_version: 2.4.8
55
+ signing_key:
56
+ specification_version: 4
57
+ summary: Unofficial RateBeer API
58
+ test_files: []