[英]RSpec: Test a create action method in controller
I have write a RSpec Test for a create action method in a controller.我已经为控制器中的创建操作方法编写了 RSpec 测试。 Now i became the following error: error Screen
现在我变成了以下错误:错误屏幕
My Test:我的测试:
describe '#create' do
before(:each) {
@address = {
attributes: {
'street': "bla",
'street-number': 2,
'zip': "12345",
'city': "blabla",
'country': ''
},
type: "addresses"
}
}
it 'test the create route' do
post 'create', { params: @address }
end
end
My Controller Method:我的控制器方法:
public def create
action(Address::Create)
.otherwise('address_create_error', 401)
.then_render(Address::Representer::Out::Default)
end
And my Factory:还有我的工厂:
FactoryGirl.define do
factory :address do
street 'Musterstraße'
street_number '1'
zip '12345'
city 'Musterstadt'
country ''
end
end
I have no Idea why this error comes.我不知道为什么会出现这个错误。 Could anybody help me?
有人可以帮我吗?
Try using the "=>" syntax尝试使用“=>”语法
@address = {
'attributes' => {
'street' => "bla",
'street-number' => 2,
'zip' => "12345",
'city' => "blabla",
'country': ''
},
'type' => "addresses"
}
I have resolved the problem today.我今天已经解决了这个问题。 To solve it, I had to adjust two things.
为了解决这个问题,我不得不调整两件事。
Thanks for your help anyway.还是要谢谢你的帮助。 :)
:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.