(this started on twitter)
The microposts spec starts out with
let(:user) { FactoryGirl.create(:user) }
before do
# This code is wrong!
@micropost = Micropost.new(content: "Lorem ipsum", user_id: user.id)
end
subject { @micropost }
Michael is telling you the code is wrong to set an instance variable in the spec. Instead, you should just:
let(:user) { FactoryGirl.create(:user) }
subject { Micropost.new(content: "Lorem ipsum", user_id: user.id) }
This way, the subject is set to the Micropost.new
The same happens in my Dog example... We are setting the subject to a new instance of Dog.
describe Dog do
This will set the subject
to Dog.new
I definitely shouldn't have put words in Michael's mouth; I assumed what was "wrong" with the spec syntax without knowing.
IMHO, using instance variables is not as flexible as using lets.