如何测试我的model
方法Project.all()
。当我查询我的方法时,我得到Projects
的列表,但我不确定要对其进行文本处理?
require 'spec_helper'
describe Project do
before(:all) do
end
it "get all projects" do
projects = Project.all( authorization: @token)
end
end
我的问题是我检查它以通过此测试?
答案 0 :(得分:1)
您可以执行以下操作: -
describe Project do
# use the mandatory attributes while creating the Project objects.
# I assumed, there is a :name attribute defined. But this is an idea
# about the approach.
let!(:proj1) { Project.create(name: "a", authorization: @token) }
let!(:proj2) { Project.create(name: "b", authorization: @token) }
let!(:proj3) { Project.create(name: "c", authorization: @token1) }
after(:all) { Project.delete_all }
it "get all projects" do
expect(Project.all( authorization: @token)).to match_array([proj1, proj2])
end
end