Sha256: 9ee56f5373d877efe2a76986ef2b4156be65a50b4646dd4a9c7f8fcd0a142e84

Contents?: true

Size: 1.33 KB

Versions: 5

Compression:

Stored size: 1.33 KB

Contents

# frozen_string_literal: true

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

module RSpec
  module Clone
    module ExpectationHelper
      # {RSpec::Clone::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:0x00007fb6b823 @actual="foo">
        #   expect { Boom } # => #<RSpec::ExpectationTarget::Block:0x00007fb6b826 @callable=#<Proc:0x00007fb6b826>>
        #
        # @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
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
r_spec-clone-1.2.1 lib/r_spec/clone/expectation_helper/it.rb
r_spec-clone-1.2.0 lib/r_spec/clone/expectation_helper/it.rb
r_spec-clone-1.1.0 lib/r_spec/clone/expectation_helper/it.rb
r_spec-clone-1.0.2 lib/r_spec/clone/expectation_helper/it.rb
r_spec-clone-1.0.0.rc1 lib/r_spec/clone/expectation_helper/it.rb