在Ruby on Rails中测试时更改规格中的会话变量的值(使用capybara和selenium) [英] Changing the value of a session variable in specs while testing in Ruby on rails.(with capybara and selenium)

查看:80
本文介绍了在Ruby on Rails中测试时更改规格中的会话变量的值(使用capybara和selenium)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用Rspec和capybara与硒驱动浏览器来为Ruby on Rails应用程序编写规范。

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

在执行我想要执行的规范之一时更改会话变量的值。
例如:我想设置 session [:location] = US 以便我可以在$中看到所有值时测试我的应用程序。我该怎么做?

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.

如何在应用程序中设置位置?用户可以手动设置吗?如果是,则应在规范中的before块中完成该操作。

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.

这篇关于在Ruby on Rails中测试时更改规格中的会话变量的值(使用capybara和selenium)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆