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

raise_error + a block produces wrong failure message #93

Open
mcmire opened this issue Jun 29, 2020 · 5 comments
Open

raise_error + a block produces wrong failure message #93

mcmire opened this issue Jun 29, 2020 · 5 comments
Labels

Comments

@mcmire
Copy link
Collaborator

mcmire commented Jun 29, 2020

When using raise_error with a block and the block contains an assertion, the generated failure message includes the full error message of that assertion.

@pavolzbell
Copy link

Hello @mcmire, maybe I bumped into this one today, here is a sample output from our JRuby project running on:

  • rspec-core 3.9.2
  • rspec-rails 4.0.1
  • super_diff 0.5.2
     Failure/Error: expect { subject.call(service, request) }.to raise(Java::JavaxXmlWsSoap::SOAPFaultException) { expect(1).to eq(0) }

       Expected raised exception #<RSpec::Expectations::ExpectationNotMetError "Expected \e[33m1\e[0m to eq \e[35m0\e[0m.">
                        to match #<Java::JavaxXmlWsSoap::SOAPFaultException>

Is there any chance for you to fix it? Can I help somehow?

Also wondering if this affects custom matchers which use nested expect calls inside match do |actual| ... end blocks...

@mcmire
Copy link
Collaborator Author

mcmire commented Oct 22, 2020

I think in this case you might need to use raise_error, not raise? Or can you use raise in JRuby like that, when you're writing an expectation?

@pavolzbell
Copy link

Oh, I'm sorry, of course it's raise_error, I just incorrectly copied the code, here is a short example you can run:

expect { raise 'x' }.to raise_error(RuntimeError) { |e| expect(e.message).to eq('x') } #=> true
expect { raise 'x' }.to raise_error(RuntimeError) { |e| expect(e.message).to eq('y') }
RSpec::Expectations::ExpectationNotMetError: Expected raised exception #<RSpec::Expectations::ExpectationNotMetError "Expected \e[33m\"x\"\e[0m to eq \e[35m\"y\"\e[0m.">
                 to match #<RuntimeError>

@mcmire
Copy link
Collaborator Author

mcmire commented Oct 26, 2020

Gotcha. 👍 Thanks for confirming this issue!

@mcmire
Copy link
Collaborator Author

mcmire commented Dec 17, 2020

Going back to the original issue, just ran into this again today. Here's a screenshot:

Screen Shot 2020-12-17 at 11 27 03 AM

@mcmire mcmire changed the title raise_error with a block raise_error + a block produces wrong failure message Feb 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants