ruby-on-railsrspecruby-on-rails-5rspec-railsrswag

dont need call parameters in every rswag response block


parameter name: :search, in: :query, type: :string

I don't want pass search param in first response param, but accrued to an error at last notice: if pass param with nil, in the controller is present as a string with zero length but still present? is true

 response('200', 'success') do
    run_test! { |_response| expect('length(address_books)').to match_json(3) }
 end

 response('200', 'search params') do
    let(:search) { 'aa' }
    run_test! { |_response| expect('length(address_books)').to match_json(2) }
  end
Failure/Error: super

     NoMethodError:
       undefined method `search' for #<RSpec::ExampleGroups::***Controller:::Get::success:0x00007fa50f7de068>

Solution

  • use required: false for your param:

    parameter name: :search, in: :query, type: :string, required: false