2013-05-17 35 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