module RSpec::Maybes::Syntax

@api private Provides methods for enabling and disabling the maybe syntax

Constants

MONKEYPATCHED_CLASSES

Public Instance Methods

disable_maybe(syntax_host = ::RSpec::Matchers) click to toggle source

@api private Disables the `maybe` syntax.

# File lib/rspec/maybes/syntax.rb, line 48
def disable_maybe(syntax_host = ::RSpec::Matchers)
  return unless maybe_enabled?(syntax_host)

  syntax_host.module_exec do
    undef maybe
  end

  MONKEYPATCHED_CLASSES.each do |klass|
    klass.class_eval do
      undef matches?
      alias matches? old_matches?
      undef old_matches?

      undef on_my_machine
      undef on_your_machine?
    end
  end
end
enable_maybe(syntax_host = ::RSpec::Matchers) click to toggle source

@api private Enables the `maybe` syntax.

# File lib/rspec/maybes/syntax.rb, line 18
def enable_maybe(syntax_host = ::RSpec::Matchers)
  return if maybe_enabled?(syntax_host)

  syntax_host.module_exec do
    def maybe(value = ::RSpec::Maybes::MaybeTarget::UndefinedValue, &block)
      ::RSpec::Maybes::MaybeTarget.for(value, block)
    end
  end

  MONKEYPATCHED_CLASSES.each do |klass|
    klass.class_eval do
      alias old_matches? matches?

      def matches?(actual)
        @actual = actual
        @your_machine || old_matches?(actual)
      end

      def on_my_machine
        @your_machine = true
        return self
      end

      def on_your_machine?() @your_machine end
    end
  end
end
matches?(actual) click to toggle source
# File lib/rspec/maybes/syntax.rb, line 31
def matches?(actual)
  @actual = actual
  @your_machine || old_matches?(actual)
end
maybe(value = ::RSpec::Maybes::MaybeTarget::UndefinedValue, &block) click to toggle source
# File lib/rspec/maybes/syntax.rb, line 22
def maybe(value = ::RSpec::Maybes::MaybeTarget::UndefinedValue, &block)
  ::RSpec::Maybes::MaybeTarget.for(value, block)
end
maybe_enabled?(syntax_host = ::RSpec::Matchers) click to toggle source

@api private Indicates whether or not the `maybe` syntax is enabled.

# File lib/rspec/maybes/syntax.rb, line 69
def maybe_enabled?(syntax_host = ::RSpec::Matchers)
  syntax_host.method_defined?(:maybe)
end
on_my_machine() click to toggle source
# File lib/rspec/maybes/syntax.rb, line 36
def on_my_machine
  @your_machine = true
  return self
end
on_your_machine?() click to toggle source
# File lib/rspec/maybes/syntax.rb, line 41
def on_your_machine?() @your_machine end