[英]How to specifiy the query string in an RSpec test of a Rails controller action?
I have an action called yearly_csv
. 我有一个名为
yearly_csv
的动作。 In this action I perform two operations like demand and supply. 在这个动作中,我执行两个操作,如需求和供应。
def yearly_csv
if demand == 'true'
demand_csv
else
supply_csv
end
end
I have two radio buttons in my view to select one of the operations. 我在视图中有两个单选按钮来选择其中一个操作。 Now I want to test each operation individually in RSpec.
现在我想在RSpec中单独测试每个操作。 For example, one spec for supply and another spec for demand.
例如,一个供应规格和另一个需求规格。 My question is how to pass the radio button value to the
yearly_csv
action (get)? 我的问题是如何将单选按钮值传递给
yearly_csv
动作(get)?
In an RSpec controller spec, specify query parameters as a hash argument to get
: 在RSpec控制器规范中,将查询参数指定为哈希参数以
get
:
describe YourController
describe '#yearly_csv'
# set up
get :yearly_csv, demand: 'true'
# assert results
end
end
在RSpec的较新版本中,您必须使用params
键声明查询字符串参数:
get :yearly_csv, params: { demand: 'true' }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.