bogus icon indicating copy to clipboard operation
bogus copied to clipboard

RSpec 3 Shared Examples Support

Open tpendragon opened this issue 10 years ago • 5 comments

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?

tpendragon avatar Dec 24 '14 00:12 tpendragon

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

tpendragon avatar Dec 24 '14 01:12 tpendragon

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 avatar Jan 02 '15 14:01 psyho

@psyho No go. The described_class didn't get overwritten.

let(:resource_class) { described_class }

didn't even work.

tpendragon avatar Jan 02 '15 16:01 tpendragon

That's a shame, I'll look into this in more detail then. Thanks for checking.

psyho avatar Jan 05 '15 08:01 psyho

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.

psyho avatar Jan 09 '15 13:01 psyho