Module: RSpec::Support
- Defined in:
- lib/rspec/support.rb,
lib/rspec/support/os.rb,
lib/rspec/support/spec.rb,
lib/rspec/support/differ.rb,
lib/rspec/support/version.rb,
lib/rspec/support/warnings.rb,
lib/rspec/support/fuzzy_matcher.rb,
lib/rspec/support/ruby_features.rb,
lib/rspec/support/encoded_string.rb,
lib/rspec/support/hunk_generator.rb,
lib/rspec/support/spec/shell_out.rb,
lib/rspec/support/directory_maker.rb,
lib/rspec/support/version_checker.rb,
lib/rspec/support/matcher_definition.rb,
lib/rspec/support/spec/in_sub_process.rb,
lib/rspec/support/spec/stderr_splitter.rb,
lib/rspec/support/recursive_const_methods.rb,
lib/rspec/support/spec/formatting_support.rb,
lib/rspec/support/method_signature_verifier.rb,
lib/rspec/support/spec/with_isolated_stderr.rb,
lib/rspec/support/spec/prevent_load_time_warnings.rb
Defined Under Namespace
Modules: FormattingSupport, FuzzyMatcher, InSubProcess, OS, RecursiveConstMethods, Ruby, RubyFeatures, ShellOut, Spec, Version, Warnings, WarningsPrevention, WithIsolatedStdErr Classes: BlockSignature, Differ, DirectoryMaker, EncodedString, HunkGenerator, LooseSignatureVerifier, MethodSignature, MethodSignatureVerifier, StdErrSplitter, VersionChecker
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)
- LibraryVersionTooLowError =
Class.new(StandardError)
- StrictSignatureVerifier =
Figures out wether a given method can accept various arguments. Surprisingly non-trivial.
MethodSignatureVerifier
Class Method Summary collapse
-
.define_optimized_require_for_rspec(lib, &require_relative) ⇒ Object
private
Defines a helper method that is optimized to require files from the named lib.
-
.deregister_matcher_definition(&block) ⇒ Object
Remove a previously registered matcher.
- .is_a_matcher?(object) ⇒ Boolean
- .matcher_definitions ⇒ Object
- .method_handle_for(object, method_name) ⇒ Object
-
.register_matcher_definition(&block) ⇒ Object
Used internally to break cyclic dependency between mocks, expectations, and support.
Class Method Details
.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 |
# File 'lib/rspec/support.rb', line 14 def self.define_optimized_require_for_rspec(lib, &require_relative) name = "require_rspec_#{lib}" if 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/rspec/support/matcher_definition.rb', line 22 def self.deregister_matcher_definition(&block) matcher_definitions.delete(block) end |
.is_a_matcher?(object) ⇒ Boolean
27 28 29 |
# File 'lib/rspec/support/matcher_definition.rb', line 27 def self.is_a_matcher?(object) matcher_definitions.any? { |md| md.call(object) } end |
.matcher_definitions ⇒ Object
4 5 6 |
# File 'lib/rspec/support/matcher_definition.rb', line 4 def self.matcher_definitions @matcher_definitions ||= [] end |
.method_handle_for(object, method_name) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rspec/support.rb', line 47 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 Exception raise original end 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/rspec/support/matcher_definition.rb', line 14 def self.register_matcher_definition(&block) matcher_definitions << block end |