Guest User

Untitled

a guest
Mar 10th, 2018
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. ## stories/all.rb
  2.  
  3. dir = File.dirname(__FILE__)
  4.  
  5. $LOAD_PATH.unshift dir
  6. require 'helper'
  7.  
  8. Dir['stories/steps/**/*.rb'].each do |steps_file|
  9. require steps_file
  10. end
  11.  
  12. with_steps_for :login do
  13. run 'stories/base/login', :type => RailsStory
  14. end
  15.  
  16. ## stories/base/login
  17.  
  18. Story: logging in
  19.  
  20. Scenario: logging in as a normal user
  21. Given a user with normal privileges
  22. When I log in
  23. Then I should be redirected to /
  24.  
  25. Scenario: logging in as an admin
  26. Given a user with admin privileges
  27. When I log in
  28. Then I should be redirected to /admin
  29.  
  30. ## stories/steps/login.rb
  31.  
  32. steps_for(:login) do
  33. Given("a user with $privileges privileges") do |privileges|
  34. user = User.create(:email => 'user@example.com', :password => 'password')
  35. if privileges == 'admin'
  36. user.admin = true
  37. user.save!
  38. end
  39. end
  40.  
  41. When("I log in") do
  42. # how should I instead parse /login to determine what to do?
  43. get '/login'
  44. post '/session', :email => 'user@example.com', :password => 'password'
  45. end
  46.  
  47. Then("I should be redirected to $url") do |url|
  48. response.should redirect_to(url)
  49. end
  50. end
Add Comment
Please, Sign In to add comment