{"id":28640783,"url":"https://github.com/pd/rspec_hpricot_matchers","last_synced_at":"2025-06-12T20:08:24.223Z","repository":{"id":384664,"uuid":"1922","full_name":"pd/rspec_hpricot_matchers","owner":"pd","description":"have_tag() without Rails' assert_select()","archived":false,"fork":false,"pushed_at":"2009-06-10T04:03:26.000Z","size":108,"stargazers_count":29,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-16T00:58:49.627Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pd.png","metadata":{"files":{"readme":"README","changelog":null,"contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2008-02-29T22:54:51.000Z","updated_at":"2024-04-16T00:58:49.630Z","dependencies_parsed_at":"2022-07-18T02:46:45.770Z","dependency_job_id":null,"html_url":"https://github.com/pd/rspec_hpricot_matchers","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/pd/rspec_hpricot_matchers","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pd%2Frspec_hpricot_matchers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pd%2Frspec_hpricot_matchers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pd%2Frspec_hpricot_matchers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pd%2Frspec_hpricot_matchers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pd","download_url":"https://codeload.github.com/pd/rspec_hpricot_matchers/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pd%2Frspec_hpricot_matchers/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259522118,"owners_count":22870449,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-12T20:08:23.512Z","updated_at":"2025-06-12T20:08:24.216Z","avatar_url":"https://github.com/pd.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"= rspec_hpricot_matchers\n\nAn implementation of have_tag(), as in rspec_on_rails, but sitting atop\nNokogiri rather than merely wrapping assert_select().\n\nSo at one point it was on Hpricot. But it's not now. Misnomers are more\nfun. You're probably better off using something like Webrat::Matchers\nanyhow.\n\n\n== Installation\n\nTo use rspec_hpricot_matchers in your project, install the gem, and\nadd the following to your spec_helper.rb file:\n\n  require 'rspec_hpricot_matchers'\n  Spec::Runner.configure do |config|\n    config.include(RspecHpricotMatchers)\n  end\n\nSimilarly, to make the matchers available to stories, you can add the\nfollowing to your stories/helper.rb file:\n\n  require 'rspec_hpricot_matchers'\n  include RspecHpricotMatchers\n\n\n== Usage\n\nAs its first argument, have_tag() accepts any CSS or XPath selectors\nwhich are supported by Hpricot.\n\n    body.should have_tag('form[@action*=session]')\n    body.should have_tag('ul \u003e li + li')\n\nExpectations can be placed upon the inner text of the matched element\nby providing another argument, which should be either a String or a\nRegexp:\n\n    body.should have_tag('h1', 'Welcome')\n    body.should have_tag('p', /a very important blurb/i)\n\nExpectations can be placed upon the number of matched elements by\npassing an options hash:\n\n    body.should have_tag('abbr', :count =\u003e 1)   # exactly one\n    body.should have_tag('dt',   :minimum =\u003e 4) # at least 4\n    body.should have_tag('dd',   :maximum =\u003e 4) # at most 4\n    body.should have_tag('a.outgoing', /rspec/i, :count =\u003e 2)\n\nThe :count key also accepts a Range, making the following equivalent:\n\n    body.should have_tag('tr',   :count =\u003e 3..5)\n    body.should have_tag('tr',   :minimum =\u003e 3,\n                                 :maximum =\u003e 5)\n\n\nThe usage of with_tag(), however, is no longer supported. Instead, a\nblock passed to have_tag() will have each matched element successively\nyielded to it. If none of the blocks return without raising an\nExpectationNotMetError, the outer have_tag() is treated as having failed:\n\n    body.should have_tag('thead') do |thead|\n      thead.should have_tag('th', :count =\u003e 5)\n    end\n\nThis also allows arbitrary expectations to be applied from within\nthe block, such as:\n\n    body.should have_tag('dl dd.sha1') do |dd|\n      dd.inner_text.length.should == 40\n    end\n\n\n== Notes\n\nCurrently, this implementation does not support substitution values\nas assert_select did (by way of HTML::Selector):\n\n    # Not yet supported:\n    body.should have_tag('li[class=?]', dom_class)\n    body.should have_tag('tr.person#?', /^person-\\d+$/)\n\nI personally rarely use these, and Hpricot's advanced selectors make\nthem mostly useless, as far as I can tell, so I am unlikely to\nimplement them myself.\n\nThis have_tag() further differs from the assert_select-based\nimplementation in that the nested have_tag() calls must *all* pass\non a single selected element in order to be true. This was a source\nof confusion in RSpec ticket #316. There is a spec covering this\ncase if you need an example.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpd%2Frspec_hpricot_matchers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpd%2Frspec_hpricot_matchers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpd%2Frspec_hpricot_matchers/lists"}