我正在关注迈克尔的 ROR 教程并创建用户身份验证系统。有一个管理员权限,允许用户删除其他用户。以特权管理员用户身份登录时,用户列表页面上会出现特殊的“删除”链接。我的应用程序运行良好,但 rspec 测试因我不知道的原因而失败。
我已经将测试分离到另一个文件中spec/requests/sat_spec.rb
,我正在尝试使用 pry gem 来调试它,但到目前为止还没有成功。
describe "delete links" do
describe "as admin user" do
let(:admin) { FactoryGirl.create(:admin) }
before do
sign_in admin
visit users_path
binding.pry
end
it { should have_link('delete', href: user_path(User.first)) }
it "should be able to delete another user" do
expect { click_link('delete') }.to change(User, :count).by(-1)
end
end
测试失败:
1) separated admin tests delete links as admin user
Failure/Error: it { should have_link('delete', href: user_path(User.first)) }
expected link "delete" to return something
# ./spec/requests/sat_spec.rb:25:in `block (4 levels) in <top (required)>'
2) separated admin tests delete links as admin user should be able to delete another user
Failure/Error: expect { click_link('delete') }.to change(User, :count).by(-1)
Capybara::ElementNotFound:
no link with title, id or text 'delete' found
# (eval):2:in `click_link'
# ./spec/requests/sat_spec.rb:28:in `block (5 levels) in <top (required)>'
# ./spec/requests/sat_spec.rb:28:in `block (4 levels) in <top (required)>'
这里的问题可能是什么,或者更重要的是如何调试它?
你可以在这里分叉我的代码https://github.com/tomek-rusilko/miniatury_katalog_2