Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined method 'visit' on request spec #960

Open
mrmarcondes opened this issue Apr 13, 2022 · 0 comments
Open

undefined method 'visit' on request spec #960

mrmarcondes opened this issue Apr 13, 2022 · 0 comments

Comments

@mrmarcondes
Copy link

mrmarcondes commented Apr 13, 2022

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant