当我运行这个规范时,它总是给出 nil 对象,任何人都可以在这里帮助我。
require 'spec_helper'
describe Api::SongsController do
describe "GET index" do
it "assigns songs json" do
song = Song.create(:title => "song")
get :index, :format => :js
assigns(:songs).should eq([song])
end
end
end
还有我的控制器代码
def index
songs = Song.all
if !songs.empty?
respond_with songs
else
render :json => {:message => "No songs found."}
end
end