2015-11-15 18 views
0

在我的應用程序/控制器/ pet_controller.rb文件我有一些代碼on Rails的RSpec的利用W /水豚4.2

class PetsController < ApplicationController 
    before_action :set_pet, only: [:show, :edit, :update, :destroy] 
    before_action :process_params, only: [:create, :edit] 
    # GET /pets 
    # GET /pets.json 
    def index 
    @pets = Pet.find_by_sql ["SELECT * FROM pets WHERE \"userId\" = ?", params[:userId].to_i] 
    end 
. 
. 
. 

我有我的規格/ pets_spec.rb一些代碼,看起來像

describe PetsController do 
    describe 'GET #index' do 
     it { is_expected.to respond_with :ok } 
    end 
end 

如果控制器響應正確,可進行簡單測試。 當我調用束EXEC rspec的,我得到一個

/spec/pets_spec.rb:1:in `<top (required)>': uninitialized constant PetsController (NameError) 

我很新的使用該測試工具,任何幫助,得到這個開始將不勝感激。

-Otterman

回答

0

你可能沒有安裝rspec Rails的所有道路。

Read this introduction

這將生成兩個文件:spec/spec_helper.rbspec/rails_helper.rb。打開它們並閱讀它們如何工作的意見以及它們的用途。然後運行bundle exec rake specbundle exec rspec spec