The error message says it all:
Then is not available from within an example (eg an it block) or from constructs that run in the scope of an example (eg before, let, etc). It is only available on an example group (eg a describe or context block).
read the error message carefully. And you have a solution in the error message itself.
You cannot use Then inside the it block, you can use Then only with describe or context .
So, to solve your problem, just use context instead of it :
describe SchoolService do Given(:school) { create(:school_with_applications) } Given(:service) { School.new(@school) } describe 'create_default_programs_and_year_grades!' do context 'checks program size' do When { service.create_default_programs_and_year_grades! } Then { expect(school.programs.size).to eq 3 } end end end
More examples here .
source share