Sha256: c958df36990203b7a8f78be3256814389eba4232794e6d21095a2d0e57297592

Contents?: true

Size: 1.36 KB

Versions: 7438

Compression:

Stored size: 1.36 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(:example) do
    #         log_in_as :admin
    #       end
    #     end
    #
    #     describe "admin section" do
    #       include LoggedInAsAdmin
    #       # ...
    #     end
    module SharedContext
      # @private
      def included(group)
        __shared_context_recordings.each do |recording|
          recording.playback_onto(group)
        end
      end

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

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

      # @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

      # @private
      record [:describe, :context] + Hooks.instance_methods(false) +
        MemoizedHelpers::ClassMethods.instance_methods(false)
    end
  end
  # @private
  SharedContext = Core::SharedContext
end

Version data entries

7,438 entries across 7,351 versions & 134 rubygems

Version Path
logstash-filter-cache-redis-0.2.0 vendor/bundle/jruby/1.9/gems/rspec-core-3.6.0/lib/rspec/core/shared_context.rb
logstash-filter-cache-redis-0.1.0 vendor/bundle/jruby/1.9/gems/rspec-core-3.6.0/lib/rspec/core/shared_context.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/rspec-core-3.5.4/lib/rspec/core/shared_context.rb
tdiary-5.0.5 vendor/bundle/gems/rspec-core-3.6.0/lib/rspec/core/shared_context.rb
tdiary-5.0.5 vendor/bundle/gems/rspec-core-3.5.4/lib/rspec/core/shared_context.rb
logstash-filter-csharp-0.1.0 vendor/bundle/jruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/shared_context.rb
logstash-filter-htmlentities-0.1.0 vendor/bundle/jruby/1.9/gems/rspec-core-3.6.0/lib/rspec/core/shared_context.rb
opal-rspec-0.6.1 rspec-core/lib/rspec/core/shared_context.rb
logstash-output-icinga-1.0.0 vendor/jruby/1.9/gems/rspec-core-3.6.0/lib/rspec/core/shared_context.rb
rspec-core-3.6.0 lib/rspec/core/shared_context.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/rspec-core-3.5.4/lib/rspec/core/shared_context.rb
etude_for_ruby-0.1.4 vendor/bundle/ruby/2.4.0/gems/rspec-core-3.5.4/lib/rspec/core/shared_context.rb
etude_for_ruby-0.1.4 vendor/bundle/ruby/2.2.0/gems/rspec-core-3.5.4/lib/rspec/core/shared_context.rb
lazy_record-0.2.1 vendor/bundle/gems/rspec-core-3.5.4/lib/rspec/core/shared_context.rb
lazy_record-0.2.0 vendor/bundle/gems/rspec-core-3.5.4/lib/rspec/core/shared_context.rb
lazy_record-0.1.9 vendor/bundle/gems/rspec-core-3.5.4/lib/rspec/core/shared_context.rb
lazy_record-0.1.8 vendor/bundle/gems/rspec-core-3.5.4/lib/rspec/core/shared_context.rb
lazy_record-0.1.7 vendor/bundle/gems/rspec-core-3.5.4/lib/rspec/core/shared_context.rb
lazy_record-0.1.6 vendor/bundle/gems/rspec-core-3.5.4/lib/rspec/core/shared_context.rb
lazy_record-0.1.4 vendor/bundle/gems/rspec-core-3.5.4/lib/rspec/core/shared_context.rb