我觉得在这种情况下,代码会胜过千言万语,所以放在代码中:
配置/路由.rb
namespace :embed do
namespace :v1 do
resources :articles
end
end
应用程序/ Controller /嵌入/v1/articles_controller.rb
class Embed::V1::ArticlesController < ApplicationController
def index
render :text => 'ok'
end
end
规范/ Controller /嵌入/v1/articles_controller_spec.rb
require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
describe Embed::V1::ArticlesController do
it "should do something" do
get :new
end
end
运行
rspec spec
$ rspec spec
F
Failures:
1) Embed::V1::ArticlesController should do something
Failure/Error: get :new
AbstractController::ActionNotFound:
The action 'new' could not be found for Embed::V1::ArticlesController
# ./spec/controllers/embed/v1/articles_controller_spec.rb:5
Finished in 0.01665 seconds
1 example, 1 failure
知道为什么吗?有嵌套限制吗?
访问网址 http://0.0.0.0:3000/embed/v1/articles 渲染 好的正如预期的那样。
最佳答案
您没有 new
Embed::V1::ArticlesController
中定义的操作, 只有 index
行动。您正在尝试点击 new
使用 get :new
在您的规范中执行操作.
关于ruby-on-rails-3 - 使用 RSpec 2 和 Rails3 测试嵌套命名空间 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5326394/