-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Fix typo in rescue_from unit test (Communication --> Communications). #546
Conversation
Fix typo in rescue_from unit test (Communication --> Communications).
Sorry for nitpicking, but this test case is unclear for me: it 'does not rescue child errors for other rescue_from instances' do
class CommunicationsError < RuntimeError; end
class BadCommunicationError < CommunicationError; end
class ProcessingError < RuntimeError; end
class BadProcessingError < ProcessingError; end
subject.rescue_from CommunicationError, rescue_subclasses: true do |e|
rack_response("rescued from #{e.class.name}", 500)
end
subject.rescue_from ProcessingError, rescue_subclasses: false do |e|
rack_response("rescued from #{e.class.name}", 500)
end
subject.get '/caught_child' do
raise BadCommunicationError
end
subject.get '/uncaught_child' do
raise BadProcessingError
end
get '/caught_child'
last_response.status.should eql 500
lambda { get '/uncaught_child' }.should raise_error(BadProcessingError)
end if you look closely, you can found the same conditions and assertions here: it 'rescues error as well as child errors with rescue_children option set' do
class CommunicationsError < RuntimeError; end
subject.rescue_from RuntimeError, rescue_subclasses: true do |e|
rack_response("rescued from #{e.class.name}", 500)
end
subject.get '/caught_child' do
raise CommunicationsError
end
subject.get '/caught_parent' do
raise RuntimeError
end
subject.get '/uncaught_parent' do
raise StandardError
end
get '/caught_child'
last_response.status.should eql 500
get '/caught_parent'
last_response.status.should eql 500
lambda { get '/uncaught_parent' }.should raise_error(StandardError)
end
it 'does not rescue child errors if rescue_subclasses is false' do
class CommunicationsError < RuntimeError; end
subject.rescue_from RuntimeError, rescue_subclasses: false do |e|
rack_response("rescued from #{e.class.name}", 500)
end
subject.get '/uncaught' do
raise CommunicationsError
end
lambda { get '/uncaught' }.should raise_error(CommunicationsError)
end BTW, It will be better to use |
@dm1try has some good points, would love further iteration from either of you |
@dm1try Sorry, this is my fault for wanting to reuse names across unit tests for simplicity, then typo'ing. I will change to use completely different names for exception classes across test cases to avoid this. If I do this, I'll end up not using the same names as in the README (except for one of the tests). Already in other tests in the same area, I found reuse of error class definitions across tests, so I thought it was safe to do this, but it seems definitions survive between If context/before blocks will avoid this, I'll refactor to use that (including other tests than the one I wrote, related to rescue_from). The reason for the first test case combining both was to show that if you use two rescue_from clauses, one with and one without rescue_subclasses true, setting one will have no effect on the other (isolation). This may have been overzealous on my part, but as I was coding, this issue happened because the setting I used was global. I think we can safely remove this test now. |
@dm1try Before I go in to fix things, I was hoping you could help me with a few questions:
Thanks for catching these, and sorry for the trouble. |
@dm1try It seems that class definitions can't be scoped within a context/before block. No matter what, using the same name but 2 different class definitions will result in an error, which is unfortunate. describe 'something' do
context 'first definition' do
before do
class ConnectionError < StandardError; end
end
it 'uses the first definition' do
# ...
puts "Using class #{ConnectionError}"
end
end
context 'second definition' do
before do
class ConnectionError < RuntimeError; end
end
it "uses the second definition"
puts "This test will fail when ConnectionError fails to be redefined"
end
end
end The actual error will look like:
So if I use the same name in different areas, I have to ensure the definition is also identical or it will die. I like reusing the same names because it's easier to read, so I'll come up with a branch that does that and ask for your thoughts again. |
I merged #548. Please don't hesitate to refactor code that's not yours, this is a community project. |
Typo on one of the unit tests which made it pass falsely (fixing the typo it still passes, but now correctly).