2014-02-28 30 views
0

通常我会避免控制器测试并坚持模型&黄瓜,但我发现自己需要一个,我似乎无法移动。Rails Rspec控制器返回'未定义的方法Sinatra ::应用程序:类'

下面的代码是简单..我已经撕去了刚才的一切

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安装在Gemfile for this rails应用程序中。 我相信sinatra可能会干扰控制器测试。

回答

0

好了..所以这个问题是错误

1)由于IM使用Sidekiq的碰撞,我在我的配置路线如下

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

这真棒一段代码安装一个Sinatra基于网页界面来监视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错误..

相关问题