Guest User

Untitled

a guest
Apr 8th, 2018
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. # 0. RSpec basics
  2.  
  3. describe "Login system" do
  4. it "should not let me in" do
  5. # ...
  6. end
  7.  
  8. it "something" do
  9. # ...
  10. end
  11. end
  12.  
  13. # 1. Visiting a URL
  14. visit "/some/url"
  15.  
  16. # 2. Visiting Link
  17. # In general, elements can be located by their inner text, their ‘title’ attribute,
  18. # their ‘name’ attribute, and their ‘id’ attribute.
  19. # They can be selected using a String, which is converted to an escaped
  20. # Regexp effectively making it a substring match, or using a Regexp.
  21. # An exception is that using Strings for ids are compared exactly (using ==)
  22. # rather than converted to a Regexp
  23. # If the element you are trying to look up does not exist, an error occurs
  24. click_link "Click here to join!" # substring text
  25. click_link /join/i # regexp text
  26. click_link "Sign up" # substring title
  27. click_link /sign.*up/i # regexp title
  28. click_link /signup.*link/i # regexp id
  29. click_link "signup_link" # exact id
  30.  
  31.  
  32.  
  33. # 3. Filling Up a form
  34. fill_in "user_email", :with => "test@example.com" # exact id
  35. fill_in /user.*email/, :with => "test@example.com" # regexp id
  36. fill_in "user[email]", :with => "test@example.com" # substring name
  37. fill_in /user[.*mail.*]/, :with => "test@example.com" # substring name
  38. fill_in "Enter your Email", :with => "test@example.com" # substring label text
  39. fill_in /enter your email/i, :with => "test@example.com" # regexp label text
  40.  
  41.  
  42. # 4. Selecting from Drop Down
  43. # Select options can be ’selected’ by inner text (an exact String or a Regexp to match).
  44. # It can optionally be selected from a particular select field, using
  45. # the usual id, name, or label text.
  46. select "Free account"
  47. select "Free account", :from => "Account Types"
  48. select "Free account", :from => "user[account_type]"
  49. select "Free account", :from => "user_account_type"
  50.  
  51.  
  52. # 5. Check Boxes
  53. # Check boxes can be ‘checked’ and ‘unchecked’
  54. check 'Remember me'
  55. uncheck 'Remember me'
  56.  
  57.  
  58. # 6. Radio Buttons
  59. # Radio buttons can be also choosen, using the usual label text, name, or id.
  60. choose "Yes"
  61.  
  62.  
  63. # 7. Buttons
  64. click_button "Register"
  65.  
  66.  
  67. # 8. Content matcher
  68. response_body.should include "Wrong password"
  69.  
  70.  
  71. # 9. List matcher
  72. response_body.should have_list <<-EOS
  73. Login
  74. Sign up
  75. Home
  76. Howdy!
  77. EOS
  78.  
  79.  
  80. # 10. Table matcher
  81. response_body.should have_table <<-EOS
  82. Name | Foo | Bar
  83. teamon | 5 | Baz
  84. EOS
Add Comment
Please, Sign In to add comment