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

Prevent invalid encoding for files blowing up Source.from_file #364

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

JonRowe
Copy link
Member

@JonRowe JonRowe commented Feb 5, 2019

From #354 an invalid encoding combination in a file can cause an error which stops RSpec from running and highlighting the correct cause:

Traceback (most recent call last):
	28: from bin/ruby_executable_hooks:24:in `<main>'
	27: from bin/ruby_executable_hooks:24:in `eval'
	26: from bin/rspec:23:in `<main>'
	25: from bin/rspec:23:in `load'
	24: from gems/rspec-core-3.8.0/exe/rspec:4:in `<top (required)>'
	23: from gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:45:in `invoke'
	22: from gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:71:in `run'
	21: from gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:86:in `run'
	20: from gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:98:in `setup'
	19: from gems/rspec-core-3.8.0/lib/rspec/core/configuration.rb:1558:in `load_spec_files'
	18: from gems/rspec-core-3.8.0/lib/rspec/core/configuration.rb:1558:in `each'
	17: from gems/rspec-core-3.8.0/lib/rspec/core/configuration.rb:1560:in `block in load_spec_files'
	16: from gems/rspec-core-3.8.0/lib/rspec/core/configuration.rb:2033:in `load_file_handling_errors'
	15: from gems/rspec-core-3.8.0/lib/rspec/core/configuration.rb:2037:in `rescue in load_file_handling_errors'
	14: from gems/rspec-core-3.8.0/lib/rspec/core/reporter.rb:161:in `notify_non_example_exception'
	13: from gems/rspec-core-3.8.0/lib/rspec/core/formatters/exception_presenter.rb:78:in `fully_formatted'
	12: from gems/rspec-core-3.8.0/lib/rspec/core/formatters/exception_presenter.rb:86:in `fully_formatted_lines'
	11: from gems/rspec-core-3.8.0/lib/rspec/core/formatters/exception_presenter.rb:240:in `formatted_message_and_backtrace'
	10: from gems/rspec-core-3.8.0/lib/rspec/core/formatters/exception_presenter.rb:34:in `colorized_message_lines'
	 9: from gems/rspec-core-3.8.0/lib/rspec/core/formatters/exception_presenter.rb:149:in `failure_lines'
	 8: from gems/rspec-core-3.8.0/lib/rspec/core/formatters/exception_presenter.rb:149:in `tap'
	 7: from gems/rspec-core-3.8.0/lib/rspec/core/formatters/exception_presenter.rb:150:in `block in failure_lines'
	 6: from gems/rspec-core-3.8.0/lib/rspec/core/formatters/exception_presenter.rb:163:in `failure_slash_error_lines'
	 5: from gems/rspec-core-3.8.0/lib/rspec/core/formatters/exception_presenter.rb:218:in `read_failed_lines'
	 4: from gems/rspec-core-3.8.0/lib/rspec/core/formatters/snippet_extractor.rb:30:in `extract_expression_lines_at'
	 3: from gems/rspec-core-3.8.0/lib/rspec/core/formatters/snippet_extractor.rb:18:in `source_from_file'
	 2: from gems/rspec-core-3.8.0/lib/rspec/core/world.rb:150:in `source_from_file'
	 1: from gems/rspec-support-3.8.0/lib/rspec/support/source.rb:12:in `from_file'
gems/rspec-support-3.8.0/lib/rspec/support/source.rb:12:in `read': U+043F from UTF-8 to ASCII-8BIT (Encoding::UndefinedConversionError)

After this PR:

An error occurred while loading ./spec/support/source_spec.broken_example.
Failure/Error: Unable to find matching line in ./spec/support/source_spec.broken_example

NameError:
  uninitialized constant UndeclaredModule

@JonRowe JonRowe force-pushed the invalid-encoding-source-from-file-fix branch from 8bc3b72 to 7aa2de0 Compare June 12, 2019 20:51
@JonRowe JonRowe changed the base branch from master to main August 2, 2020 01:55
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 this pull request may close these issues.

1 participant