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

Documentation needed that #after hooks are executed for pending/skipped/failed specs #2692

Closed
skalee opened this issue Jan 30, 2020 · 3 comments

Comments

@skalee
Copy link
Contributor

skalee commented Jan 30, 2020

Subject of the issue

This issue is purely about the documentation hosted on Relish.

after(:example) hooks are executed regardless example has failed, was skipped or whatever. I am pretty convinced that this is a correct behaviour, however it does not seem to be documented in https://relishapp.com/rspec/rspec-core/v/3-9/docs, particularly not in https://relishapp.com/rspec/rspec-core/v/3-9/docs/hooks/before-and-after-hooks, nor in https://relishapp.com/rspec/rspec-core/v/3-9/docs/pending-and-skipped-examples. Same for skipped/pending specs

Your environment

  • Ruby version: 2.6.3p62
  • rspec-core version: 3.9.0

Steps to reproduce

Given following spec file after_spec.rb:

require "rspec"

RSpec.describe(":after hook is run anyway") do
  before(:example) do
    raise "in before example"
  end

  after(:example) do
    raise "in after example"
  end

  example do
    raise "in example"
  end
end

When I run rspec after_spec.rb

I see:

Failures:

  1) :after hook is run anyway
     Got 0 failures and 2 other errors:

     1.1) Failure/Error: raise "in before example"

          RuntimeError:
            in before example
          # ./after_spec.rb:5:in `block (2 levels) in <top (required)>'

     1.2) Failure/Error: raise "in after example"

          RuntimeError:
            in after example
          # ./after_spec.rb:9:in `block (2 levels) in <top (required)>'

Finished in 0.00562 seconds (files took 0.57673 seconds to load)
1 example, 1 failure

Expected behavior documentation

  1. It should be documented that :after hooks are executed despite any failures or errors in the example or respective before(:example) hooks.
  2. It should be documented that :after hooks are executed for pending examples.

Actual behavior documentation

Is silent on that.

Can you do a pull request?

Yes, but my English may need some corrections.

@pirj
Copy link
Member

pirj commented Jan 30, 2020

Pull request is welcome!

@JonRowe
Copy link
Member

JonRowe commented Jan 30, 2020

A pending example is just a failing example thats expected to fail, feel free to add a scenario to https://relishapp.com/rspec/rspec-core/v/3-9/docs/hooks/before-and-after-hooks if you'd like to illustrate that hooks runs despite a failing example, it is kind of covered implicitly elsewhere but I agree it could be more specific.

skalee added a commit to skalee/rspec-core that referenced this issue Feb 4, 2020
`after` blocks are run no matter if given example has succeeded or not.
This is normal behaviour, and this very commit adds a respective
Cucumber scenario.

Fixes rspec#2692.
@JonRowe
Copy link
Member

JonRowe commented Apr 5, 2020

Closed by #2715

@JonRowe JonRowe closed this as completed Apr 5, 2020
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

Successfully merging a pull request may close this issue.

3 participants