2011-06-15 46 views
2

我一直在成功使用RSpec(version 2.0.1)的have_selector。我最近发现的文件上have_tag ... with_tag使用RSpec 1.3.2关联......并想使用它,但RSpec的给我的错误:have_tag vs. have_selector

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”取代没有成功。

回答

10

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

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 
+6

您可以在这里提供的链接找到你的文件。 – Chirantan 2011-08-08 03:13:47

+0

很棒的发现,从我+1,虽然我用content.should have_selector('dl') – 2011-12-01 18:39:45

+5

我不认为这个工程。该块显然被忽略......恐怕你并没有真正主张这里的内容。 – AlexChaffee 2012-06-19 22:06:46

相关问题