【问题标题】:have_tag vs. have_selectorhave_tag 与 have_selector
【发布时间】:2011-06-15 18:26:41
【问题描述】:

我已经成功地将 have_selector 与 RSpec(版本 2.0.1)一起使用。我最近发现了关于 have_tag ... with_tag ... 与 RSpec 1.3.2 相关的文档并想使用它,但 RSpec 给了我错误:

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

在以下几行:

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

我尝试使用相同的语法将“have_selector”和“with_selector”替换为“have_tag”和“with_tag”,在这种情况下我会收到错误消息

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

我也尝试过不使用“with_tag”,而用“have_selector”替换,但没有成功。

【问题讨论】:

    标签: rspec selector


    【解决方案1】:

    我花了一段时间才在文档中找到它,但正确的答案是

      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
    

    【讨论】:

    • 您可以在此处提供您找到的文档的链接。
    • 很棒的发现,我 +1,虽然我使用了 content.should have_selector('dl')
    • 我认为这行不通。该块显然被忽略了......恐怕你并没有真正断言这里的内容。
    • 我想知道的是如何确保brands.name 在marketsize.name 之前?
    • @AlexChaffee 是对的。每次都会过去,但这是误报。该块被忽略(尽管为什么让我感到困惑)
    【解决方案2】:

    RSpec-2 将不包含 have_tag。请改用 webrat 的 have_selector 匹配器。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多