Rails Rspec Controller 返回 'undefined method Sinatra::Application:Class'



通常我会避免控制器测试并坚持使用Model&Cucumber,但我发现自己需要一个,而且我似乎无法移动。

下面的代码很简单。 我已经撕掉了几乎所有东西

1 require 'spec_helper'
2
3 describe ExperiencesController do
4   describe "GET #show" do
5     context "experience item" do
6       it "redirects to the success url" do
7         experience = build(:experience)
8         get :show, :id => experience.id
9         #should be a test here :)
10       end
11     end
12   end
13 end

产生以下结果

Failures:
  1) ExperiencesController GET #show experience item redirects to the success url
     Failure/Error: get :show, :id => experience.id
     NoMethodError:
     undefined method `id' for Sinatra::Application:Class
      # (__DELEGATE__):2:in `get'
      # ./spec/controller_spec/experiences_controller_spec.rb:8:in `block (4 levels) in      <top (required)>'
$ rake routes|grep experience
                 experiences GET      /experiences(.:format)                                      experiences#index
                             POST     /experiences(.:format)                                      experiences#create
              new_experience GET      /experiences/new(.:format)                                  experiences#new
             edit_experience GET      /experiences/:id/edit(.:format)                             experiences#edit
                  experience GET      /experiences/:id(.:format)                                  experiences#show
                             PUT      /experiences/:id(.:format)                                  experiences#update
                             DELETE   /experiences/:id(.:format)                                  experiences#destroy

真的感觉像一个配置类型的东西我不明白为什么会产生Sinatra错误任何帮助表示赞赏

**更新**

SideKiq及其依赖项sinatra安装在此rails应用程序的Gemfile中。我相信Sinatra可能会干扰控制器测试。

好的,所以问题是错误的碰撞

1.)因为我使用Sidekiq,所以我的配置路由中有以下内容

require 'sidekiq/web'
mount Sidekiq::Web => '/sidekiq'

这段很棒的代码安装了一个基于Sinatra的Web界面来监控Sidekiq

2.)如果你注意到我上面的目录是错误的

It was incorrectly spec/controller_spec instead of spec/controller
When that happens rspec doesnt know you are intending to test controllers and doesnt
load all the Get/post helpers , instead in the loaded stack the only thing it 
found was sinatra which has a get method.. 

溶液。。 将规范移动到正确的目录,以便正确推断正确的依赖项

IT10T 错误..

相关内容

最新更新