Advertisement
Guest User

Untitled

a guest
May 28th, 2015
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. require "test_helper"
  3.  
  4. feature "Shopping" do
  5. scenario "add several items to the cart and check out", js: true do
  6. # Go to the store's homepage
  7. visit root_path
  8. cart_must_be_empty
  9.  
  10. # Add the first item to the cart.
  11. entries = page.all(".entry_list .entry")
  12.  
  13. product1 = product_for_entry(entries.first)
  14. add_to_cart(entries.first, product1)
  15. total_price_must_be(product1.price)
  16.  
  17. # Add the last item to the cart.
  18. product2 = product_for_entry(entries.last)
  19. add_to_cart(entries.last, product2)
  20. total_price_must_be(product1.price + product2.price)
  21.  
  22. # Check out.
  23. complete_order
  24.  
  25. # See the order confirmed.
  26. cart_must_be_empty
  27. page.must_have_css("#notice", text: "Thank you for your order.")
  28. end
  29.  
  30. def cart_must_be_empty
  31. within("#cart") do
  32. page.must_have_css(".contents", text: "Your cart is empty.")
  33. page.must_have_css(".total_line .price", text: "$0.00")
  34. end
  35. end
  36.  
  37. def product_for_entry(entry)
  38. id = entry[:id].sub(/entry_/, "")
  39. Product.find(id)
  40. end
  41.  
  42. def add_to_cart(entry, product = nil)
  43. product ||= product_for_entry(entry)
  44.  
  45. within(entry) do
  46. click_button("Add to Cart")
  47. end
  48.  
  49. within("#cart .current_item") do
  50. page.must_have_css(".quantity", text: "1×")
  51. page.must_have_css(".title", text: product.title)
  52. page.must_have_css(".price", text: sprintf("$%.2f", product.price))
  53. end
  54.  
  55. product
  56. end
  57.  
  58. def total_price_must_be(amount)
  59. page.must_have_css("#cart .total_line .price",
  60. text: sprintf("$%.2f", amount))
  61. end
  62.  
  63. def complete_order
  64. find("#cart").find_button("Checkout").click
  65.  
  66. within("form#new_order") do
  67. fill_in("Name", with: "Bill Lumbergh")
  68. fill_in("Address", with: "123 Shady Tree Lane")
  69. fill_in("Email", with: "da_boss@initech.com")
  70. select("Purchase Order", from: "Pay type")
  71. click_button("Create Order")
  72. end
  73. end
  74. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement