Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
optionally decode html entities (defaults to true) to make behavior r…
…e html entities a bit more consistent
- Loading branch information
Sven Fuchs
committed
Apr 2, 2010
1 parent
71180d4
commit 7f31143
Showing
9 changed files
with
140 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module Locator | ||
module Decoding | ||
def decode_entities? | ||
@decode_entities ||= true | ||
end | ||
|
||
def decode_entities=(decode_entities) | ||
@decode_entities = decode_entities | ||
end | ||
|
||
def decode_attributes(hash) | ||
Hash[*hash.map { |name, value| [name, decode(value)] }.flatten] | ||
end | ||
|
||
def decode(value) | ||
value.is_a?(String) ? html_entities.decode(value) : value | ||
end | ||
|
||
protected | ||
|
||
def html_entities | ||
html_entities ||= begin | ||
require 'htmlentities' | ||
HTMLEntities.new | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# encoding: utf-8 | ||
require File.expand_path('../test_helper', __FILE__) | ||
require 'action_pack' | ||
require 'webrat' | ||
require 'rack/test' | ||
|
||
Webrat.configure do |config| | ||
config.mode = :rack | ||
end | ||
|
||
class WebratBehaviorTest < Test::Unit::TestCase | ||
include Webrat::Methods | ||
|
||
def last_response | ||
@last_response ||= Rack::Response.new | ||
end | ||
|
||
def with_html(html) | ||
last_response.body = html | ||
end | ||
|
||
test "foo" do | ||
with_html '<span>München</span>' | ||
field = field_by_xpath(".//span") | ||
p field.element.to_s | ||
end | ||
end |