Sha256: 25ed3aeb56b85fd035357d2093f73e764f9dc4f65090815289ad17f4704c4573

Contents?: true

Size: 1.33 KB

Versions: 8

Compression:

Stored size: 1.33 KB

Contents

module RSpec
  module Core
    # Exposes {ExampleGroup}-level methods to a module, so you can include that
    # module in an {ExampleGroup}.
    #
    # @example
    #
    #     module LoggedInAsAdmin
    #       extend RSpec::Core::SharedContext
    #       before(:each) do
    #         log_in_as :admin
    #       end
    #     end
    #
    #     describe "admin section" do
    #       include LoggedInAsAdmin
    #       # ...
    #     end
    module SharedContext
      # @api private
      def included(group)
        __shared_context_recordings.each do |recording|
          recording.playback_onto(group)
        end
      end

      # @api private
      def __shared_context_recordings
        @__shared_context_recordings ||= []
      end

      Recording = Struct.new(:method_name, :args, :block) do
        def playback_onto(group)
          group.__send__(method_name, *args, &block)
        end
      end

      # @api private
      def self.record(methods)
        methods.each do |meth|
          define_method(meth) do |*args, &block|
            __shared_context_recordings << Recording.new(meth, args, block)
          end
        end
      end

      record [:describe, :context] + Hooks.instance_methods(false) +
        MemoizedHelpers::ClassMethods.instance_methods(false)
    end
  end

  SharedContext = Core::SharedContext
end

Version data entries

8 entries across 8 versions & 3 rubygems

Version Path
opal-rspec-cj-0.4.4 vendor_lib/rspec/core/shared_context.rb
opal-rspec-0.4.3 vendor_lib/rspec/core/shared_context.rb
opal-rspec-0.4.2 vendor_lib/rspec/core/shared_context.rb
opal-rspec-0.4.1 vendor_lib/rspec/core/shared_context.rb
opal-rspec-0.4.0 vendor_lib/rspec/core/shared_context.rb
opal-rspec-0.4.0.beta4 vendor_lib/rspec/core/shared_context.rb
rspec-core-3.0.0.beta2 lib/rspec/core/shared_context.rb
rspec-core-3.0.0.beta1 lib/rspec/core/shared_context.rb