2013-05-17 93 views
0

我是使用Rails創建API的新手,並且正在嘗試創建一個測試。如何解決rails api測試錯誤?

require "spec_helper" 

describe "/api/v1/iosapps", :type => :api do 


    context "view all apps" do 
     let(:url) { "/api/v1/iosapps" } 
     it "json" do 
      get "#{url}.json" 
      iosapps_json = Iosapp.all.to_json 
      last_response.body.should eql(iosapps_json) 
      last_response.status.should eql(200) 
      iosapps = JSON.parse(last_response.body) 

      iosapps.any? do |p| 
       p["name"] == iosapp.name 
      end.should be_true 
     end 
    end 

end 

我收到一個錯誤,說下面。有關如何解決這個問題的任何建議?

Failure/Error: get "#{url}.json" 
ActiveRecord::StatementInvalid: 
    Could not find table 'iosapps' 

回答

1

測試數據庫沒有準備好。您需要運行

rake db:migrate 
rake db:test:prepare