psyho / bogus

Fake library for Ruby
Other
359 stars 14 forks source link

RSpec 3 Shared Examples Support #63

Open tpendragon opened 9 years ago

tpendragon commented 9 years ago

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 commented 9 years ago

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
psyho commented 9 years ago

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.

tpendragon commented 9 years ago

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

let(:resource_class) { described_class }

didn't even work.

psyho commented 9 years ago

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

psyho commented 9 years ago

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.