首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Rswag和Rspec: URL参数的未定义方法

Rswag和Rspec: URL参数的未定义方法
EN

Stack Overflow用户
提问于 2018-12-14 20:39:28
回答 1查看 1.5K关注 0票数 3

我正在从事一个Rails项目,该项目使用Swagger通过rswag和Rspec进行测试。代码是一个API,需要通过Rspec系统进行测试。我对rswag和Rspec都是新手。

我的代码目前可以工作,但是它失败了提供的Rspec测试。我的问题是Rspec报告:

代码语言:javascript
复制
NoMethodError:
   undefined method `comment_id' for #<RSpec::ExampleGroups::Comments::CommentsCommentId::Patch::CommentWithProvidedIdSetToSticky:0x000000000c3055a0>

comment_id是URL中的一个参数。以下是相关的Rswag/rspec定义:

代码语言:javascript
复制
path '/comments/{comment_id}' do
  parameter name: :comment_id, in: :path, type: :string, format: :uuid
  patch 'Sets the sticky comment for a given invoice, client or debtor id' do
    tags 'Comments'
    produces 'application/json'
    consumes 'application/json'
    security [oauth2: []]
    parameter name: :data, in: :body, required: true, schema: {
      type: :object,
      properties: {
        data: {
          type: :object,
          properties: {
            attributes: {
              type: :object,
              required: %i[comment_id],
              properties: {
                sticky_flag: { type: :boolean }
              }
            }
          }
        }
      }
    }

    response '201', 'comment with provided id set to sticky' do
      let(:data) { { comment_id: '', sticky_flag: '' } }
      run_test!
    end

为什么要在Rspec输出中获得No方法错误?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-01-26 07:25:56

您需要添加“id”的let(:comment_id){ 'id' },您可以通过FactoryBot创建一个记录,如:let(:comment_id){ FactoryBot.create(:comment).id }

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53786609

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档