Replies: 2 comments 14 replies
-
It exists to back this guideline, originated here. Speaking of the example itself, I see an option to avoid stubbing by passing invalid values to the object initializer (e.g. |
Beta Was this translation helpful? Give feedback.
-
It's a personal preference, but I don't use subject(:number) { 3 }
its(:odd?) { is_expected.to be true }
it { expect(number).to be_odd }
it { is_expected.to be_odd } There are even cases where I can't tell if it { expect(number.allbits?(1)).to be true }
it { is_expected.to be_allbits(1) } |
Beta Was this translation helpful? Give feedback.
-
Can anyone help me understand the logic behind the
RSpec/SubjectStub
cop?It disallows stubbing of inner methods of the subject under test, but to me this seems like a legitimate, intuitive and readable approach. I do not see the downside, and any alternative I can think of would require more coding and less readability.
Consider this test subject:
and this spec:
running
rubocop --only RSpec
will trigger this offense:why is this bad? and what is an acceptable alternative?
Beta Was this translation helpful? Give feedback.
All reactions