I recently saw code similar to this in a spec file:
RSpec.describe Foo do
subject { described_class.new }
it 'does its thing' do
some { setup }
some.other.setup
is_expected.to be_truthy
end
end
That expectation – is_expected.to be_truthy – struck me as weird. I understand the readability of the one-liner version, e.g. it { is_expected.to be_truthy }, but when there is more than one line in the block, that expectation syntax is strange.
Would it be possible to check for – and disallow – this syntax?
Yes, that would be a good cop. I can take on it in the next couple of weeks
I agree that this makes it weird for multiline blocks, but I think it with additional descriptor also could disqualify the implicit version:
it "does its thing" do
is_expected.to be_truthy
end
WDYT?
Good point, @Drenmi.
On a maybe-related note, I could see myself wanting to completely disable the it { some_expectation } syntax. Do we currently have a cop that would do this, or does RSpec have a configuration for it?
ExampleWithoutDescription configured with EnforcedStyle: disallow will complain about it not having a description
Most helpful comment
ExampleWithoutDescriptionconfigured withEnforcedStyle: disallowwill complain aboutitnot having a description