session available in some rspec files and not others. how come?

后端 未结 2 1493
南方客
南方客 2020-12-16 20:35

In trying to test some sign-in/out functionality I want to delete some information from the session. I found out I couldn\'t access the sessions at all. I kept getting the

2条回答
  •  醉酒成梦
    2020-12-16 21:03

    Your 2nd test is a "request" spec which is an integration test. These are designed to simulate the browser and the helpers you get let you click buttons and fill out forms and assert text, tags on the page. It's the wrong level of abstraction for inspecting the session object.

    If you want to stub out authentication, e.g. best to go through the app. See, e.g. here: Stubbing authentication in request spec

    Know that integration tests are "exploratory" or "smoke" tests, high level tests that check the seams between components, not the guts of the components themselves. They're the most expensive to write and maintain. Use controller specs for verifying session stuff and move all business logic to the models where it's easiest to test.

提交回复
热议问题