Skip to content

Instantly share code, notes, and snippets.

@xnzac
Forked from mattwynne/step_to_match_list_item.rb
Created April 12, 2009 07:55
Show Gist options
  • Save xnzac/93916 to your computer and use it in GitHub Desktop.
Save xnzac/93916 to your computer and use it in GitHub Desktop.
def within_list(css_class)
css_selector = css_class.gsub(/ /, '.') #stack the css classes for selection
list = current_dom.at("ol.#{css_selector}") || current_dom.at("ul.#{css_selector}") # Could add an opt param to the method to make this explicit - for now we don't care
assert_not_nil(list, "Expected to find a ul or li tag matching the css class '#{css_class}'")
yield list
end
Then /^I should see the text "(.*)" in the "(.*)" list$/ do |text, css_class| #"
within_list(css_class) do |list|
matching_list_items = list.search("li").select{ |li| strip_html_tags_from(li.inner_html) =~ escape_text_for_regexp(text) }
assert(matching_list_items.length > 0, "Expected to find at least one list item matching #{escape_text_for_regexp(text)} in this HTML fragment:\n#{list.inner_html}")
end
dump_page
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment