我想修改控制器中的一些东西并使用 rspec 测试它们。我想new
为Spree::ProductsController
. 这是我尝试过的
routes.rb
resources :products
prodcuts_controller_decorator.rb
Spree::ProductsController.class_eval do
before_filter :authenticate_spree_user!, :except => [:show, :index]
def new
@product = current_user.products.build
end
end
products_controller_spec.rb
require 'spec_helper'
describe Spree::ProductsController do
let(:user) {create(:user)}
before(:each) do
Spree::Core::Engine.routes
BigPlanet::Application.routes
controller.stub :spree_current_user => user
end
it "render new template" do
get :new
response.should render_template(:new)
end
end
end
但它使用原始Spree::Controller
并给出
Failure/Error: get :new
ActionController::RoutingError:
No route matches {:controller=>"spree/products", :action=>"new"}
如果有人能把我推向正确的方向,那就太好了。