我是 Rails 新手,我想用 rspec、should 和 factory girl 测试现有的 rails 项目。
我尝试为模型的变量赋值,但我不能。
这是错误;
Failure/Error: @brief.brand_info = 'bla bla bla'
NoMethodError:
undefined method `brand_info=' for nil:NilClass
# ./spec/models/brief_spec.rb:34:in `block (3 levels) in <top (required)>'
您可以通过访问此链接访问我的模型和工厂...
简要工厂代码;
Factory.define :brief, :class => Brief do |b|
b.brand_info 'brand info'
b.duration 14
end
项目工厂代码;
Factory.define :project, :class => Project do |p|
p.association :owner, :factory => :customer
p.title 'project title'
p.description 'project description'
p.stage :brief_completed
p.contest_type :standard
p.brief {|p| p.association(:brief)}
p.association :project_type, :factory => :project_type
end
Factory.define :project_with_prize, :parent => :project do |p|
p.prize 5000
p.stage :prize_determined
end
Factory.define :project_waiting_for_payment, :parent => :project_with_prize do |p|
p.stage :awaiting_payment
end
Factory.define :project_started, :parent => :project_with_prize do |p|
p.start Time.zone.now
p.end Time.zone.now.advance(:days => 14)
p.stage :started
end
Factory.define :project_started_with_no_brief, :parent => :project_with_prize do |p|
p.brief nil
p.start Time.zone.now.advance(:days => -10)
p.end Time.zone.now.advance(:days => 4)
p.stage :started
end
Factory.define :project_overdue, :parent => :project_with_prize do |p|
p.start Time.zone.now.advance(:days => -14)
p.end Time.zone.now.advance(:minutes => -15)
p.stage :started
end
Factory.define :project_ended, :parent => :project_with_prize do |p|
p.start Time.zone.now.advance(:days => -15)
p.end Time.zone.now.advance(:days => -1)
p.stage :ended
end
Factory.define :project_revising, :parent => :project_ended do |p|
p.stage :revising
end
Factory.define :project_delivering_files, :parent => :project_ended do |p|
p.stage :delivering_files
end
Factory.define :project_completed, :parent => :project_ended do |p|
p.stage :completed
end
Factory.define :faulty_project, :parent => :project do |p|
p.title nil
end