简体   繁体   中英

Feature tests not passing REQUEST_URI to a middleware with RSpec and Capybara

I am trying to setup feature testing on an application. I decided to install Capybara, and thus added it to my project's Gemfile:

group :test do
  gem "capybara"
end

I declare my tests on the spec/feature folder, and the test manages to execute:

require "rails_helper"

feature 'My Feature' do
  scenario 'User visits feature page' do
    visit '/my-feature'
    expect(page).to have_text('Stuff')    
  end
end

Issue: I have an URL middleware that does not detect the env['REQUEST_URI] flag and thus my test fails:

class UrlNormalizationMiddleware

  def initialize(app)
    @app = app
  end


  def call(env)
    uri_items = env['REQUEST_URI'].split('?')
    ...
    @app.call(env)
  end
end

The actual application loads, and passes values on env['REQUEST_URI'] , but doesn't on the test environment.

Anything else that I need to setup?

Thanks!

REQUEST_URI is not part of the rack spec, which means it's not guaranteed to be set, and you shouldn't be using it in your middleware. Instead you should be using things like PATH_INFO, QUERY_STRING, etc. which are specified in the rack spec and should therefore be available - https://github.com/rack/rack/blob/master/SPEC

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM