RSpec控制器测试使请求进入错误的URL

时间:2014-01-27 08:33:03

标签: ruby-on-rails

我有这个RSpec测试:

# /spec/controllers/user/builder_tab/biographies_controller_spec.rb
describe User::BuilderTab::BiographiesController do
  before(:each) do
    @user    = create :user 
    sign_in @user
  end

  describe "#update" do
    it "can update" do
      patch :update, profile: { name: "Joe Peshi" }

      expect(User.first.profile.name).to eq "Joe Peshi"
    end
  end
end

但是当我运行它时 - 由于某种原因它会提出这个请求:

No route matches {:profile=>{:name=>"Joe Peshi"}, :controller=>"user/biographies", :action=>"update"}

这显然失败了,因为路径不是/user/biographies - 它是/user/builder_tab/biographies

我该如何解决?

我的路线是:

namespace :user do
  namespace :builder_tab do
    resource :biography, only: [:edit, :update]
  end
end

Builder_tab的定义如下:

class User::BuilderTab < User
end

1 个答案:

答案 0 :(得分:0)

尝试对您的模块进行详细说明并查看是否有帮助

module User
  module BuilderTab
    describe BiographiesController
      ..
    end
  end
end