加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails-3 – 使用RSpec 2和Rails3测试嵌套的命名空间控制

发布时间:2020-12-17 03:19:55 所属栏目:百科 来源:网络整理
导读:在这种情况下,我觉得代码说的不仅仅是单词,所以放在代码中: 配置/ routes.rb中 namespace :embed do namespace :v1 do resources :articles endend 应用程序/控制器/嵌入/ V1 / articles_controller.rb class Embed::V1::ArticlesController ApplicationCon
在这种情况下,我觉得代码说的不仅仅是单词,所以放在代码中:

配置/ routes.rb中

namespace :embed do
  namespace :v1 do
    resources :articles
  end
end

应用程序/控制器/嵌入/ V1 / articles_controller.rb

class Embed::V1::ArticlesController < ApplicationController
  def index
    render :text => 'ok'
  end
end

规格/控制器/嵌入/ 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规范

$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

知道为什么会这样吗?有嵌套限制吗?
访问URL http://0.0.0.0:3000/embed/v1/articles按预期呈现正常.

解决方法

您没有在Embed :: V1 :: ArticlesController中定义的新操作,只有索引操作.您正尝试使用get:new命中您的规范中的新操作.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读