Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 0. RSpec basics
- describe "Login system" do
- it "should not let me in" do
- # ...
- end
- it "something" do
- # ...
- end
- end
- # 1. Visiting a URL
- visit "/some/url"
- # 2. Visiting Link
- # In general, elements can be located by their inner text, their ‘title’ attribute,
- # their ‘name’ attribute, and their ‘id’ attribute.
- # They can be selected using a String, which is converted to an escaped
- # Regexp effectively making it a substring match, or using a Regexp.
- # An exception is that using Strings for ids are compared exactly (using ==)
- # rather than converted to a Regexp
- # If the element you are trying to look up does not exist, an error occurs
- click_link "Click here to join!" # substring text
- click_link /join/i # regexp text
- click_link "Sign up" # substring title
- click_link /sign.*up/i # regexp title
- click_link /signup.*link/i # regexp id
- click_link "signup_link" # exact id
- # 3. Filling Up a form
- fill_in "user_email", :with => "test@example.com" # exact id
- fill_in /user.*email/, :with => "test@example.com" # regexp id
- fill_in "user[email]", :with => "test@example.com" # substring name
- fill_in /user[.*mail.*]/, :with => "test@example.com" # substring name
- fill_in "Enter your Email", :with => "test@example.com" # substring label text
- fill_in /enter your email/i, :with => "test@example.com" # regexp label text
- # 4. Selecting from Drop Down
- # Select options can be ’selected’ by inner text (an exact String or a Regexp to match).
- # It can optionally be selected from a particular select field, using
- # the usual id, name, or label text.
- select "Free account"
- select "Free account", :from => "Account Types"
- select "Free account", :from => "user[account_type]"
- select "Free account", :from => "user_account_type"
- # 5. Check Boxes
- # Check boxes can be ‘checked’ and ‘unchecked’
- check 'Remember me'
- uncheck 'Remember me'
- # 6. Radio Buttons
- # Radio buttons can be also choosen, using the usual label text, name, or id.
- choose "Yes"
- # 7. Buttons
- click_button "Register"
- # 8. Content matcher
- response_body.should include "Wrong password"
- # 9. List matcher
- response_body.should have_list <<-EOS
- Login
- Sign up
- Home
- Howdy!
- EOS
- # 10. Table matcher
- response_body.should have_table <<-EOS
- Name | Foo | Bar
- teamon | 5 | Baz
- EOS
Add Comment
Please, Sign In to add comment