Forked from them0nk/rspec_rails_cheetsheet.rb
Created
February 24, 2014 21:48
Revisions
-
them0nk revised this gist
Mar 24, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ #Model @user.should have(1).error_on(:username) # Checks whether there is an error in username @user.errors[:username].should include("can't be blank") # check for the error message #Rendering response.should render_template(:index) -
them0nk revised this gist
Mar 24, 2012 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,8 @@ #Model @user.should have(1).error_on(:username) # Checks whether there is an error in username #Rendering response.should render_template(:index) -
them0nk revised this gist
Mar 23, 2012 . 1 changed file with 13 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -21,15 +21,26 @@ response.body.should have_xpath("//a") response.body.should have_xpath("//a",:href => "google.com") response.body.should have_xpath("//a[@href => 'google.com']") response.body.should have_xpath("//a[contains(.,'some string')]") response.body.should have_xpath("//p//a", :text => /re[dab]i/i, :count => 1) # can take both xpath and css as input and can take arguments similar to both have_css and have_xpath response.body.should have_selector(:xpath, "//p/h1") response.body.should have_selector(:css, "p a#movie_edit_path") # For making capybara to take css as default selector Capybara.default_selector = :css response.body.should have_selector("input") #checks for the presence of the input tag response.body.should have_selector("input", :value =>"Twelve Angry Men") # checks for input tag with value response.body.should have_no_selector("input") # For making capybara to take css as default selector Capybara.default_selector = :xpath response.body.should have_selector("//input") #checks for the presence of the input tag response.body.should have_selector("//input", :value =>"Twelve Angry Men") # checks for input tag with value # To access elements inside form response.body.should have_field("FirstName") # checks for presence of a input field named FirstName in a form -
them0nk revised this gist
Mar 23, 2012 . 1 changed file with 10 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,15 +4,11 @@ #Redirecting response.should redirect_to(movies_path) #Capybara Matchers response.body.should have_content("Hello world") response.body.should have_no_content("Hello world") response.body.should have_css("input#movie_title") response.body.should have_css("input#movie_title", :value => "Twelve Angry Men") response.body.should have_css("input", :count => 3) #True if there are 3 input tags in response @@ -26,6 +22,15 @@ response.body.should have_xpath("//a") response.body.should have_xpath("//a",:href => "google.com") # can take both xpath and css as input and can take arguments similar to both have_css and have_xpath response.body.should have_selector("input") #checks for the presence of the input tag response.body.should have_selector("input", :value =>"Twelve Angry Men") # checks for input tag with value response.body.should have_no_selector("input") response.body.should have_selector(:xpath, "//p/h1") response.body.should have_selector(:css, "p a#movie_edit_path") # To access elements inside form response.body.should have_field("FirstName") # checks for presence of a input field named FirstName in a form response.body.should have_field("FirstName", :value => "Rambo") -
them0nk revised this gist
Mar 23, 2012 . 1 changed file with 16 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -15,8 +15,24 @@ response.body.should have_css("input#movie_title") response.body.should have_css("input#movie_title", :value => "Twelve Angry Men") response.body.should have_css("input", :count => 3) #True if there are 3 input tags in response response.body.should have_css("input", :maximum => 3) # True if there or fewer or equal to 3 input tags response.body.should have_css("input", :minimum => 3) # True if there are minimum of 3 input tags response.body.should have_css("input", :between => 1..3) # True if there 1 to 3 input tags response.body.should have_css("p a", :text => "hello") # True if there is a anchor tag with text hello response.body.should have_css("p a", :text => /[hH]ello(.+)/i) # True if there is a anchor tag with text matching regex response.body.should have_xpath("//a") response.body.should have_xpath("//a",:href => "google.com") # To access elements inside form response.body.should have_field("FirstName") # checks for presence of a input field named FirstName in a form response.body.should have_field("FirstName", :value => "Rambo") response.body.should have_field("FirstName", :with => "Rambo") response.body.should have_link("Foo") response.body.should have_link("Foo", :href=>"googl.com") response.body.should have_no_link("Foo", :href=>"google.com") -
them0nk revised this gist
Mar 23, 2012 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -14,7 +14,9 @@ response.body.should have_no_selector("input") response.body.should have_css("input#movie_title") response.body.should have_css("input#movie_title", :value => "Twelve Angry Men") response.body.should have_xpath("//a") response.body.should have_xpath("//a",:href => "google.com") -
them0nk revised this gist
Mar 23, 2012 . 1 changed file with 13 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,20 @@ #Rendering response.should render_template(:index) #Redirecting response.should redirect_to(movies_path) #Matchers response.body.should have_content("Hello world") response.body.should have_no_content("Hello world") response.body.should have_selector("input") #checks for the presence of the input tag response.body.should have_selector("input", :value =>"Twelve Angry Men") # checks for input tag with value response.body.should have_no_selector("input") response.body.should have_css("input#movie_title") -
them0nk revised this gist
Mar 23, 2012 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,3 @@ #Rendering & Redirecting response.should render_template(:index) -
them0nk created this gist
Mar 23, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ #Rendering & Redirecting response.should render_template(:index) response.should redirect_to(movies_path) #Matching response.body.should have_content("Hello world")