Module: RSpec::Support

Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/spec.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/mutex.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/differ.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/source.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/version.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/warnings.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/source/node.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/source/token.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/fuzzy_matcher.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/ruby_features.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/encoded_string.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/hunk_generator.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/spec/shell_out.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/directory_maker.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/reentrant_mutex.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/source/location.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/object_formatter.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/spec/diff_helpers.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/comparable_version.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/matcher_definition.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/spec/in_sub_process.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/spec/stderr_splitter.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/recursive_const_methods.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/spec/formatting_support.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/spec/library_wide_checks.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/method_signature_verifier.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/spec/with_isolated_stderr.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/with_keywords_when_needed.rb

Defined Under Namespace

Modules: AllExceptionsExceptOnesWeMustNotRescue, FormattingSupport, FuzzyMatcher, InSubProcess, OS, RecursiveConstMethods, Ruby, RubyFeatures, ShellOut, Spec, Version, Warnings, WhitespaceChecks, WithIsolatedStdErr, WithKeywordsWhenNeeded Classes: BlockSignature, ComparableVersion, Differ, DirectoryMaker, EncodedString, HunkGenerator, LooseSignatureVerifier, MethodSignature, MethodSignatureExpectation, MethodSignatureVerifier, Mutex, ObjectFormatter, ReentrantMutex, Source, StdErrSplitter

Constant Summary collapse

KERNEL_METHOD_METHOD =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

::Kernel.instance_method(:method)
DEFAULT_FAILURE_NOTIFIER =
lambda { |failure, _opts| raise failure }
DEFAULT_WARNING_NOTIFIER =
lambda { |warning| ::Kernel.warn warning }
StrictSignatureVerifier =

Figures out wether a given method can accept various arguments. Surprisingly non-trivial.

MethodSignatureVerifier

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.warning_notifierObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



132
133
134
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support.rb', line 132

def self.warning_notifier
  @warning_notifier ||= DEFAULT_WARNING_NOTIFIER
end

Class Method Details

.class_of(object) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Used internally to get a class of a given object, even if it does not respond to #class.



84
85
86
87
88
89
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support.rb', line 84

def self.class_of(object)
  object.class
rescue NoMethodError
  singleton_class = class << object; self; end
  singleton_class.ancestors.find { |ancestor| !ancestor.equal?(singleton_class) }
end

.define_optimized_require_for_rspec(lib, &require_relative) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Defines a helper method that is optimized to require files from the named lib. The passed block MUST be ‘{ |f| require_relative f }` because for `require_relative` to work properly from within the named lib the line of code must be IN that lib.

‘require_relative` is preferred when available because it is always O(1), regardless of the number of dirs in $LOAD_PATH. `require`, on the other hand, does a linear O(N) search over the dirs in the $LOAD_PATH until it can resolve the file relative to one of the dirs.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support.rb', line 14

def self.define_optimized_require_for_rspec(lib, &require_relative)
  name = "require_rspec_#{lib}"

  if RUBY_PLATFORM == 'java' && !Kernel.respond_to?(:require)
    # JRuby 9.1.17.0 has developed a regression for require
    (class << self; self; end).__send__(:define_method, name) do |f|
      Kernel.send(:require, "rspec/#{lib}/#{f}")
    end
  elsif Kernel.respond_to?(:require_relative)
    (class << self; self; end).__send__(:define_method, name) do |f|
      require_relative.call("#{lib}/#{f}")
    end
  else
    (class << self; self; end).__send__(:define_method, name) do |f|
      require "rspec/#{lib}/#{f}"
    end
  end
end

.deregister_matcher_definition(&block) ⇒ Object

Remove a previously registered matcher. Useful for cleaning up after yourself in specs.



22
23
24
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/matcher_definition.rb', line 22

def self.deregister_matcher_definition(&block)
  matcher_definitions.delete(block)
end

.failure_notifierObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



105
106
107
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support.rb', line 105

def self.failure_notifier
  thread_local_data[:failure_notifier] || DEFAULT_FAILURE_NOTIFIER
end

.failure_notifier=(callable) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



97
98
99
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support.rb', line 97

def self.failure_notifier=(callable)
  thread_local_data[:failure_notifier] = callable
end

.is_a_matcher?(object) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/matcher_definition.rb', line 27

def self.is_a_matcher?(object)
  matcher_definitions.any? { |md| md.call(object) }
end

.matcher_definitionsObject



4
5
6
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/matcher_definition.rb', line 4

def self.matcher_definitions
  @matcher_definitions ||= []
end

.method_handle_for(object, method_name) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support.rb', line 52

def self.method_handle_for(object, method_name)
  KERNEL_METHOD_METHOD.bind(object).call(method_name)
rescue NameError => original
  begin
    handle = object.method(method_name)
    raise original unless handle.is_a? Method
    handle
  rescue Support::AllExceptionsExceptOnesWeMustNotRescue
    raise original
  end
end

.notify_failure(failure, options = {}) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



110
111
112
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support.rb', line 110

def self.notify_failure(failure, options={})
  failure_notifier.call(failure, options)
end

.register_matcher_definition(&block) ⇒ Object

Used internally to break cyclic dependency between mocks, expectations, and support. We don’t currently have a consistent implementation of our matchers, though we are considering changing that: github.com/rspec/rspec-mocks/issues/513



14
15
16
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/matcher_definition.rb', line 14

def self.register_matcher_definition(&block)
  matcher_definitions << block
end

.rspec_description_for_object(object) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

gives a string representation of an object for use in RSpec descriptions



34
35
36
37
38
39
40
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/matcher_definition.rb', line 34

def self.rspec_description_for_object(object)
  if RSpec::Support.is_a_matcher?(object) && object.respond_to?(:description)
    object.description
  else
    object
  end
end

.thread_local_dataObject

A single thread local variable so we don’t excessively pollute that namespace.



92
93
94
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support.rb', line 92

def self.thread_local_data
  Thread.current[:__rspec] ||= {}
end

.with_failure_notifier(callable) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



115
116
117
118
119
120
121
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support.rb', line 115

def self.with_failure_notifier(callable)
  orig_notifier = failure_notifier
  self.failure_notifier = callable
  yield
ensure
  self.failure_notifier = orig_notifier
end