Advertisement
saasbook

spec_using_factory.rb

Sep 15th, 2014
477
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.56 KB | None | 0 0
  1. # in spec/models/movie_spec.rb
  2. describe Movie do
  3.   it 'should include rating and year in full name' do
  4.     # 'build' creates but doesn't save object; 'create' also saves it
  5.     movie = FactoryGirl.build(:movie, :title => 'Milk', :rating => 'R')
  6.     movie.name_with_rating.should == 'Milk (R)'
  7.   end
  8. end
  9. # More concise: uses Alternative RSpec2 'subject' syntax', and mixes in
  10. # FactoryGirl methods in spec_helper.rb (see FactoryGirl README)
  11. describe Movie do
  12.   subject { build :movie, :title => 'Milk', :rating => 'R' }
  13.   its(:name_with_rating) { should == 'Milk (R)' }
  14. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement