【发布时间】:2012-05-02 07:12:18
【问题描述】:
我有一个链接如下,我正在尝试测试(请忽略方括号):
[%= link_to "删除用户", destroy_user_account_path(@profile.user), :class=> "删除", :confirm => "a", :title => "删除#{@profile.user.name}", :method => :delete %]
下面的测试失败了,但如果我注释掉 :confirm => "a" 行,它就通过了:
it "should have a link to delete the user's account (using the destroy_user_account action in the registrations controller)" do get :show, :id => @profile response.should have_selector("a", :href => destroy_user_account_path(@profile.user), :confirm => "a", :title => "Delete #{@profile.user.name}", :class => "delete", :content => "Delete User") end
看我的失败:(
Failure/Error: response.should have_selector("a", expected following output to contain a <a title='Delete Michael Hartl' class='delete' href='/destroy-user-account/159' confirm='a'>Delete User</a> tag:
这一行的实际 html 输出如下(同样,方括号是我的)。我注意到它在这里输出“data-confirm”作为属性,而不是测试所期望的“确认”。
[a href="/destroy-user-account/159" class="delete" data-confirm="a" data-method="delete" rel="nofollow" title="删除迈克尔 Hartl"]删除用户[/a]
谁能解释在这种情况下确认和数据确认之间有什么区别,并帮助我弄清楚为什么我会收到这个错误/如何解决它?
谢谢!
【问题讨论】:
标签: ruby-on-rails rspec2 ruby-1.8.7