Skip to content

Instantly share code, notes, and snippets.

@jherdman
Forked from batasrki/pricing.feature
Created December 1, 2010 17:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jherdman/723814 to your computer and use it in GitHub Desktop.
Save jherdman/723814 to your computer and use it in GitHub Desktop.
Feature: Pricing
In order to purchase two items from the store
As a Store user
I should be able to add two items and checkout with the right price displayed
Scenario: Successful checkout
Given the user adds the "Unique Ability" product to the cart
And then adds "Strategy Circle Software" product to the cart
When the user views the cart, it should have 2 items totalling "$130"
Then the user logs in and confirms the right price
And checks out confirming right "shipping" and "taxes"
Given /^the user adds the "([^\"]*)" product to the cart$/ do |product_name|
@unique_ability = Product.first(:conditions => "name like '#{product_name}%'")
@unique_ability.should_not be_nil
host! 'private.store.local'
visit store_product_url(@unique_ability)
response.should have_selector("a[id=add_to_order]")
click_link("add to order")
package = @unique_ability.packages.first
visit "/store/add_to_cart/#{package.id}?product_id=#{@unique_ability.id}"
end
Given /^then adds "([^"]*)" product to the cart$/ do |product_name|
@strategy_software = Product.first(:conditions => "name like '%#{product_name}%'")
@strategy_software.should_not be_nil
host! 'private.store.local'
visit store_product_url(@strategy_software)
response.should have_selector("a[id=add_to_order]")
package = @strategy_software.packages.first
visit "/store/add_to_cart/#{package.id}?product_id=#{@strategy_software.id}"
end
When /^the user views the cart, it should have (\d+) items totalling "([^"]*)"$/ do |number_of_items, price|
host! 'private.store.local'
visit "/cart"
response.should have_selector("span[class=ordersub]")
response.should contain(price)
end
Then /^I should see (\d+) items? in the cart$/ do |num|
response.should have_selector("span.ordersub", :count => num.to_i)
end
Then /^I the cart should have a total of "([^"]*)"$/ do |total|
response.should contain(total)
end
Then /^the user logs in and confirms the right price$/ do
host! 'private.store.local'
click_link "checkout"
visit "/account/login"
fill_in :user_login, :with => "bobdabuilder"
fill_in :user_password, :with => "test"
click_button("b_login")
User.find_by_login("bobdabuilder").user_type_name.should == "Store User"
visit "/checkout/checkout"
response.should contain("130")
fill_in :order_card_number, :with => "4511111111111111"
select "Ontario", :from => "order_bill_province_CA"
select "06", :from => "order_card_expiry_month"
select "2012", :from => "order_card_expiry_year"
submit_form "entryform"
host! 'private.store.local'
visit 'checkout/checkout_process'
end
Then /^checks out confirming right "([^"]*)" and "([^"]*)"$/ do |shipping, taxes|
host! 'private.store.local'
visit 'checkout/checkout_preview'
response.should have_selector("td#shipping_charge", :content => "10.95")
response.should have_selector("td#tax_hst", :content => "15.12")
response.should have_selector("span.ordersub", :content => "156.07")
click_button "submit_order"
response.should contain(/success\/(\d)+$/) #fails here
id = $1
puts id
host! 'private.store.local'
visit "checkout/success/#{id}"
response.should have_selector("h2.tophead", :content => "Your order has been placed")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment