bogus
bogus copied to clipboard
RSpec 3 Shared Examples Support
Not sure if this is specific to RSpec 3 - I'm trying to use Bogus and have two classes that have similar contracts (as one's a subclass of another). I'd normally put these in a shared example group and run those contract tests on both - but when I do that, Bogus doesn't pick up that the methods ran. Thoughts?
So this is because the described_class is overriden by Bogus and so doesn't match. I had to do this.
RSpec.shared_examples "a term" do
let(:id) { "Creator" }
let(:resource) { resource_class.new(id) }
end
RSpec.describe Term do
verify_contract(:term)
it_behaves_like "a term" do
let(:resource_class) { Term }
end
end
Thanks for reporting the issue. I just released version 0.1.6 which should have a fix for overwriting #described_class in RSpec 3.* (it was a problem I encountered in our integration tests). I'd really appreciate it, if you tried running your tests with updated bogus version and see if it fixed your issue as well.
@psyho No go. The described_class didn't get overwritten.
let(:resource_class) { described_class }
didn't even work.
That's a shame, I'll look into this in more detail then. Thanks for checking.
I've spent some time debugging this issue today, and it looks like there's no reliable way to overwrite described_class
in RSpec 3. I think I'm going to introduce a new helper method, like bogus_described_class
and stop overwriting described_class altogether.