Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pending Shared Example #1583

Closed
andyl opened this issue Jun 5, 2014 · 6 comments
Closed

Pending Shared Example #1583

andyl opened this issue Jun 5, 2014 · 6 comments

Comments

@andyl
Copy link

andyl commented Jun 5, 2014

I've got a collection of duck-type classes that all implement a set of methods.
I'm able to build a shared example group that describes a these methods.

shared_examples_for "a duck type" do
  it { should respond_to(:method1) }
end
describe Class1 do
  it_should_behave_like "a duck type"
end
describe Class2 do
  it_should_behave_like "a duck type"
end

In my situation, I have implemented Class1#method1, but Class2#method1 is pending.

I'd like the ability to say:

describe Class2 do
    it_should_behave_like "a duck type", :pending
end

I can apply pending to a shared example, but not to it_should_behave_like. This is sub-optimal when working with a collection of duck-types where some class implementations are complete and others are pending.

Enhancement requests:

  1. enable the :pending attribute for it_should_behave_like
  2. enable the :skip attribute for it_should_behave_like
  3. add xit_should_behave_like
@myronmarston
Copy link
Member

Arguments passed to it_should_behave_like have a different purpose: they get yielded to the shared example group block:

https://relishapp.com/rspec/rspec-core/v/3-0/docs/example-groups/shared-examples#passing-parameters-to-a-shared-example-group

It would be confusing to treat the arguments as metadata as well. You can get the behavior you want, though:

shared_examples_for "a duck type" do |*metadata|
  context "describe this group", *metadata do
    # put the specs in here.
  end
end

@myronmarston
Copy link
Member

Alternately, if you don't want to wrap the specs in an additional context, you can support pending or skip with a before hook:

shared_examples_for "a duck type" do |*flags|
  before { pending } if flags.include?(:pending)
  # specs go here
end

@andyl
Copy link
Author

andyl commented Jun 5, 2014

Yes thanks very much - that will work perfectly.

@andyl andyl closed this as completed Jun 5, 2014
@TimMoore
Copy link

If anyone else finds this issue via Google, here's another trick you can use at the call site, which doesn't require modifying the shared examples definition to take a metadata or flags argument:

it_behaves_like 'some shared example' do
  before { pending }
end

@Startouf
Copy link

Startouf commented Jan 30, 2019

I believe the issue should be reopened and one of the following should be done

  • Either allow marking all examples as pending by wrapping them around pending blocks
pending('Reason for pending') do 
  it_behaves_like '...'
  context do 
     ...
  end
end

@andyl

@JonRowe
Copy link
Member

JonRowe commented Jan 30, 2019

Happy to accept a PR to improve the documentation if you'd like to attempt it, but I don't feel the api should be expanded to change this behaviour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants