Created
March 14, 2015 16:53
-
-
Save whatisinternet/15e80a0d5150d1bfbe68 to your computer and use it in GitHub Desktop.
pizza-pizza
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'capybara' | |
require 'capybara/dsl' | |
require 'selenium-webdriver' | |
Capybara.default_driver = :webkit | |
Capybara.run_server = false | |
module Pizza | |
class PizzaPizza | |
attr_accessor :pizza_types, :pizzas, :city, :delivery, :phoenix, :pizza_count | |
include Capybara::DSL | |
Capybara.current_driver = :selenium | |
def initialize(city, delivery, people) | |
medium = 8 | |
self.pizzas = ( people * 2.5 ) / medium | |
self.city = city.to_s | |
self.delivery = delivery.to_s | |
self.pizza_count = 0 | |
self.pizza_types = { | |
medium_peperoni: 'M1P', | |
medium_suprime: 'MSU', | |
canadian: 'FICAN', | |
medium_veggie: 'MVG', | |
medium_meat_suprime: 'MME' | |
} | |
self.phoenix = '/PhoenixWEB/order/#cat/10010/' | |
end | |
def visit_pizza | |
Capybara.app_host = 'https://order.pizzapizza.ca' | |
visit('/') | |
set_location | |
end | |
def set_location | |
sleep(2.5) | |
fill_in 'cityInput', :with => "#{self.city}" | |
find('#geolocation_continue').click | |
end | |
def add_pizzas | |
while self.pizza_count < self.pizzas | |
add_some_pizzas | |
end | |
end | |
def add_some_pizzas | |
self.pizza_types.each do |pizza_title, uri| | |
self.pizza_count += 1 | |
sleep(2.5) | |
add_a_pizza(pizza_title, uri) | |
sleep(2.5) | |
select_delivery | |
break unless self.pizza_count < self.pizzas | |
end | |
end | |
def add_a_pizza(pizza_title, uri) | |
visit("#{self.phoenix}#{uri}") | |
sleep(3) | |
puts "Adding: #{pizza_title}" | |
find('.add_to_order').click | |
end | |
def select_delivery | |
begin | |
find(".#{self.delivery}").click | |
rescue | |
end | |
end | |
def checkout | |
print "About to order is that ok? [enter]" | |
gets | |
find('.checkout').click | |
end | |
def unregistered_corder | |
puts "Ok for an Unregistered order? [enter]" | |
gets | |
find('.unregistered').click | |
gets | |
end | |
end | |
end | |
def main(city, delivery, people) | |
pizza = Pizza::PizzaPizza.new(city, delivery, people) | |
pizza.visit_pizza | |
pizza.add_pizzas | |
pizza.checkout | |
pizza.unregistered_corder | |
end | |
main( "waterloo", 'delivery', 5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment