diff --git a/test/test_helper.rb b/test/test_helper.rb index 041e352..1e4ac39 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -141,20 +141,8 @@ class ActiveSupport::TestCase def find_tag_in_string text, options doc = Nokogiri::HTML.fragment text - tag = doc.css(options[:tag]).first - return unless tag - content = tag.text.strip - - attributes = {}; tag.attributes.each do |a, v| - a = a.to_sym - next unless options[:attributes].has_key? a - attributes[a] = v.value - end if options[:attributes].present? - - ret = true - ret &&= options[:attributes].blank? || attributes == options[:attributes] - ret &&= options[:content].blank? || content == options[:content] - ret + tag = doc.css("#{options[:tag]}#{options[:attributes].map{ |a, v| "[#{a}=\"#{v}\"]" }.join}").first + tag end def assert_tag_in_string(text, options) diff --git a/test/unit/cms_helper_test.rb b/test/unit/cms_helper_test.rb index b9b4ab1..14d6f12 100644 --- a/test/unit/cms_helper_test.rb +++ b/test/unit/cms_helper_test.rb @@ -10,9 +10,9 @@ class CmsHelperTest < ActionView::TestCase should 'show default options for article' do result = options_for_article(build(RssFeed, :profile => Profile.new)) - assert_match /id="article_published_true" name="article\[published\]" type="radio" value="true"/, result - assert_match /id="article_published_false" name="article\[published\]" type="radio" value="false"/, result - assert_match /id="article_accept_comments" name="article\[accept_comments\]" type="checkbox" value="1"/, result + assert_tag_in_string result, tag: 'input', attributes: {id: 'article_published_true', name:'article[published]', type: 'radio', value: 'true'} + assert_tag_in_string result, tag: 'input', attributes: {id: 'article_published_false', name:'article[published]', type: 'radio', value: 'false'} + assert_tag_in_string result, tag: 'input', attributes: {id: 'article_accept_comments', name:'article[accept_comments]', type: 'checkbox', value: '1'} end should 'show custom options for blog' do -- libgit2 0.21.2