Reputation: 457
I am working on a Rails project that uses Swagger through rswag and Rspec for testing. The code is an API which needs to be tested through the Rspec system. I am new to both rswag and Rspec.
My code works currently but it fails the provided Rspec tests. The issue I am having is that Rspec reports:
NoMethodError:
undefined method `comment_id' for #<RSpec::ExampleGroups::Comments::CommentsCommentId::Patch::CommentWithProvidedIdSetToSticky:0x000000000c3055a0>
comment_id is a parameter in the URL. Here is the relevant Rswag/rspec definition:
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
Why am I getting the No Method error in the Rspec output?
Upvotes: 3
Views: 2024
Reputation: 26
you need add let(:comment_id){ 'id' }
that 'id' you can create an record by FactoryBot like:
let(:comment_id){ FactoryBot.create(:comment).id }
Upvotes: 1