function_name
stringlengths
2
43
file_path
stringlengths
20
71
focal_code
stringlengths
176
2.2k
file_content
stringlengths
428
89.7k
language
stringclasses
1 value
function_component
dict
metadata
dict
ascend_until
rspec-core/lib/rspec/core/ruby_project.rb
def ascend_until fs = File::SEPARATOR escaped_slash = "\\#{fs}" special = "_RSPEC_ESCAPED_SLASH_" project_path = File.expand_path(".") parts = project_path.gsub(escaped_slash, special).squeeze(fs).split(fs).map do |x| x.gsub(special, escaped_slash) end ...
# This is borrowed (slightly modified) from Scott Taylor's # project_path project: # http://github.com/smtlaissezfaire/project_path module RSpec module Core # @private module RubyProject def add_to_load_path(*dirs) dirs.each { |dir| add_dir_to_load_path(File.join(root, dir)) } end ...
Ruby
{ "end_line": 43, "name": "ascend_until", "signature": "def ascend_until", "start_line": 28 }
{ "class_name": "", "class_signature": "", "module": "RSpec" }
autorun
rspec-core/lib/rspec/core/runner.rb
def self.autorun if autorun_disabled? RSpec.deprecate("Requiring `rspec/autorun` when running RSpec via the `rspec` command") return elsif installed_at_exit? || running_in_drb? return end at_exit { perform_at_exit } @installed_at_exit = true e...
module RSpec module Core # Provides the main entry point to run a suite of RSpec examples. class Runner # @attr_reader # @private attr_reader :options, :configuration, :world # Register an `at_exit` hook that runs the suite when the process exits. # # @note This is not gen...
Ruby
{ "end_line": 26, "name": "autorun", "signature": "def self.autorun", "start_line": 16 }
{ "class_name": "Runner", "class_signature": "class Runner", "module": "RSpec" }
running_in_drb?
rspec-core/lib/rspec/core/runner.rb
def self.running_in_drb? return false unless defined?(DRb) server = begin DRb.current_server rescue DRb::DRbServerNotFound return false end return false unless server && server.alive? require 'socket' requ...
module RSpec module Core # Provides the main entry point to run a suite of RSpec examples. class Runner # @attr_reader # @private attr_reader :options, :configuration, :world # Register an `at_exit` hook that runs the suite when the process exits. # # @note This is not gen...
Ruby
{ "end_line": 172, "name": "running_in_drb?", "signature": "def self.running_in_drb?", "start_line": 151 }
{ "class_name": "Runner", "class_signature": "class Runner", "module": "RSpec" }
handle_interrupt
rspec-core/lib/rspec/core/runner.rb
def self.handle_interrupt if RSpec.world.wants_to_quit exit!(1) else RSpec.world.wants_to_quit = true $stderr.puts( "\nRSpec is shutting down and will print the summary report... Interrupt again to force quit " \ "(warning: at_exit hooks will be ski...
module RSpec module Core # Provides the main entry point to run a suite of RSpec examples. class Runner # @attr_reader # @private attr_reader :options, :configuration, :world # Register an `at_exit` hook that runs the suite when the process exits. # # @note This is not gen...
Ruby
{ "end_line": 191, "name": "handle_interrupt", "signature": "def self.handle_interrupt", "start_line": 180 }
{ "class_name": "Runner", "class_signature": "class Runner", "module": "RSpec" }
sandboxed
rspec-core/lib/rspec/core/sandbox.rb
def self.sandboxed orig_config = RSpec.configuration orig_world = RSpec.world orig_example = RSpec.current_example RSpec.configuration = RSpec::Core::Configuration.new RSpec.world = RSpec::Core::World.new(RSpec.configuration) yield RSpec.configuration e...
module RSpec module Core # A sandbox isolates the enclosed code into an environment that looks 'new' # meaning globally accessed objects are reset for the duration of the # sandbox. # # @note This module is not normally available. You must require # `rspec/core/sandbox` to load it. modul...
Ruby
{ "end_line": 34, "name": "sandboxed", "signature": "def self.sandboxed", "start_line": 21 }
{ "class_name": "", "class_signature": "", "module": "RSpec" }
add
rspec-core/lib/rspec/core/shared_example_group.rb
def add(context, name, *metadata_args, &block) unless block RSpec.warning "Shared example group #{name} was defined without a "\ "block and will have no effect. Please define a "\ "block or remove the definition." end if RSpe...
RSpec::Support.require_rspec_support "with_keywords_when_needed" module RSpec module Core # Represents some functionality that is shared with multiple example groups. # The functionality is defined by the provided block, which is lazily # eval'd when the `SharedExampleGroupModule` instance is included in...
Ruby
{ "end_line": 172, "name": "add", "signature": "def add(context, name, *metadata_args, &block)", "start_line": 150 }
{ "class_name": "Registry", "class_signature": "class Registry", "module": "RSpec" }
legacy_add
rspec-core/lib/rspec/core/shared_example_group.rb
def legacy_add(context, name, *metadata_args, &block) ensure_block_has_source_location(block) { CallerFilter.first_non_rspec_line } shared_module = SharedExampleGroupModule.new(name, block, {}) if valid_name?(name) warn_if_key_taken context, name, block shared_exam...
RSpec::Support.require_rspec_support "with_keywords_when_needed" module RSpec module Core # Represents some functionality that is shared with multiple example groups. # The functionality is defined by the provided block, which is lazily # eval'd when the `SharedExampleGroupModule` instance is included in...
Ruby
{ "end_line": 202, "name": "legacy_add", "signature": "def legacy_add(context, name, *metadata_args, &block)", "start_line": 189 }
{ "class_name": "Registry", "class_signature": "class Registry", "module": "RSpec" }
warn_if_key_taken
rspec-core/lib/rspec/core/shared_example_group.rb
def warn_if_key_taken(context, key, new_block) existing_module = shared_example_groups[context][key] return unless existing_module old_definition_location = formatted_location existing_module.definition new_definition_location = formatted_location new_block loaded_spec...
RSpec::Support.require_rspec_support "with_keywords_when_needed" module RSpec module Core # Represents some functionality that is shared with multiple example groups. # The functionality is defined by the provided block, which is lazily # eval'd when the `SharedExampleGroupModule` instance is included in...
Ruby
{ "end_line": 242, "name": "warn_if_key_taken", "signature": "def warn_if_key_taken(context, key, new_block)", "start_line": 215 }
{ "class_name": "Registry", "class_signature": "class Registry", "module": "RSpec" }
announce_filters
rspec-core/lib/rspec/core/world.rb
def announce_filters fail_if_config_and_cli_options_invalid filter_announcements = [] announce_inclusion_filter filter_announcements announce_exclusion_filter filter_announcements unless filter_manager.empty? if filter_announcements.length == 1 report_filt...
module RSpec module Core # @api private # # Internal container for global non-configuration data. class World # @private attr_reader :example_groups, :filtered_examples, :example_group_counts_by_spec_file # Used internally to determine what to do when a SIGINT is received. att...
Ruby
{ "end_line": 202, "name": "announce_filters", "signature": "def announce_filters", "start_line": 171 }
{ "class_name": "World", "class_signature": "class World", "module": "RSpec" }
descending_declaration_line_numbers_by_file
rspec-core/lib/rspec/core/world.rb
def descending_declaration_line_numbers_by_file @descending_declaration_line_numbers_by_file ||= begin declaration_locations = FlatMap.flat_map(example_groups, &:declaration_locations) hash_of_arrays = Hash.new { |h, k| h[k] = [] } # TODO: change `inject` to `each_with_object` whe...
module RSpec module Core # @api private # # Internal container for global non-configuration data. class World # @private attr_reader :example_groups, :filtered_examples, :example_group_counts_by_spec_file # Used internally to determine what to do when a SIGINT is received. att...
Ruby
{ "end_line": 250, "name": "descending_declaration_line_numbers_by_file", "signature": "def descending_declaration_line_numbers_by_file", "start_line": 234 }
{ "class_name": "World", "class_signature": "class World", "module": "RSpec" }
bisect
rspec-core/lib/rspec/core/bisect/coordinator.rb
def bisect repro = start_bisect_runner do |runner| minimizer = ExampleMinimizer.new(@shell_command, runner, @notifier) gracefully_abort_on_sigint(minimizer) minimizer.find_minimal_repro minimizer.repro_command_for_currently_needed_ids end @...
RSpec::Support.require_rspec_core "bisect/shell_command" RSpec::Support.require_rspec_core "bisect/example_minimizer" RSpec::Support.require_rspec_core "bisect/utilities" RSpec::Support.require_rspec_core "formatters/bisect_progress_formatter" module RSpec module Core module Bisect # The main entry point i...
Ruby
{ "end_line": 43, "name": "bisect", "signature": "def bisect", "start_line": 26 }
{ "class_name": "Coordinator", "class_signature": "class Coordinator", "module": "RSpec" }
find_minimal_repro
rspec-core/lib/rspec/core/bisect/example_minimizer.rb
def find_minimal_repro prep _, duration = track_duration do bisect(non_failing_example_ids) end notify(:bisect_complete, :duration => duration, :original_non_failing_count => non_failing_example_ids.size, ...
RSpec::Support.require_rspec_core "bisect/utilities" module RSpec module Core module Bisect # @private # Contains the core bisect logic. Searches for examples we can ignore by # repeatedly running different subsets of the suite. class ExampleMinimizer attr_reader :shell_command, :...
Ruby
{ "end_line": 31, "name": "find_minimal_repro", "signature": "def find_minimal_repro", "start_line": 19 }
{ "class_name": "ExampleMinimizer", "class_signature": "class ExampleMinimizer", "module": "RSpec" }
bisect
rspec-core/lib/rspec/core/bisect/example_minimizer.rb
def bisect(candidate_ids) notify(:bisect_dependency_check_started) if get_expected_failures_for?([]) notify(:bisect_dependency_check_failed) self.remaining_ids = [] return end notify(:bisect_dependency_check_passed) bisect_over(candi...
RSpec::Support.require_rspec_core "bisect/utilities" module RSpec module Core module Bisect # @private # Contains the core bisect logic. Searches for examples we can ignore by # repeatedly running different subsets of the suite. class ExampleMinimizer attr_reader :shell_command, :...
Ruby
{ "end_line": 43, "name": "bisect", "signature": "def bisect(candidate_ids)", "start_line": 33 }
{ "class_name": "ExampleMinimizer", "class_signature": "class ExampleMinimizer", "module": "RSpec" }
bisect_over
rspec-core/lib/rspec/core/bisect/example_minimizer.rb
def bisect_over(candidate_ids) return if candidate_ids.one? notify( :bisect_round_started, :candidate_range => example_range(candidate_ids), :candidates_count => candidate_ids.size ) slice_size = (candidate_ids.length / 2.0).ceil lh...
RSpec::Support.require_rspec_core "bisect/utilities" module RSpec module Core module Bisect # @private # Contains the core bisect logic. Searches for examples we can ignore by # repeatedly running different subsets of the suite. class ExampleMinimizer attr_reader :shell_command, :...
Ruby
{ "end_line": 81, "name": "bisect_over", "signature": "def bisect_over(candidate_ids)", "start_line": 45 }
{ "class_name": "ExampleMinimizer", "class_signature": "class ExampleMinimizer", "module": "RSpec" }
prep
rspec-core/lib/rspec/core/bisect/example_minimizer.rb
def prep notify(:bisect_starting, :original_cli_args => shell_command.original_cli_args, :bisect_runner => runner.class.name) _, duration = track_duration do original_results = runner.original_results @all_example_ids = original_resul...
RSpec::Support.require_rspec_core "bisect/utilities" module RSpec module Core module Bisect # @private # Contains the core bisect logic. Searches for examples we can ignore by # repeatedly running different subsets of the suite. class ExampleMinimizer attr_reader :shell_command, :...
Ruby
{ "end_line": 132, "name": "prep", "signature": "def prep", "start_line": 113 }
{ "class_name": "ExampleMinimizer", "class_signature": "class ExampleMinimizer", "module": "RSpec" }
get_expected_failures_for?
rspec-core/lib/rspec/core/bisect/example_minimizer.rb
def get_expected_failures_for?(ids) ids_to_run = all_example_ids & (ids + failed_example_ids) notify( :bisect_individual_run_start, :command => shell_command.repro_command_from(ids_to_run), :ids_to_run => ids_to_run ) results, duration = track...
RSpec::Support.require_rspec_core "bisect/utilities" module RSpec module Core module Bisect # @private # Contains the core bisect logic. Searches for examples we can ignore by # repeatedly running different subsets of the suite. class ExampleMinimizer attr_reader :shell_command, :...
Ruby
{ "end_line": 151, "name": "get_expected_failures_for?", "signature": "def get_expected_failures_for?(ids)", "start_line": 138 }
{ "class_name": "ExampleMinimizer", "class_signature": "class ExampleMinimizer", "module": "RSpec" }
initialize
rspec-core/lib/rspec/core/bisect/fork_runner.rb
def initialize(runner, channel) @runner = runner @channel = channel @spec_output = StringIO.new runner.configuration.tap do |c| c.reset_reporter c.output_stream = @spec_output c.error_stream = @spec_output end ...
require 'stringio' RSpec::Support.require_rspec_core "formatters/base_bisect_formatter" RSpec::Support.require_rspec_core "bisect/utilities" module RSpec module Core module Bisect # A Bisect runner that runs requested subsets of the suite by forking # sub-processes. The main process bootstraps RSpec ...
Ruby
{ "end_line": 91, "name": "initialize", "signature": "def initialize(runner, channel)", "start_line": 80 }
{ "class_name": "ForkRunner", "class_signature": "class ForkRunner", "module": "RSpec" }
capture_run_results
rspec-core/lib/rspec/core/bisect/server.rb
def capture_run_results(files_or_directories_to_run=[], expected_failures=[]) self.expected_failures = expected_failures self.files_or_directories_to_run = files_or_directories_to_run self.latest_run_results = nil run_output = yield if latest_run_results.nil? || lates...
require 'drb/drb' require 'drb/acl' RSpec::Support.require_rspec_core "bisect/utilities" module RSpec module Core # @private module Bisect # @private # A DRb server that receives run results from a separate RSpec process # started by the bisect process. class Server def self.r...
Ruby
{ "end_line": 32, "name": "capture_run_results", "signature": "def capture_run_results(files_or_directories_to_run=[], expected_failures=[])", "start_line": 21 }
{ "class_name": "Server", "class_signature": "class Server", "module": "RSpec" }
command_for
rspec-core/lib/rspec/core/bisect/shell_command.rb
def command_for(locations, server) parts = [] parts << RUBY << load_path parts << open3_safe_escape(RSpec::Core.path_to_executable) parts << "--format" << "bisect-drb" parts << "--drb-port" << server.drb_port parts.concat(reusable_cli_options) p...
RSpec::Support.require_rspec_core "shell_escape" require 'shellwords' module RSpec module Core module Bisect # Provides an API to generate shell commands to run the suite for a # set of locations, using the given bisect server to capture the results. # @private class ShellCommand ...
Ruby
{ "end_line": 30, "name": "command_for", "signature": "def command_for(locations, server)", "start_line": 17 }
{ "class_name": "ShellCommand", "class_signature": "class ShellCommand", "module": "RSpec" }
reusable_cli_options
rspec-core/lib/rspec/core/bisect/shell_command.rb
def reusable_cli_options @reusable_cli_options ||= begin opts = original_cli_args_without_locations if (port = parsed_original_cli_options[:drb_port]) opts -= %W[ --drb-port #{port} ] end parsed_original_cli_options.fetch(:formatters) { [] }.each...
RSpec::Support.require_rspec_core "shell_escape" require 'shellwords' module RSpec module Core module Bisect # Provides an API to generate shell commands to run the suite for a # set of locations, using the given bisect server to capture the results. # @private class ShellCommand ...
Ruby
{ "end_line": 97, "name": "reusable_cli_options", "signature": "def reusable_cli_options", "start_line": 82 }
{ "class_name": "ShellCommand", "class_signature": "class ShellCommand", "module": "RSpec" }
run_command
rspec-core/lib/rspec/core/bisect/shell_runner.rb
def run_command(cmd) out = err = nil original_spec_opts = ENV['SPEC_OPTS'] ENV['SPEC_OPTS'] = @shell_command.spec_opts_without_bisect Open3.popen3(cmd) do |_, stdout, stderr| # Reading the streams blocks until the process is complete out = st...
require 'open3' RSpec::Support.require_rspec_core "bisect/server" module RSpec module Core module Bisect # Provides an API to run the suite for a set of locations, using # the given bisect server to capture the results. # # Sets of specs are run by shelling out. # @private cla...
Ruby
{ "end_line": 67, "name": "run_command", "signature": "def run_command(cmd)", "start_line": 52 }
{ "class_name": "ShellRunner", "class_signature": "class ShellRunner", "module": "RSpec" }
bisect_dependency_check_failed
rspec-core/lib/rspec/core/formatters/bisect_progress_formatter.rb
def bisect_dependency_check_failed(_notification) output.puts " failure(s) do not require any non-failures to run first" if @bisect_runner == :fork output.puts output.puts "=" * 80 output.puts "NOTE: this bisect run used `config.bisect_runner = :fork`, which gene...
RSpec::Support.require_rspec_core "formatters/base_text_formatter" module RSpec module Core module Formatters # @private # Produces progress output while bisecting. class BisectProgressFormatter < BaseTextFormatter def initialize(output, bisect_runner) super(output) ...
Ruby
{ "end_line": 48, "name": "bisect_dependency_check_failed", "signature": "def bisect_dependency_check_failed(_notification)", "start_line": 36 }
{ "class_name": "BisectProgressFormatter", "class_signature": "class BisectProgressFormatter < < BaseTextFormatter", "module": "RSpec" }
console_code_for
rspec-core/lib/rspec/core/formatters/console_codes.rb
def console_code_for(code_or_symbol) if (config_method = config_colors_to_methods[code_or_symbol]) console_code_for RSpec.configuration.__send__(config_method) elsif VT100_CODE_VALUES.key?(code_or_symbol) code_or_symbol else VT100_CODES.fetch(code_or_sym...
module RSpec module Core module Formatters # ConsoleCodes provides helpers for formatting console output # with ANSI codes, e.g. color's and bold. module ConsoleCodes # @private VT100_CODES = { :black => 30, :red => 31, ...
Ruby
{ "end_line": 57, "name": "console_code_for", "signature": "def console_code_for(code_or_symbol)", "start_line": 47 }
{ "class_name": "", "class_signature": "", "module": "RSpec" }
printer
rspec-core/lib/rspec/core/formatters/deprecation_formatter.rb
def printer @printer ||= case deprecation_stream when File ImmediatePrinter.new(FileStream.new(deprecation_stream), summary_stream, self) when RaiseErrorStream Immediat...
RSpec::Support.require_rspec_core "formatters/helpers" module RSpec module Core module Formatters # @private class DeprecationFormatter Formatters.register self, :deprecation, :deprecation_summary attr_reader :count, :deprecation_stream, :summary_stream def initialize(deprec...
Ruby
{ "end_line": 30, "name": "printer", "signature": "def printer", "start_line": 20 }
{ "class_name": "DeprecationFormatter", "class_signature": "class DeprecationFormatter", "module": "RSpec" }
initialize
rspec-core/lib/rspec/core/formatters/exception_presenter.rb
def initialize(exception, example, options={}) @exception = exception @example = example @message_color = options.fetch(:message_color) { RSpec.configuration.failure_color } @description = options.fetch(:description) ...
# encoding: utf-8 RSpec::Support.require_rspec_core "formatters/console_codes" RSpec::Support.require_rspec_core "formatters/snippet_extractor" RSpec::Support.require_rspec_core 'formatters/syntax_highlighter' RSpec::Support.require_rspec_support "encoded_string" module RSpec module Core module Formatters ...
Ruby
{ "end_line": 32, "name": "initialize", "signature": "def initialize(exception, example, options={})", "start_line": 21 }
{ "class_name": "ExceptionPresenter", "class_signature": "class ExceptionPresenter", "module": "RSpec" }
formatted_cause
rspec-core/lib/rspec/core/formatters/exception_presenter.rb
def formatted_cause(exception) last_cause = final_exception(exception, [exception]) cause = [] if exception.cause cause << '------------------' cause << '--- Caused by: ---' cause << "#{exception_class_name(last_cause)}:" unless exception_cl...
# encoding: utf-8 RSpec::Support.require_rspec_core "formatters/console_codes" RSpec::Support.require_rspec_core "formatters/snippet_extractor" RSpec::Support.require_rspec_core 'formatters/syntax_highlighter' RSpec::Support.require_rspec_support "encoded_string" module RSpec module Core module Formatters ...
Ruby
{ "end_line": 74, "name": "formatted_cause", "signature": "def formatted_cause(exception)", "start_line": 50 }
{ "class_name": "ExceptionPresenter", "class_signature": "class ExceptionPresenter", "module": "RSpec" }
fully_formatted_lines
rspec-core/lib/rspec/core/formatters/exception_presenter.rb
def fully_formatted_lines(failure_number, colorizer) lines = [ encoded_description(description), detail_formatter.call(example, colorizer), formatted_message_and_backtrace(colorizer), extra_detail_formatter.call(failure_number, colorizer), ].compact.fl...
# encoding: utf-8 RSpec::Support.require_rspec_core "formatters/console_codes" RSpec::Support.require_rspec_core "formatters/snippet_extractor" RSpec::Support.require_rspec_core 'formatters/syntax_highlighter' RSpec::Support.require_rspec_support "encoded_string" module RSpec module Core module Formatters ...
Ruby
{ "end_line": 105, "name": "fully_formatted_lines", "signature": "def fully_formatted_lines(failure_number, colorizer)", "start_line": 94 }
{ "class_name": "ExceptionPresenter", "class_signature": "class ExceptionPresenter", "module": "RSpec" }
indent_lines
rspec-core/lib/rspec/core/formatters/exception_presenter.rb
def indent_lines(lines, failure_number) alignment_basis = ' ' * @indentation alignment_basis << "#{failure_number}) " if failure_number indentation = ' ' * alignment_basis.length lines.each_with_index.map do |line, index| if index == 0 "#{alignment_bas...
# encoding: utf-8 RSpec::Support.require_rspec_core "formatters/console_codes" RSpec::Support.require_rspec_core "formatters/snippet_extractor" RSpec::Support.require_rspec_core 'formatters/syntax_highlighter' RSpec::Support.require_rspec_support "encoded_string" module RSpec module Core module Formatters ...
Ruby
{ "end_line": 153, "name": "indent_lines", "signature": "def indent_lines(lines, failure_number)", "start_line": 139 }
{ "class_name": "ExceptionPresenter", "class_signature": "class ExceptionPresenter", "module": "RSpec" }
failure_lines
rspec-core/lib/rspec/core/formatters/exception_presenter.rb
def failure_lines @failure_lines ||= [].tap do |lines| lines.concat(failure_slash_error_lines) sections = [failure_slash_error_lines, exception_lines] if sections.any? { |section| section.size > 1 } && !exception_lines.first.empty? lines << '' end...
# encoding: utf-8 RSpec::Support.require_rspec_core "formatters/console_codes" RSpec::Support.require_rspec_core "formatters/snippet_extractor" RSpec::Support.require_rspec_core 'formatters/syntax_highlighter' RSpec::Support.require_rspec_support "encoded_string" module RSpec module Core module Formatters ...
Ruby
{ "end_line": 173, "name": "failure_lines", "signature": "def failure_lines", "start_line": 161 }
{ "class_name": "ExceptionPresenter", "class_signature": "class ExceptionPresenter", "module": "RSpec" }
failure_slash_error_lines
rspec-core/lib/rspec/core/formatters/exception_presenter.rb
def failure_slash_error_lines lines = read_failed_lines if lines.count == 1 lines[0] = "Failure/Error: #{lines[0].strip}" else least_indentation = SnippetExtractor.least_indentation_from(lines) lines = lines.map { |line| line.sub(/^#{least_indentation}/,...
# encoding: utf-8 RSpec::Support.require_rspec_core "formatters/console_codes" RSpec::Support.require_rspec_core "formatters/snippet_extractor" RSpec::Support.require_rspec_core 'formatters/syntax_highlighter' RSpec::Support.require_rspec_support "encoded_string" module RSpec module Core module Formatters ...
Ruby
{ "end_line": 185, "name": "failure_slash_error_lines", "signature": "def failure_slash_error_lines", "start_line": 175 }
{ "class_name": "ExceptionPresenter", "class_signature": "class ExceptionPresenter", "module": "RSpec" }
exception_lines
rspec-core/lib/rspec/core/formatters/exception_presenter.rb
def exception_lines @exception_lines ||= begin lines = [] lines << "#{exception_class_name}:" unless exception_class_name =~ /RSpec/ encoded_string(exception_message_string(exception)).split("\n").each do |line| lines << (line.empty? ? line : " #{line}") ...
# encoding: utf-8 RSpec::Support.require_rspec_core "formatters/console_codes" RSpec::Support.require_rspec_core "formatters/snippet_extractor" RSpec::Support.require_rspec_core 'formatters/syntax_highlighter' RSpec::Support.require_rspec_support "encoded_string" module RSpec module Core module Formatters ...
Ruby
{ "end_line": 218, "name": "exception_lines", "signature": "def exception_lines", "start_line": 209 }
{ "class_name": "ExceptionPresenter", "class_signature": "class ExceptionPresenter", "module": "RSpec" }
extra_failure_lines
rspec-core/lib/rspec/core/formatters/exception_presenter.rb
def extra_failure_lines @extra_failure_lines ||= begin lines = Array(example.metadata[:extra_failure_lines]) unless lines.empty? lines.unshift('') unless lines.first == '' lines.push('') unless lines.last == '' end lines end...
# encoding: utf-8 RSpec::Support.require_rspec_core "formatters/console_codes" RSpec::Support.require_rspec_core "formatters/snippet_extractor" RSpec::Support.require_rspec_core 'formatters/syntax_highlighter' RSpec::Support.require_rspec_support "encoded_string" module RSpec module Core module Formatters ...
Ruby
{ "end_line": 229, "name": "extra_failure_lines", "signature": "def extra_failure_lines", "start_line": 220 }
{ "class_name": "ExceptionPresenter", "class_signature": "class ExceptionPresenter", "module": "RSpec" }
read_failed_lines
rspec-core/lib/rspec/core/formatters/exception_presenter.rb
def read_failed_lines matching_line = find_failed_line unless matching_line return ["Unable to find matching line from backtrace"] end file_and_line_number = matching_line.match(/(.+?):(\d+)(|:\d+)/) unless file_and_line_number return ["Unable ...
# encoding: utf-8 RSpec::Support.require_rspec_core "formatters/console_codes" RSpec::Support.require_rspec_core "formatters/snippet_extractor" RSpec::Support.require_rspec_core 'formatters/syntax_highlighter' RSpec::Support.require_rspec_support "encoded_string" module RSpec module Core module Formatters ...
Ruby
{ "end_line": 265, "name": "read_failed_lines", "signature": "def read_failed_lines", "start_line": 241 }
{ "class_name": "ExceptionPresenter", "class_signature": "class ExceptionPresenter", "module": "RSpec" }
find_failed_line
rspec-core/lib/rspec/core/formatters/exception_presenter.rb
def find_failed_line line_regex = RSpec.configuration.in_project_source_dir_regex loaded_spec_files = RSpec.configuration.loaded_spec_files exception_backtrace.reject! do |line| line.start_with?("<internal:") end exception_backtrace.find do |line| ...
# encoding: utf-8 RSpec::Support.require_rspec_core "formatters/console_codes" RSpec::Support.require_rspec_core "formatters/snippet_extractor" RSpec::Support.require_rspec_core 'formatters/syntax_highlighter' RSpec::Support.require_rspec_support "encoded_string" module RSpec module Core module Formatters ...
Ruby
{ "end_line": 280, "name": "find_failed_line", "signature": "def find_failed_line", "start_line": 267 }
{ "class_name": "ExceptionPresenter", "class_signature": "class ExceptionPresenter", "module": "RSpec" }
pending_options
rspec-core/lib/rspec/core/formatters/exception_presenter.rb
def pending_options if @execution_result.pending_fixed? { :description => "#{@example.full_description} FIXED", :message_color => RSpec.configuration.fixed_color, :failure_lines => [ "Expected pending '#{@execution_result.pend...
# encoding: utf-8 RSpec::Support.require_rspec_core "formatters/console_codes" RSpec::Support.require_rspec_core "formatters/snippet_extractor" RSpec::Support.require_rspec_core 'formatters/syntax_highlighter' RSpec::Support.require_rspec_support "encoded_string" module RSpec module Core module Formatters ...
Ruby
{ "end_line": 352, "name": "pending_options", "signature": "def pending_options", "start_line": 333 }
{ "class_name": "ExceptionPresenter", "class_signature": "class ExceptionPresenter", "module": "RSpec" }
with_multiple_error_options_as_needed
rspec-core/lib/rspec/core/formatters/exception_presenter.rb
def with_multiple_error_options_as_needed(exception, options) return options unless multiple_exceptions_error?(exception) options = options.merge( :failure_lines => [], :extra_detail_formatter => sub_failure_list_formatter(exception, options[:message_color])...
# encoding: utf-8 RSpec::Support.require_rspec_core "formatters/console_codes" RSpec::Support.require_rspec_core "formatters/snippet_extractor" RSpec::Support.require_rspec_core 'formatters/syntax_highlighter' RSpec::Support.require_rspec_support "encoded_string" module RSpec module Core module Formatters ...
Ruby
{ "end_line": 368, "name": "with_multiple_error_options_as_needed", "signature": "def with_multiple_error_options_as_needed(exception, options)", "start_line": 354 }
{ "class_name": "ExceptionPresenter", "class_signature": "class ExceptionPresenter", "module": "RSpec" }
multiple_exception_summarizer
rspec-core/lib/rspec/core/formatters/exception_presenter.rb
def multiple_exception_summarizer(exception, prior_detail_formatter, color) lambda do |example, colorizer| summary = if exception.aggregation_metadata[:hide_backtrace] # Since the backtrace is hidden, the subfailures will come # immediately a...
# encoding: utf-8 RSpec::Support.require_rspec_core "formatters/console_codes" RSpec::Support.require_rspec_core "formatters/snippet_extractor" RSpec::Support.require_rspec_core 'formatters/syntax_highlighter' RSpec::Support.require_rspec_support "encoded_string" module RSpec module Core module Formatters ...
Ruby
{ "end_line": 393, "name": "multiple_exception_summarizer", "signature": "def multiple_exception_summarizer(exception, prior_detail_formatter, color)", "start_line": 374 }
{ "class_name": "ExceptionPresenter", "class_signature": "class ExceptionPresenter", "module": "RSpec" }
sub_failure_list_formatter
rspec-core/lib/rspec/core/formatters/exception_presenter.rb
def sub_failure_list_formatter(exception, message_color) common_backtrace_truncater = CommonBacktraceTruncater.new(exception) lambda do |failure_number, colorizer| FlatMap.flat_map(exception.all_exceptions.each_with_index) do |failure, index| options = with_multipl...
# encoding: utf-8 RSpec::Support.require_rspec_core "formatters/console_codes" RSpec::Support.require_rspec_core "formatters/snippet_extractor" RSpec::Support.require_rspec_core 'formatters/syntax_highlighter' RSpec::Support.require_rspec_support "encoded_string" module RSpec module Core module Formatters ...
Ruby
{ "end_line": 416, "name": "sub_failure_list_formatter", "signature": "def sub_failure_list_formatter(exception, message_color)", "start_line": 395 }
{ "class_name": "ExceptionPresenter", "class_signature": "class ExceptionPresenter", "module": "RSpec" }
with_truncated_backtrace
rspec-core/lib/rspec/core/formatters/exception_presenter.rb
def with_truncated_backtrace(child) child_bt = child.backtrace parent_bt = @parent.backtrace return child if child_bt.nil? || child_bt.empty? || parent_bt.nil? index_before_first_common_frame = -1.downto(-child_bt.size).find do |index| parent_bt[...
# encoding: utf-8 RSpec::Support.require_rspec_core "formatters/console_codes" RSpec::Support.require_rspec_core "formatters/snippet_extractor" RSpec::Support.require_rspec_core 'formatters/syntax_highlighter' RSpec::Support.require_rspec_support "encoded_string" module RSpec module Core module Formatters ...
Ruby
{ "end_line": 448, "name": "with_truncated_backtrace", "signature": "def with_truncated_backtrace(child)", "start_line": 433 }
{ "class_name": "ExceptionPresenter", "class_signature": "class ExceptionPresenter", "module": "RSpec" }
add
rspec-core/lib/rspec/core/formatters/exception_presenter.rb
def add(exception) # `PendingExampleFixedError` can be assigned to an example that initially has no # failures, but when the `aggregate_failures` around hook completes, it notifies of # a failure. If we do not ignore `PendingExampleFixedError` it would be surfaced to # the user a...
# encoding: utf-8 RSpec::Support.require_rspec_core "formatters/console_codes" RSpec::Support.require_rspec_core "formatters/snippet_extractor" RSpec::Support.require_rspec_core 'formatters/syntax_highlighter' RSpec::Support.require_rspec_support "encoded_string" module RSpec module Core module Formatters ...
Ruby
{ "end_line": 493, "name": "add", "signature": "def add(exception)", "start_line": 473 }
{ "class_name": "MultipleExceptionError", "class_signature": "class MultipleExceptionError < < StandardError", "module": "RSpec" }
format_duration
rspec-core/lib/rspec/core/formatters/helpers.rb
def self.format_duration(duration) precision = case when duration < 1 then SUB_SECOND_PRECISION when duration < 120 then DEFAULT_PRECISION when duration < 300 then 1 else 0 end ...
RSpec::Support.require_rspec_core "shell_escape" module RSpec module Core module Formatters # Formatters helpers. module Helpers # @private SUB_SECOND_PRECISION = 5 # @private DEFAULT_PRECISION = 2 # @api private # # Formats seconds into a hum...
Ruby
{ "end_line": 40, "name": "format_duration", "signature": "def self.format_duration(duration)", "start_line": 24 }
{ "class_name": "", "class_signature": "", "module": "RSpec" }
pluralize
rspec-core/lib/rspec/core/formatters/helpers.rb
def self.pluralize(count, string) pluralized_string = if count.to_f == 1 string elsif string.end_with?('s') # e.g. "process" "#{string}es" # e.g. "processes" else ...
RSpec::Support.require_rspec_core "shell_escape" module RSpec module Core module Formatters # Formatters helpers. module Helpers # @private SUB_SECOND_PRECISION = 5 # @private DEFAULT_PRECISION = 2 # @api private # # Formats seconds into a hum...
Ruby
{ "end_line": 98, "name": "pluralize", "signature": "def self.pluralize(count, string)", "start_line": 88 }
{ "class_name": "", "class_signature": "", "module": "RSpec" }
organize_ids
rspec-core/lib/rspec/core/formatters/helpers.rb
def self.organize_ids(ids) grouped = ids.inject(Hash.new { |h, k| h[k] = [] }) do |hash, id| file, id = Example.parse_id(id) hash[file] << id hash end grouped.sort_by(&:first).map do |file, grouped_ids| grouped_ids = grouped_ids.sort_by { |i...
RSpec::Support.require_rspec_core "shell_escape" module RSpec module Core module Formatters # Formatters helpers. module Helpers # @private SUB_SECOND_PRECISION = 5 # @private DEFAULT_PRECISION = 2 # @api private # # Formats seconds into a hum...
Ruby
{ "end_line": 114, "name": "organize_ids", "signature": "def self.organize_ids(ids)", "start_line": 102 }
{ "class_name": "", "class_signature": "", "module": "RSpec" }
print_summary
rspec-core/lib/rspec/core/formatters/html_printer.rb
def print_summary(duration, example_count, failure_count, pending_count) totals = String.new( "#{example_count} example#{'s' unless example_count == 1}, " ) totals << "#{failure_count} failure#{'s' unless failure_count == 1}" totals << ", #{pending_count} pending" if ...
require 'erb' module RSpec module Core module Formatters # @private class HtmlPrinter include ERB::Util # For the #h method. def initialize(output) @output = output end def print_html_start @output.puts HTML_HEADER @output.puts REPORT_HEA...
Ruby
{ "end_line": 77, "name": "print_summary", "signature": "def print_summary(duration, example_count, failure_count, pending_count)", "start_line": 59 }
{ "class_name": "HtmlPrinter", "class_signature": "class HtmlPrinter", "module": "RSpec" }
lines_around
rspec-core/lib/rspec/core/formatters/html_snippet_extractor.rb
def lines_around(file, line) if File.file?(file) lines = File.read(file).split("\n") min = [0, line - 3].max max = [line + 1, lines.length - 1].min selected_lines = [] selected_lines.join("\n") lines[min..max].join("\n") else ...
module RSpec module Core module Formatters # @api private # # Extracts code snippets by looking at the backtrace of the passed error # and applies synax highlighting and line numbers using html. class HtmlSnippetExtractor # @private module NullConverter def ...
Ruby
{ "end_line": 99, "name": "lines_around", "signature": "def lines_around(file, line)", "start_line": 84 }
{ "class_name": "HtmlSnippetExtractor", "class_signature": "class HtmlSnippetExtractor", "module": "RSpec" }
dump_summary
rspec-core/lib/rspec/core/formatters/json_formatter.rb
def dump_summary(summary) @output_hash[:summary] = { :duration => summary.duration, :example_count => summary.example_count, :failure_count => summary.failure_count, :pending_count => summary.pending_count, :errors_outside_of_examples_count => summar...
RSpec::Support.require_rspec_core "formatters/base_formatter" require 'json' module RSpec module Core module Formatters # @private class JsonFormatter < BaseFormatter Formatters.register self, :message, :dump_summary, :dump_profile, :stop, :seed, :close attr_reader :output_hash ...
Ruby
{ "end_line": 33, "name": "dump_summary", "signature": "def dump_summary(summary)", "start_line": 24 }
{ "class_name": "JsonFormatter", "class_signature": "class JsonFormatter < < BaseFormatter", "module": "RSpec" }
stop
rspec-core/lib/rspec/core/formatters/json_formatter.rb
def stop(group_notification) @output_hash[:examples] = group_notification.notifications.map do |notification| format_example(notification.example).tap do |hash| e = notification.example.exception if e hash[:exception] = { :class => e.c...
RSpec::Support.require_rspec_core "formatters/base_formatter" require 'json' module RSpec module Core module Formatters # @private class JsonFormatter < BaseFormatter Formatters.register self, :message, :dump_summary, :dump_profile, :stop, :seed, :close attr_reader :output_hash ...
Ruby
{ "end_line": 49, "name": "stop", "signature": "def stop(group_notification)", "start_line": 35 }
{ "class_name": "JsonFormatter", "class_signature": "class JsonFormatter < < BaseFormatter", "module": "RSpec" }
line_range_of_expression
rspec-core/lib/rspec/core/formatters/snippet_extractor.rb
def line_range_of_expression @line_range_of_expression ||= begin line_range = line_range_of_location_nodes_in_expression initial_unclosed_tokens = unclosed_tokens_in_line_range(line_range) unclosed_tokens = initial_unclosed_tokens until (initial_unclo...
module RSpec module Core module Formatters # @private class SnippetExtractor NoSuchFileError = Class.new(StandardError) NoSuchLineError = Class.new(StandardError) def self.extract_line_at(file_path, line_number) source = source_from_file(file_path) line = s...
Ruby
{ "end_line": 68, "name": "line_range_of_expression", "signature": "def line_range_of_expression", "start_line": 55 }
{ "class_name": "SnippetExtractor", "class_signature": "class SnippetExtractor", "module": "RSpec" }
unclosed_tokens_in_line_range
rspec-core/lib/rspec/core/formatters/snippet_extractor.rb
def unclosed_tokens_in_line_range(line_range) tokens = FlatMap.flat_map(line_range) do |line_number| source.tokens_by_line_number[line_number] end tokens.each_with_object([]) do |token, unclosed_tokens| if token.opening? unclosed_tokens <<...
module RSpec module Core module Formatters # @private class SnippetExtractor NoSuchFileError = Class.new(StandardError) NoSuchLineError = Class.new(StandardError) def self.extract_line_at(file_path, line_number) source = source_from_file(file_path) line = s...
Ruby
{ "end_line": 85, "name": "unclosed_tokens_in_line_range", "signature": "def unclosed_tokens_in_line_range(line_range)", "start_line": 70 }
{ "class_name": "SnippetExtractor", "class_signature": "class SnippetExtractor", "module": "RSpec" }
highlight_syntax
rspec-core/lib/rspec/core/formatters/syntax_highlighter.rb
def self.highlight_syntax(lines) highlighted = begin CodeRay.encode(lines.join("\n"), :ruby, :terminal) rescue Support::AllExceptionsExceptOnesWeMustNotRescue return lines end highlighted.split("\n").map do |line| line.sub(/\S/) ...
module RSpec module Core module Formatters # @private # Provides terminal syntax highlighting of code snippets # when coderay is available. class SyntaxHighlighter def initialize(configuration) @configuration = configuration end def highlight(lines) ...
Ruby
{ "end_line": 74, "name": "highlight_syntax", "signature": "def self.highlight_syntax(lines)", "start_line": 64 }
{ "class_name": "SyntaxHighlighter", "class_signature": "class SyntaxHighlighter", "module": "RSpec" }