@user response.should -6ren">
gpt4 book ai didi

ruby-on-rails - 使用 rspec 和 cabybara 测试链接 : old and new syntax

转载 作者:数据小太阳 更新时间:2023-10-29 08:04:20 24 4
gpt4 key购买 nike

在 rspec 的旧语法中,我可以这样做:

It "should have the right URL" do 
get :show, :id => @user
response.should have_selector('td>a', :content => user_path(@user),
:href => user_path(@user))
end

在新语法中我们可以这样做:

It "should have the right URL" do 
visit user_path(@user)
expect(page).to have_link user_path(@user), href: user_path(@user)
end

但是,在 rspec 和使用 capybara 的新语法中,我怎么能说链接应该在哪里?在第一个例子中我说它在'td>a'中,那么第二个例子呢?

谢谢!

编辑:

如果我尝试这样做:

It "should have the right URL" do 
expect(page).to have_selector('td>a', :content => user_path(@user),
:href => user_path(@user))

我收到以下错误:

  1) UsersController GET 'show' should have the right URL
Failure/Error: expect(page).to have_selector(:content => user_path(@user),
ArgumentError:
invalid keys :content, :href, should be one of :text, :visible, :between, :count, :maximum, :minimum, :exact, :match, :wait

最佳答案

也许你也升级了你的 capybara gem

尝试:

It "should have the right URL" do 
expect(page).to have_selector("td>a[href='#{user_path(@user)}']",
:text=> user_path(@user))

关于ruby-on-rails - 使用 rspec 和 cabybara 测试链接 : old and new syntax,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22186474/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com