railsware / rack_session_access

Rack middleware that provides access to rack.session environment
MIT License
257 stars 29 forks source link

Fetch values without navigating user? #20

Closed lotyrin closed 7 years ago

lotyrin commented 9 years ago

It would be nice if with capybara integration, a fetch of session keys wouldn't affect the preexisting page visit.

e.g.

path = current_path
page.get_rack_session_key('some key')
expect(current_path).to eq(path)
ayanko commented 9 years ago

Its not possible because it's middleware. And communication with it only possible on app level. E.g browser - server - app with injected midleware.

Actually with low level capybara driver (rack-test) it might be possible because in this case there is no server process. But it will look as hack.

The main goal of this gem is ability to manage app session on high level so that it can be used in acceptance testing with any capybara driver: rack-test, selenium, webkit, poltergeist, etc.

So you must navigate to this midleware urls in order to set/get data.

lotyrin commented 9 years ago

I haven't looked at the architecture here much yet, but would it not be possible to make requests to the middleware URLs out of band from capybara? With plain ruby http requests? Even in the case of a selenium remote, it seems possible to use the webdriver API to borrow its cookies to be able to make the request with unless I'm missing something.

ayanko commented 9 years ago

Then we need 2 implementations. One for rack-test driver (no http stack) and second for another drivers (with http stack).

I'd like to keep it simple.

yurighensev commented 7 years ago

So in other words, when I use rack_session_access it is not possible to write tests that assert anything based on current_path?

ayanko commented 7 years ago

No. It's possible. But before current_path assertion you should visit some page. And that actually makes sense.

E.g.

background do
  logged_as user
and

scenario 'foo' do
  visit dashboard_path
  expect(page).to have_text('Welcome')
  expect(page.current_path).to eq('/dashboard')
  click_button 'Profile'
  expect(page).to have_text('My Profile')
  expect(page.current_path).to eq('/dashboard/profile')
end

Also make sure that BEFORE current patg assertion you have assertion that waits for feedback on user action.