Commit 5d783a7e4a2c6ceed45ce9573cba13ef03af5963
1 parent
92267854
Exists in
master
and in
11 other branches
rails4: check tag content
Showing
1 changed file
with
7 additions
and
1 deletions
Show diff stats
test/test_helper.rb
| @@ -138,12 +138,18 @@ class ActiveSupport::TestCase | @@ -138,12 +138,18 @@ class ActiveSupport::TestCase | ||
| 138 | def find_tag_in_string text, options | 138 | def find_tag_in_string text, options |
| 139 | doc = Nokogiri::HTML.fragment text | 139 | doc = Nokogiri::HTML.fragment text |
| 140 | tag = doc.css(options[:tag]).first | 140 | tag = doc.css(options[:tag]).first |
| 141 | + content = tag.text.strip | ||
| 142 | + | ||
| 141 | attributes = {}; tag.attributes.each do |a, v| | 143 | attributes = {}; tag.attributes.each do |a, v| |
| 142 | a = a.to_sym | 144 | a = a.to_sym |
| 143 | next unless options[:attributes].has_key? a | 145 | next unless options[:attributes].has_key? a |
| 144 | attributes[a] = v.value | 146 | attributes[a] = v.value |
| 145 | end | 147 | end |
| 146 | - tag if (tag and attributes == options[:attributes]) | 148 | + |
| 149 | + ret = tag.present? | ||
| 150 | + ret &&= options[:attributes].blank? || attributes == options[:attributes] | ||
| 151 | + ret &&= options[:content].blank? || content == options[:content] | ||
| 152 | + ret | ||
| 147 | end | 153 | end |
| 148 | 154 | ||
| 149 | def assert_tag_in_string(text, options) | 155 | def assert_tag_in_string(text, options) |