私はRailsの初心者で、rspec、shoulda、factorygirlを使用して既存の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