mirror of
https://github.com/iritmaximus/brewery.git
synced 2026-10-12 19:13:49 +03:00
5.3 implemented tests for BeermappingApi
This commit is contained in:
@@ -78,6 +78,7 @@ group :test do
|
||||
gem "launchy"
|
||||
gem "simplecov", require: false
|
||||
gem "rubocop"
|
||||
gem "webmock"
|
||||
end
|
||||
|
||||
|
||||
|
||||
@@ -86,6 +86,8 @@ GEM
|
||||
xpath (~> 3.2)
|
||||
coderay (1.1.3)
|
||||
concurrent-ruby (1.2.2)
|
||||
crack (0.4.5)
|
||||
rexml
|
||||
crass (1.0.6)
|
||||
date (3.3.4)
|
||||
debug (1.8.0)
|
||||
@@ -103,6 +105,7 @@ GEM
|
||||
railties (>= 5.0.0)
|
||||
globalid (1.2.1)
|
||||
activesupport (>= 6.1)
|
||||
hashdiff (1.0.1)
|
||||
httparty (0.21.0)
|
||||
mini_mime (>= 1.0.0)
|
||||
multi_xml (>= 0.5.2)
|
||||
@@ -282,6 +285,10 @@ GEM
|
||||
nokogiri (~> 1.6)
|
||||
rubyzip (>= 1.3.0)
|
||||
selenium-webdriver (~> 4.0, < 4.11)
|
||||
webmock (3.19.1)
|
||||
addressable (>= 2.8.0)
|
||||
crack (>= 0.3.2)
|
||||
hashdiff (>= 0.4.0, < 2.0.0)
|
||||
websocket (1.2.10)
|
||||
websocket-driver (0.7.6)
|
||||
websocket-extensions (>= 0.1.0)
|
||||
@@ -321,6 +328,7 @@ DEPENDENCIES
|
||||
tzinfo-data
|
||||
web-console
|
||||
webdrivers
|
||||
webmock
|
||||
|
||||
RUBY VERSION
|
||||
ruby 3.1.4p223
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe "Places" do
|
||||
it "displays a place if one is returned from the api" do
|
||||
allow(BeermappingApi).to receive(:places_in).with("kumpula").and_return(
|
||||
[ Place.new( name: "Oljenkorsi", id: 1 ) ]
|
||||
)
|
||||
|
||||
visit places_path
|
||||
fill_in("city", with: "kumpula")
|
||||
click_button "Search"
|
||||
|
||||
expect(page).to have_content "Oljenkorsi"
|
||||
end
|
||||
|
||||
it "displays all places if multiple are returned from the api" do
|
||||
allow(BeermappingApi).to receive(:places_in).with("kumpula").and_return(
|
||||
[ Place.new( name: "Oljenkorsi", id: 1 ), Place.new( name: "Emt mitä paikkoja kumpulassa on", id: 2), Place.new( name: ":D", id: 3) ]
|
||||
)
|
||||
|
||||
visit places_path
|
||||
fill_in("city", with: "kumpula")
|
||||
click_button "Search"
|
||||
|
||||
expect(page).to have_content "Oljenkorsi"
|
||||
expect(page).to have_content "Emt mitä paikkoja kumpulassa on"
|
||||
expect(page).to have_content ":D"
|
||||
end
|
||||
|
||||
it "displays 'No locations in _city_' if none is returned by the api" do
|
||||
allow(BeermappingApi).to receive(:places_in).with("kumpula").and_return(
|
||||
[]
|
||||
)
|
||||
|
||||
visit places_path
|
||||
fill_in("city", with: "kumpula")
|
||||
click_button "Search"
|
||||
|
||||
expect(page).to have_content "No locations in kumpula"
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,39 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe "Beermapping API" do
|
||||
it "when HTTP GET returns one entry, it is parsed and returned" do
|
||||
|
||||
http_response_body = <<-END_OF_STRING
|
||||
<?xml version='1.0' encoding='utf-8' ?><bmp_locations><location><id>18856</id><name>Panimoravintola Koulu</name><status>Brewpub</status><reviewlink>https://beermapping.com/location/18856</reviewlink><proxylink>http://beermapping.com/maps/proxymaps.php?locid=18856&d=5</proxylink><blogmap>http://beermapping.com/maps/blogproxy.php?locid=18856&d=1&type=norm</blogmap><street>Eerikinkatu 18</street><city>Turku</city><state></state><zip>20100</zip><country>Finland</country><phone>(02) 274 5757</phone><overall>0</overall><imagecount>0</imagecount></location></bmp_locations>
|
||||
END_OF_STRING
|
||||
stub_request(:get, /.*turku/).to_return(body: http_response_body, headers: { "Content-Type" => "text/xml" })
|
||||
|
||||
places = BeermappingApi.places_in("turku")
|
||||
|
||||
expect(places.size).to eq 1
|
||||
|
||||
place = places.first
|
||||
expect(place.name).to eq "Panimoravintola Koulu"
|
||||
expect(place.street).to eq "Eerikinkatu 18"
|
||||
end
|
||||
|
||||
it "should return empty array when no places are returned from api" do
|
||||
http_response_body = <<-END_OF_STRING
|
||||
<?xml version='1.0' encoding='utf-8' ?><bmp_locations><location><id>6742</id><name>Pullman Bar</name><status>Beer Bar</status><reviewlink>https://beermapping.com/location/6742</reviewlink><proxylink>http://beermapping.com/maps/proxymaps.php?locid=6742&d=5</proxylink><blogmap>http://beermapping.com/maps/blogproxy.php?locid=6742&d=1&type=norm</blogmap><street>Kaivokatu 1</street><city>Helsinki</city><state></state><zip>00100</zip><country>Finland</country><phone>+358 9 0307 22</phone><overall>72.500025</overall><imagecount>0</imagecount></location><location><id>6743</id><name>Belge</name><status>Beer Bar</status><reviewlink>https://beermapping.com/location/6743</reviewlink><proxylink>http://beermapping.com/maps/proxymaps.php?locid=6743&d=5</proxylink><blogmap>http://beermapping.com/maps/blogproxy.php?locid=6743&d=1&type=norm</blogmap><street>Kluuvikatu 5</street><city>Helsinki</city><state></state><zip>00100</zip><country>Finland</country><phone>+358 10 766 35</phone><overall>67.499925</overall><imagecount>1</imagecount></location></bmp_locations>
|
||||
END_OF_STRING
|
||||
stub_request(:get, /.*helsinki/).to_return(body: http_response_body, headers: { "Content-Type": "text/xml" })
|
||||
|
||||
places = BeermappingApi.places_in("helsinki")
|
||||
first_place = places[0]
|
||||
second_place = places[1]
|
||||
|
||||
expect(first_place.name).to eq "Pullman Bar"
|
||||
expect(first_place.street).to eq "Kaivokatu 1"
|
||||
|
||||
expect(second_place.name).to eq "Belge"
|
||||
expect(second_place.street).to eq "Kluuvikatu 5"
|
||||
|
||||
expect(first_place.class).to eq Place
|
||||
expect(second_place.class).to eq Place
|
||||
end
|
||||
end
|
||||
@@ -7,6 +7,8 @@ abort("The Rails environment is running in production mode!") if Rails.env.produ
|
||||
require 'rspec/rails'
|
||||
# Add additional requires below this line. Rails is not loaded until this point!
|
||||
|
||||
require 'webmock/rspec'
|
||||
|
||||
# Requires supporting ruby files with custom matchers and macros, etc, in
|
||||
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
|
||||
# run as spec files by default. This means that files in spec/support that end
|
||||
|
||||
Reference in New Issue
Block a user