Sha256: 4d9af29401fa396c92ee95d165a3bc9cf430fde9c841e440b899f990ae3baba8

Contents?: true

Size: 1.26 KB

Versions: 7

Compression:

Stored size: 1.26 KB

Contents

# frozen_string_literal: true

require_relative "shared"
require_relative File.join("..", "expectation_target")

module RSpec
  module ExpectationHelper
    # {RSpec::Dsl.it}'s expectation helper module.
    module It
      include Shared

      # Create an expectation for a spec.
      #
      # @param value [#object_id, nil]  An actual value.
      # @param block [#call, nil]       A code to evaluate.
      #
      # @return [Block, Value] The wrapped target of an expectation.
      #
      # @example
      #   expect("foo") # => #<RSpec::ExpectationTarget::Value:0x00007fb6b82311a0 @actual="foo">
      #   expect { Boom } # => #<RSpec::ExpectationTarget::Block:0x00007fb6b8263df8 @callable=#<Proc:0x00007fb6b8263e20>>
      #
      # @api public
      def expect(value = self.class.superclass, &block)
        ExpectationTarget.call(self.class.superclass, value, block)
      end

      # Wraps the target of an expectation with the subject as actual value.
      #
      # @return [Block] The wrapped target of an expectation.
      #
      # @example
      #   is_expected # => #<RSpec::ExpectationTarget::Block:0x00007fb6b8263df8 @callable=#<Proc:0x00007fb6b8263e20>>
      #
      # @api public
      def is_expected
        expect { subject }
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
r_spec-1.0.1 lib/r_spec/expectation_helper/it.rb
r_spec-1.0.0 lib/r_spec/expectation_helper/it.rb
r_spec-1.0.0.beta11 lib/r_spec/expectation_helper/it.rb
r_spec-1.0.0.beta10 lib/r_spec/expectation_helper/it.rb
r_spec-1.0.0.beta9 lib/r_spec/expectation_helper/it.rb
r_spec-1.0.0.beta8 lib/r_spec/expectation_helper/it.rb
r_spec-1.0.0.beta7 lib/r_spec/expectation_helper/it.rb