Contenu connexe Similaire à Acceptance Testing with Webrat (20) Acceptance Testing with Webrat1. Acceptance Testing
with Webrat
Luismi Cavallé
http://twitter.com/cavalle
http://lmcavalle.com
http://spainrb.org/luismi-cavalle
5. Webrat
#get #post #head #delete ...
#put #request #follow_redirect!
ActionController:: Nokogiri
Integration::
Session
6. Rails Integration Test
test "Hotel creation" do
get "/hotels"
assert_select "body", :text => /Ritz/, :count => 0
get "/hotels/new"
post_via_redirect "/hotels",
:hotel => { :name => "Ritz" }
assert_response :success
assert_select "body", /Hotel was successfully created/
assert_select "body", /Ritz/
end
7. Webrat
#get #post #head #delete ...
#put #request #follow_redirect!
Hpricot + REXML
Rack::Test
11. click_link
def link_element
matching_links.min { |a, b|
Webrat::XML.all_inner_text(a).length <=>
Webrat::XML.all_inner_text(b).length }
end
12. click_link
def matching_links
@matching_links ||= link_elements.select do |link_element|
matches_text?(link_element) ||
matches_id?(link_element)
end
end
16. click_link
def matching_links
@matching_links ||= link_elements.select do |link_element|
matches_text?(link_element) ||
matches_id?(link_element)
end
end
17. click_link
def matches_text?(link)
if @value.is_a?(Regexp)
matcher = @value
else
matcher = /#{Regexp.escape(@value.to_s)}/i
end
replace_nbsp(Webrat::XML.all_inner_text(link)) =~ matcher ||
replace_nbsp_ref(Webrat::XML.inner_html(link)) =~ matcher ||
Webrat::XML.attribute(link, "title")=~ matcher
end
18. click_link
def matches_id?(link)
if @value.is_a?(Regexp)
(Webrat::XML.attribute(link, "id") =~ @value) ? true : false
else
(Webrat::XML.attribute(link, "id") == @value) ? true : false
end
end
19. click_link
def link_element
matching_links.min { |a, b|
Webrat::XML.all_inner_text(a).length <=>
Webrat::XML.all_inner_text(b).length }
end
22. click_link
def click(options = {})
method = options[:method] || http_method
return if href =~ /^#/ && method == :get
options[:javascript] = true if options[:javascript].nil?
if options[:javascript]
@session.request_page(absolute_href, method, data)
else
@session.request_page(absolute_href, :get, {})
end
end
30. Forms
select_date "April 26, 1982", :from => "Birthday"
select_date Date.today
select_datetime 2.days.ago
select_datetime "April 26, 1982 7:00PM", :from => "Event"
select_time "22:30"
select_time "1:30AM", :from => "Arrival time"
31. Forms
select_date "April 26, 1982", :from => "Birthday"
select_date Date.today
select_datetime 2.days.ago
select_datetime "April 26, 1982 7:00PM", :from => "Event"
select_time "22:30"
select_time "1:30AM", :from => "Arrival time"
32. Forms
select_date "April 26, 1982", :from => "Birthday"
select_date Date.today
select_datetime 2.days.ago
select_datetime "April 26, 1982 7:00PM", :from => "Event"
select_time "22:30"
select_time "1:30AM", :from => "Arrival time"
33. Forms
select_date "April 26, 1982", :from => "Birthday"
select_date Date.today
select_datetime 2.days.ago
select_datetime "April 26, 1982 7:00PM", :from => "Event"
select_time "22:30"
select_time "1:30AM", :from => "Arrival time"
34. Forms
select_date "April 26, 1982", :from => "Birthday"
select_date Date.today
select_datetime 2.days.ago
select_datetime "April 26, 1982 7:00PM", :from => "Event"
select_time "22:30"
select_time "1:30AM", :from => "Arrival time"
35. Forms
select_date "April 26, 1982", :from => "Birthday"
select_date Date.today
select_datetime 2.days.ago
select_datetime "April 26, 1982 7:00PM", :from => "Event"
select_time "22:30"
select_time "1:30AM", :from => "Arrival time"
36. Forms
select_date "April 26, 1982", :from => "Birthday"
select_date Date.today
select_datetime 2.days.ago
select_datetime "April 26, 1982 7:00PM", :from => "Event"
select_time "22:30"
select_time "1:30AM", :from => "Arrival time"
37. Forms
select_date "April 26, 1982", :from => "Birthday"
select_date Date.today
select_datetime 2.days.ago
select_datetime "April 26, 1982 7:00PM", :from => "Event"
select_time "22:30"
select_time "1:30AM", :from => "Arrival time"
46. Matchers
assert_have_xpath "//div[@id = 'hotel_1']",
:content => "Sol Meliá Berlín"
assert_have_xpath "//*[@class = 'bookings']",
:count => 5
assert_have_no_xpath "//a[enabled(.)]",
:href => "http://google.com"
55. Gracias!
http://wiki.github.com/brynary/webrat
http://gitrdoc.com/brynary/webrat/tree/master/
http://twitter.com/cavalle
http://lmcavalle.com
http://spainrb.org/luismi-cavalle