[英]Rspec: How can I have many controllers in one test? How can I change controllers in a test?
I'm running into an interesting issue when I try to write a full walk through test. 当我尝试编写完整的逐步测试时,我遇到了一个有趣的问题。
First, I'd like to acknowledge that tests should be discrete and specific things. 首先,我想承认测试应该是离散且特定的事情。 This fact I know.. but :)
我知道这个事实..但是:)
But as with a play and learning lines, I think it's a good idea to have a full walk through test before you open the doors. 但是,就像玩游戏和学习游戏一样,我认为在打开门之前进行完整的测试是一个好主意。 To this end I want to write a massive integration test, that hits a pile of controllers.
为此,我想编写一个大规模的集成测试,该测试会遇到大量的控制器。 It will be super slow so I've already isolated it to run only when asked for.
它将非常慢,因此我已经隔离了它仅在需要时运行。 But now I'm stuck
但是现在我被卡住了
I can't seem to figure out how to "hit" the controllers. 我似乎无法弄清楚如何“命中”控制器。
I've tried setting my test type to 'integration' and stipulating. 我尝试将测试类型设置为“集成”并进行规定。 I followed the steps outlined in this questions answer post to a different controller in an rspec test And I threw in a 1/0 in the controller, and it never hit.
在rspec测试中 ,我按照此问题解答中概述的步骤将其传递给其他控制器,然后在控制器中放入了1/0,但从未成功。
Okay.. I figured this out, thanks to other answers.. I'm just writing it out simpler, for my own notes.. and for future hunters. 好吧..我想出了这一点,这要归功于其他答案..我只是为了自己的笔记和将来的猎人而简化了写法。
describe 'Payments Integration', :type => :request do
let(:attributes) { p 'blabla' }
it 'should create user and billing details' do
expect{
post '/api/account', account: attributes
}.to change(User,:count).by(1)
user = User.find(json['account']['id'])
auth = user.authentication_token
expect{
post '/api/billing_details', auth_token: auth, credit_card: valid_card
}.to change(BillingDetail,:count).by(1)
end
end
I had many posts and puts, but this code is enough to get anyone started. 我有很多职位,但是这段代码足以使任何人入门。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.