Guest User

Untitled

a guest
Mar 8th, 2018
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. require File.join(File.dirname(__FILE__), "helper")
  2.  
  3. Story "users visiting the homepage", %{
  4. As an user
  5. I should see information based on based on authentication
  6. So that I can see relative content
  7. }, :type => RailsStory do
  8.  
  9. Scenario "anonymous user visting the home page" do
  10. Given "the user is anonymous" do
  11. @current_user.should be_nil #example of checking
  12. end
  13. When "visiting home page" do
  14. get "/"
  15. end
  16. Then "user should see", "site_pages/_frontpage" do |partial|
  17. response.should render_template(partial)
  18. end
  19. And "the page should show", "Sign up and become a member!", do |message|
  20. response.should have_text(/#{message}/)
  21. end
  22. end
  23.  
  24. Scenario "authenticated user visting the home page" do
  25. Given "the user is", "anonymous" do | login |
  26. @current_user.should be_nil #example of checking
  27. end
  28. When "visiting home page" do
  29. get "/"
  30. end
  31. Then "user should see", "site_pages/_anon_welcome" do |partial|
  32. response.should render_template(partial)
  33. end
  34. And "the page should show", "Sign up and become a member!", do |message|
  35. response.should have_text(/#{message}/)
  36. end
  37. end
  38.  
  39. Scenario "vistiing the about page" do
  40. Given "the user named", "Jon" do |login|
  41. @user = current_user login
  42. end
  43. Given "the user is logged in" do
  44. post_via_redirect "/session", :login => "Jon", :password => "testing"
  45. end
  46. When "visiting home page" do
  47. get "/"
  48. end
  49. Then "user should see", "site_pages/_user_welcome" do |partial|
  50. response.should render_template(partial)
  51. end
  52. And "the page should show", "Welcome back! #{@user.name}", do |message|
  53. response.should have_text(/#{message}/)
  54. end
  55. end
  56.  
  57. end
  58.  
  59. def current_user(login)
  60. user = User.create!(
  61. :login => login,
  62. :email => "test@localhost.com",
  63. :password => "testing",
  64. :password_confirmation => "testing")
  65. user
  66. end
  67.  
  68. end
Add Comment
Please, Sign In to add comment