rspec-wait
rspec-wait copied to clipboard
Wait.for doesn't seem to work well with raise_error expectations
Hi,
I'm trying to wait for a system to leave an error state, but the system always raises exceptions, to try and wait for it i ended up using a wait.for but couldn't find a way to do it without causing the underlying exception from always being thrown. I have some basic specs that demonstrate the behaviour
it "respects the raise_error matcher and raise and expectation not met error " do
expect {
wait(1).for { raise RuntimeError }.to_not raise_error
}.to raise_error(RSpec::Expectations::ExpectationNotMetError)
end
This spec here raises this error
1) wait for not_to respects the raise_error matcher and raise and expectation not met error
Failure/Error:
expect {
wait(1).for { raise RuntimeError }.to_not raise_error
}.to raise_error(RSpec::Expectations::ExpectationNotMetError)
expected RSpec::Expectations::ExpectationNotMetError, got #<RuntimeError: RuntimeError> with backtrace:
When i try and do the positive match e.g.
it "respects the raise_error matcher and only raises the matcher exception" do
wait.for { raise RuntimeError }.to raise_error(RuntimeError)
end
I get this error
Failures:
1) wait for to respects the raise_error matcher and only raises the matcher exception
Failure/Error: wait.for { raise RuntimeError }.to raise_error(RuntimeError)
RuntimeError:
RuntimeError
As you can see, the Runtime error is being raised from the wait.for the block, and the raise_error matcher never seems to convert it to a success.
Is this expected behaviour? Should I be converting my exception into a value inside the block to prevent the wait.for from being exposed to it?
This was tested against
PATH
remote: .
specs:
rspec-wait (0.0.9)
rspec (>= 3, < 4)
GEM
remote: https://rubygems.org/
specs:
byebug (9.1.0)
diff-lcs (1.3)
rake (11.3.0)
rspec (3.6.0)
rspec-core (~> 3.6.0)
rspec-expectations (~> 3.6.0)
rspec-mocks (~> 3.6.0)
rspec-core (3.6.0)
rspec-support (~> 3.6.0)
rspec-expectations (3.6.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.6.0)
rspec-mocks (3.6.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.6.0)
rspec-support (3.6.0)
PLATFORMS
ruby
DEPENDENCIES
bundler (~> 1.12)
byebug
rake (~> 11.2)
rspec-wait!
BUNDLED WITH
1.15.3
This is a very interesting case, thank you! Would you be comfortable committing your failing tests and submitting a pull request? It's okay that they're red. If you want to make them green, even better! 😉
+1 I'm also hitting this issue.