, . , , , proc raise_error .
I found that you can give names subjects, for example lets. This will allow you to reference the named subjectfrom the outer scope in the new one subject. Here is an example:
describe 'do_some_math' do
let!(:calculator) { create(:calculator) }
subject(:do_some_math) {
-> { calculator.do_some_math(with, complicated, args) }
}
context 'when something breaks' do
it { is_expected.to raise_error }
end
context 'when everything works' do
subject { do_some_math.call }
it { is_expected.to be_a(Numeric) }
end
end
source
share