小编ian*_*anm的帖子

在Scoped路径上使用RSpec控制器测试的RoutingError

所以我有一条看起来像这样的路线:

scope "4" do
  scope "public" do
    scope ":apikey" do
      resources :shops
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

还有一堆控制器规格,其中一个例子如下:

describe ShopsController do

  describe "when responding to a GET" do

    context "#new" do
      it "should create a new instance of the shop class" do
        get :new
        @shop.should_not_be_nil
      end
    end

  end

end
Run Code Online (Sandbox Code Playgroud)

在rake路由中,以及通过Web浏览器,此控制器/操作正常工作.然而,RSpec抛出:

1) ShopsController when responding to a GET#new should create a new instance of the shop class
 Failure/Error: get :new
 ActionController::RoutingError:
   No route matches {:controller=>"shops", :action=>"new"}
 # ./spec/controllers/shops_controller_spec.rb:9:in `block (4 levels) in <top …
Run Code Online (Sandbox Code Playgroud)

scope controller rspec routes ruby-on-rails-3

3
推荐指数
1
解决办法
2624
查看次数

标签 统计

controller ×1

routes ×1

rspec ×1

ruby-on-rails-3 ×1

scope ×1