我使用的是Rails 4.2 rspec 3.5
在基本脚手架生成之后,我试图运行rspec,但不断得到这个错误。
控制器测试
it "updates the requested" do
some_object = SomeObject.create! valid_attributes
put :update, params: {id: some_object.to_param, some_object: new_attributes}, session: valid_session
some_object.reload
skip("Add assertions for updated state")
end
给出了这个输出
Failure/Error: put :update, params: {id: some_object.to_param, some_object: valid_attributes}, session: valid_session
ActionController::UrlGenerationError:
No route matches {:action=>"update"
观看测试
require 'rails_helper'
RSpec.describe "some_objects/edit", type: :view do
before(:each) do
@some_object = assign(:some_object, SomeObject.create!(
:first_name => "MyString",
:last_name => "MyString"
))
end
it "renders the edit some_object form" do
render
assert_select "form[action=?][method=?]", some_object_path(@some_object), "post" do
assert_select "input#some_object_first_name[name=?]", "some_object[first_name]"
assert_select "input#some_object_last_name[name=?]", "some_object[last_name]"
end
end
end
给出了这个输出:
Failure/Error: <%= form_for(@some_object) do |f| %>
ActionView::Template::Error:
undefined method `polymorphic_path' for #<#<Class:0x005606c04fff98>:0x005606c04ffb60>
这是生成的代码。我只更改了valid_attributes哈希,这似乎是rails / rspec中的一些错误。你有任何解决方案
答案 0 :(得分:0)
问题在于传递params:update。只需删除参数:即可使用:
age