2014-02-28 61 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錯誤..

相關問題