Skip to content

Instantly share code, notes, and snippets.

@urbanautomaton
Created June 23, 2016 12:36
Show Gist options
  • Save urbanautomaton/c51e2537718b44e35f2274c09a03b9b4 to your computer and use it in GitHub Desktop.
Save urbanautomaton/c51e2537718b44e35f2274c09a03b9b4 to your computer and use it in GitHub Desktop.
actually, factory_girl is extremely good
RSpec.describe 'FactoryGirl.build_stubbed' do
let(:stubbed_model) { FactoryGirl.build_stubbed(:step_progress) }
it 'doesnt allow #save' do
expect {
stubbed_model.save
}.to raise_error RuntimeError, /stubbed models are not allowed to access the database/
end
it 'doesnt allow #update_attributes' do
expect {
stubbed_model.update_attributes(created_at: Time.now)
}.to raise_error RuntimeError, /stubbed models are not allowed to access the database/
end
it 'allows #save!' do
stubbed_model.save!
end
it 'allows #touch' do
stubbed_model.touch(:last_completed_at)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment