Class/Module Index [+]

Quicksearch

RSpec::Expectations::Syntax

@api private Provides methods for enabling and disabling the available syntaxes provided by rspec-expectations.

Public Instance Methods

default_should_host() click to toggle source

@api private Determines where we add `should` and `should_not`.

# File lib/rspec/expectations/syntax.rb, line 42
def default_should_host
  @default_should_host ||= ::Object.ancestors.last
end
disable_expect(syntax_host = ::RSpec::Matchers) click to toggle source

@api private Disables the `expect` syntax.

# File lib/rspec/expectations/syntax.rb, line 89
def disable_expect(syntax_host = ::RSpec::Matchers)
  return unless expect_enabled?(syntax_host)

  syntax_host.module_eval do
    undef expect
  end
end
disable_should(syntax_host = default_should_host) click to toggle source

@api private Disables the `should` syntax.

# File lib/rspec/expectations/syntax.rb, line 64
def disable_should(syntax_host = default_should_host)
  return unless should_enabled?(syntax_host)

  syntax_host.module_eval do
    undef should
    undef should_not
  end
end
enable_expect(syntax_host = ::RSpec::Matchers) click to toggle source

@api private Enables the `expect` syntax.

# File lib/rspec/expectations/syntax.rb, line 75
def enable_expect(syntax_host = ::RSpec::Matchers)
  return if expect_enabled?(syntax_host)

  syntax_host.module_eval do
    def expect(*target, &target_block)
      target << target_block if block_given?
      raise ArgumentError.new("You must pass an argument or a block to #expect but not both.") unless target.size == 1
      ::RSpec::Expectations::ExpectationTarget.new(target.first)
    end
  end
end
enable_should(syntax_host = default_should_host) click to toggle source

@api private Enables the `should` syntax.

# File lib/rspec/expectations/syntax.rb, line 48
def enable_should(syntax_host = default_should_host)
  return if should_enabled?(syntax_host)

  syntax_host.module_eval do
    def should(matcher=nil, message=nil, &block)
      ::RSpec::Expectations::PositiveExpectationHandler.handle_matcher(self, matcher, message, &block)
    end

    def should_not(matcher=nil, message=nil, &block)
      ::RSpec::Expectations::NegativeExpectationHandler.handle_matcher(self, matcher, message, &block)
    end
  end
end
expect(*target, &target_block) click to toggle source
# File lib/rspec/expectations/syntax.rb, line 79
def expect(*target, &target_block)
  target << target_block if block_given?
  raise ArgumentError.new("You must pass an argument or a block to #expect but not both.") unless target.size == 1
  ::RSpec::Expectations::ExpectationTarget.new(target.first)
end
expect_enabled?(syntax_host = ::RSpec::Matchers) click to toggle source

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

# File lib/rspec/expectations/syntax.rb, line 105
def expect_enabled?(syntax_host = ::RSpec::Matchers)
  syntax_host.method_defined?(:expect)
end
should(matcher=nil, message=nil, &block) click to toggle source
# File lib/rspec/expectations/syntax.rb, line 52
def should(matcher=nil, message=nil, &block)
  ::RSpec::Expectations::PositiveExpectationHandler.handle_matcher(self, matcher, message, &block)
end
should_enabled?(syntax_host = default_should_host) click to toggle source

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

# File lib/rspec/expectations/syntax.rb, line 99
def should_enabled?(syntax_host = default_should_host)
  syntax_host.method_defined?(:should)
end
should_not(matcher=nil, message=nil, &block) click to toggle source
# File lib/rspec/expectations/syntax.rb, line 56
def should_not(matcher=nil, message=nil, &block)
  ::RSpec::Expectations::NegativeExpectationHandler.handle_matcher(self, matcher, message, &block)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.