Permalink
Browse files

Strip and normalize spaces

  • Loading branch information...
1 parent ff0a6e7 commit a4107f231dff1ee7703c90548c62695e60615cde @halogenandtoast halogenandtoast committed Sep 23, 2011
Showing with 8 additions and 1 deletion.
  1. +3 −1 lib/capybara/driver/webkit/node.rb
  2. +5 −0 spec/driver_spec.rb
@@ -1,7 +1,9 @@
class Capybara::Driver::Webkit
class Node < Capybara::Driver::Node
def text
- invoke "text"
+ nbsp = "\xC2\xA0"
+ nbsp = nbsp.force_encoding("UTF-8") if nbsp.respond_to?(:force_encoding)
+ invoke("text").gsub(nbsp, "\x20").gsub(/\s+/u, ' ').strip
end
def [](name)
View
@@ -159,6 +159,7 @@
</style>
</head>
<body>
+ <div class='normalize'>Spaces&nbsp;not&nbsp;normalized&nbsp;</div>
<div id="display_none">
<div id="invisible">Can't see me</div>
</div>
@@ -202,6 +203,10 @@
subject.find("//p").first.text.should == "hello"
end
+ it "normalizes a node's text" do
+ subject.find("//div[contains(@class, 'normalize')]").first.text.should == "Spaces not normalized"
+ end
+
it "returns the current URL" do
port = subject.instance_variable_get("@rack_server").port
subject.current_url.should == "http://127.0.0.1:#{port}/hello/world?success=true"

0 comments on commit a4107f2

Please sign in to comment.