Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 21st, 2012  |  syntax: None  |  size: 1.97 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. require 'acceptance/acceptance_helper'
  2.  
  3.  
  4.  
  5. feature 'Signup:', %q{
  6.   In order to start using the app
  7.   Users should be able to signup
  8.   And link with an OAuth provider
  9. } do
  10.  
  11.   #VCR will record interactions if cassette file doesn't exist, otherwise it will use what's in the cassette
  12.   use_vcr_cassette 'registration', :record => :once
  13.  
  14.   #This is a nice little tweak, that saves the current state of the browser on a spec fail and opens it
  15.   after do
  16.     if example.exception
  17.       page.driver.render('testoutput.png')
  18.       `open testoutput.png`
  19.     end
  20.   end
  21.  
  22.  
  23.  
  24.   background do
  25.     visit '/users/sign_up
  26.   end
  27.  
  28.   #If your app relies on JS, don't forget :js => true, or you will hate yourself
  29.   scenario 'create an account', :js => true do
  30.  
  31.     #skips any jQuery animations, for speed
  32.     page.driver.evaluate_script('$.fx.off = true')
  33.    
  34.     #First we just want to fill in the form and submit
  35.     fill_fields({
  36.       "First name" => "Philip",
  37.       "Last name" => "Roberts",
  38.       "Company" => "Float",
  39.       "Email" => 'phil@floatapp.com',
  40.       "Choose your password" => "password"
  41.     })
  42.    
  43.     click_button "Start your free trial!"
  44.  
  45.     # This is where it gets interesting. If we are recording the VCR cassette, we want to
  46.     # actually go through the interaction with the third party. These steps will depend on the
  47.     # third-party
  48.     if VCR.current_cassette.recording?
  49.       page.should have_content 'Please log in'
  50.       fill_fields({
  51.         :email => "my_username",
  52.         :password => "my_password"
  53.       })
  54.       find(:css, 'input[type=submit]').click
  55.       find(:css, 'a[href="grant_approval"]').click
  56.  
  57.       # This will take us back to our callback /oauth/callback with a real code.
  58.       # This code will be upgraded, and all the interactions for doing so will be recorded for next time
  59.     else
  60.       #If we are not recording, skip the third party stuff, and use the recorded token upgrade
  61.       visit '/oauth/callback?code=fake'
  62.     end
  63.  
  64.     page.should have_content "Welcome!"
  65.  
  66.   end
  67. end