Use lambdas for RSpec subjects
You can pass a lambda to RSpec's subject block for more concise expectations:
describe Car do
describe '.accelerate' do
subject { -> { car.accelerate } }
it { should change(car, :speed).by(1) }
end
describe '.boomtown' do
subject { -> { car.boomtown } }
it { should raise_error }
end
end
Written by Eric Holmes
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#