Navigation Menu

Skip to content

Commit

Permalink
Strip and normalize spaces. Fixes thoughtbot#112 thoughtbot#145
Browse files Browse the repository at this point in the history
  • Loading branch information
halogenandtoast committed Sep 23, 2011
1 parent ff0a6e7 commit 6d92f35
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/capybara/driver/webkit/node.rb
@@ -1,7 +1,10 @@
class Capybara::Driver::Webkit
class Node < Capybara::Driver::Node
NBSP = "\xC2\xA0"
NBSP.force_encoding("UTF-8") if NBSP.respond_to?(:force_encoding)

def text
invoke "text"
invoke("text").gsub(NBSP, ' ').gsub(/\s+/u, ' ').strip
end

def [](name)
Expand Down
5 changes: 5 additions & 0 deletions spec/driver_spec.rb
Expand Up @@ -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>
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 6d92f35

Please sign in to comment.