0

Here is my Lesson Factory i-e lesson.rb

FactoryGirl.define do
  factory :lesson do |lesson|
   lesson.sequence(:title) { |n| "title#{n}" }
   lesson.sequence(:description) { |n| "description#{n}" }
   lesson.sequence(:transcript) { |n| "transcript#{n}" }
   association :course, strategy: :build
  end
end

Here is my lesson_spec.rb file

require 'spec_helper'

describe Lesson do
  before { let(:lesson) { FactoryGirl.create(:lesson) } }
  subject (:lesson)
  it { should validate_presence_of :title    }
end

Any Help? Thanks in advance!!!

Ch Zeeshan
  • 1,644
  • 11
  • 29

3 Answers3

0

you don't need the before statement in the before block.

before { let(:lesson) { FactoryGirl.create(:lesson) } }

change to this

let(:lesson) { FactoryGirl.create(:lesson)
muttonlamb
  • 6,341
  • 3
  • 26
  • 35
0

Simple you dont needed let in before, either you would use before or let i would prefer to use let, have look at this answerexplainin when to use let and when to use before.

require 'spec_helper'

describe Lesson do
  let(:lesson) { FactoryGirl.create(:lesson) }
  subject (lesson)
  it { should validate_presence_of :title    }
end
Community
  • 1
  • 1
Muhamamd Awais
  • 2,385
  • 14
  • 25
0

I did i this way and it works

require 'spec_helper'

describe Lesson do
  subject { FactoryGirl.create(:lesson) }
  it { should validate_presence_of :title    }
Ch Zeeshan
  • 1,644
  • 11
  • 29