gpt4 book ai didi

ruby-on-rails - Rspec:如何测试 Rails 的 url_for 助手?

转载 作者:行者123 更新时间:2023-12-03 23:27:21 25 4
gpt4 key购买 nike

使用 RSpec,我如何测试 url_for 辅助方法以确保它以特定格式转到正确的 Controller 和操作?

最佳答案

我必须做以下事情——

将此添加到 spec_helper.rb:

Rspec.configure do |config|
config.include Rails.application.routes.url_helpers # url_for
end

然后:
describe "Article routing" do
it "routes to #index.atom" do
get('/articles.atom').
should route_to('articles#index', format: 'atom')

url_for(:controller => 'articles', :format => :atom, :only_path => true).
should == '/articles/index.atom'
end
end

关于ruby-on-rails - Rspec:如何测试 Rails 的 url_for 助手?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25494419/

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