我正在从事一个Rails项目,该项目使用Swagger通过rswag和Rspec进行测试。代码是一个API,需要通过Rspec系统进行测试。我对rswag和Rspec都是新手。
我的代码目前可以工作,但是它失败了提供的Rspec测试。我的问题是Rspec报告:
NoMethodError:
undefined method `comment_id' for #<RSpec::ExampleGroups::Comments::CommentsCommentId::Patch::CommentWithProvidedIdSetToSticky:0x000000000c3055a0>comment_id是URL中的一个参数。以下是相关的Rswag/rspec定义:
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方法错误?
发布于 2021-01-26 07:25:56
您需要添加“id”的let(:comment_id){ 'id' },您可以通过FactoryBot创建一个记录,如:let(:comment_id){ FactoryBot.create(:comment).id }
https://stackoverflow.com/questions/53786609
复制相似问题