have_tag vs. have_selector

我只是一个虾纸丫 提交于 2019-12-21 22:31:17

问题


I've been using have_selector with RSpec (version 2.0.1) successfully. I recently found documentation on have_tag ... with_tag ... associated with RSpec 1.3.2 and would like to use it, but RSpec gives me the error:

undefined method `has_tag?' for #<ActionController::TestResponse:0x105584e80>

on the following lines:

      response.should have_tag("div.breadcrumbs select") do
        with_tag(:option, :value => @brands.name)
        with_tag(:option, :value => @marketsize.name)
      end

I've tried the same syntax substituting "have_selector" and "with_selector for "have_tag" and "with_tag", in which case I get the error message

undefined method `with_selector' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1::Nested_1::Nested_1:0x105379de8>

I've also tried leaving the "with_tag" alone while substituting "have_selector" with no success.


回答1:


Took me a while to find it in the documentation, but the correct answer is

  response.should have_selector("div.breadcrumbs select") do |content|
    content.should have_selector(:option, :value => @brands.name)
    content.should have_selector(:option, :value => @marketsize.name)
  end



回答2:


RSpec-2 will not include have_tag. Use webrat's have_selector matcher instead.

http://groups.google.com/group/rspec/browse_thread/thread/1c254524d6859ba9



来源:https://stackoverflow.com/questions/6362493/have-tag-vs-have-selector

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!