CREDITS TO
#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#Renderingresponse.should render_template(:index)#Redirectingresponse.should redirect_to(movies_path)#Capybara Matchersresponse.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 responseresponse.body.should have_css("input", :maximum => 3) # True if there or fewer or equal to 3 input tagsresponse.body.should have_css("input", :minimum => 3) # True if there are minimum of 3 input tagsresponse.body.should have_css("input", :between => 1..3) # True if there 1 to 3 input tagsresponse.body.should have_css("p a", :text => "hello") # True if there is a anchor tag with text helloresponse.body.should have_css("p a", :text => /[hH]ello(.+)/i)# True if there is a anchor tag with text matching regexresponse.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_xpathresponse.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 selectorCapybara.default_selector = :cssresponse.body.should have_selector("input") #checks for the presence of the input tagresponse.body.should have_selector("input", :value =>"Twelve Angry Men") # checks for input tag with valueresponse.body.should have_no_selector("input")# For making capybara to take css as default selectorCapybara.default_selector = :xpathresponse.body.should have_selector("//input") #checks for the presence of the input tagresponse.body.should have_selector("//input", :value =>"Twelve Angry Men") # checks for input tag with value# To access elements inside formresponse.body.should have_field("FirstName") # checks for presence of a input field named FirstName in a formresponse.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")
1 comments:
It is a good blog. It is very helpful blog. Thank you for sharing this blog with us. Ruby on Rails Developers
Post a Comment