Skip to content

Instantly share code, notes, and snippets.

@biot023
Created February 4, 2010 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save biot023/294802 to your computer and use it in GitHub Desktop.
Save biot023/294802 to your computer and use it in GitHub Desktop.
my_env.rb
# Again, the text() method wouldn't give me what I wanted, so I came up with this to get at it (and to remove any
# whitespace either side of it).
# Used like:
# find( "//a[@id = 'messages']" ).should contain_text( "Review Your Messages" )
class ContainText
def initialize( text )
@text = text
end
def matches?( node )
@node_text = node.text.strip
return true if @node_text.blank? && @text.blank?
@node_text == @text
end
def failure_message
"The node should have contained the text #{ @text.inspect }, but instead got #{ @node_text.inspect }."
end
def negative_failure_message
"The node should not have contained the text #{ text.inspect }, but did in #{ @node_text.inspect }."
end
end
def contain_text( text )
ContainText.new( text )
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment