Skip to content

undefined method 'visit' on request spec #960

@mrmarcondes

Description

@mrmarcondes

Hi,

I'm trying to use Clearance::BackDoor on my requests specs that use rswag gem.

My sample test is:

require 'swagger_helper'

RSpec.describe 'api/v1/animals', type: :request do
  let!(:customer) { create(:customer) }

  before do
    visit session_path(as: customer)
  end

  path '/api/v1/animals' do
    let!(:animals) { create_list(:animal, 2, customer: customer) }

    get('list animals') do
      security [cookies: []]
      produces 'application/json'
      response(200, 'successful') do
        after do |example|
          puts response.request.inspect
          example.metadata[:response][:content] = {
            'application/json' => {
              example: JSON.parse(response.body, symbolize_names: true)
            }
          }
        end
        run_test! do
          expect(response.body).to match_json_schema('response')
        end
      end
    end
end

I'm getting the error:

    1.1) Failure/Error: visit session_path(as: customer)
          
          NoMethodError:
            undefined method `visit' for #<RSpec::ExampleGroups::ApiV1Animals::ApiV1Animals::Get::Successful:0x0000557b76384bd0>

My test.rb has:

# test.rb
Rails.application.configure do
  ...
  config.middleware.use Clearance::BackDoor
end

I tested on Clearance 2.5.0, 2.2.1 and 1.16.1

I can execute this in replacement of visit:

  before do
    backdoor = Clearance::BackDoor.new(ENV)
    puts backdoor.inspect
  end

And I got a result. So, the backdoor was injected into my code.

Could you help me, please? Am I missing something?

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions