我正在使用 Mongoid。我有一个对象:
class Employee
include Mongoid::Document
field :name_first, type: String
field :name_last, type: String
field :name_other, type: Array, default: []
field :title, type: String
field :education, type: Hash, default: {}
field :languages, type: Array, default: []
field :phone, type: Hash, default: {}
field :address, type: Hash, default: {}
field :email, type: Array, default: []
field :url, type: Array, default: []
field :history, type: Array, default: []
field :profile, type: String
field :social_media, type: Hash, default: {}
field :last_contact, type: Time
field :signed_up, type: Date
belongs_to :user
belongs_to :practice
end
而且,我正在尝试使用 Fabrication,但遇到了问题。宝石安装良好。在 /spec/fabricators/employee_fabricator.rb 我有
Fabricator :employee do
end
在 my_controller_spec.rb 我有:
describe CasesController do
describe "viewing cases" do
before(:each) do
Fabricate(:employee)
end
it "allows viewing the cases index page" do
get 'index'
response.should_not be_success
end
end
end
当我在终端中运行“rspec spec”时,我得到:
Failures:
1) CasesController viewing cases allows viewing the cases index page
Failure/Error: Fabricate(:employee)
ArgumentError:
wrong number of arguments (2 for 1)
这里发生了什么?我尝试了各种排列,其中一些会引发其他错误,但没有任何运行。不调用 Fabricate(:employee) 行,它按预期运行,但到目前为止只有空测试......