这是我的代码工作但我的测试失败并且我需要知道我做错了什么的情况之一?
我有一个项目类,它的all
方法只是吐出这个类的实例:
class Project
@@all_projects = []
def initialize(options)
@@all_projects << self
end
def self.all
@@all_projects
end
end
现在Project.all
工作得很好,但我写的规范没有。
context "manipulating projects" do
before do
options1 = {
name: 'Building house'
}
options2 = {
name: 'Getting a loan from the Bank'
}
@project1 = Project.new(options1)
@project2 = Project.new(options2)
end
it "can print all projects" do
Project.all.should eq([@project1, @project2])
end
我收到的失败消息是:
Project manipulating projects can print all projects
Failure/Error: Project.all.should eq([@project1, @project2])
expected: [Building house, Getting a loan from the Bank]
got: [Building house, Building house, Building house, Getting a loan from the Bank, Building house, Getting a loan from the Bank]
这是要点中的完整规范:https ://gist.github.com/4535863
我究竟做错了什么?我该如何解决?