开发者

Changing the value of a session variable in specs while testing in Ruby on rails.(with capybara and selenium)

开发者 https://www.devze.com 2023-03-16 22:00 出处:网络
I\'m currently writing specs for my Ruby on Rails application using Rspec and capybara with selenium to drive the browser.

I'm currently writing specs for my Ruby on Rails application using Rspec and capybara with selenium to drive the browser.

While executing one of the specs I want to change the value of a session variable. Eg: I want to set session[:location]="US开发者_运维百科" so that I can test my application while all values are seen in $. How do I go about it?


Capybara/Selenium specs are for acceptance testing. You shouldn't do any kind of mocking, stubbing or...changing session values directly. You should interact with your application from within the spec just like a normal user would do in the browser.

How the location is being set in your app? Can the user set it manually? If yes, you should do it in the spec in a before block.


It's not exacly as you say.In Cucumber scenario we have chance to test some cases, and you must have a changes to create some background for that cases like create some user in Given block or add somethink to db and etc. Sessions is the same resoures like db and i thnik you should have the chance to prepare it for tests. No metter how strong it's connected with end-user.

Imagin that you create some multistep application where you presist some info beatween steps in session. Your client couldn't even imagin his reservation wihout any of this few steps. So from this point of few it's seems to not make any seans to create acceptance test for every step separatly. But after moth your client want's add some extra super user-frandly validation on 4th step. Now he is only intresting in this side and this validation. Probably he could deal with other extra 4th steps but why? He already saw all this staff and accept it.

What you think about this point of view?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号