Sha256: 08ee68e89e35c6541b2c8e75e2c586a047e09af5fc08c8178f24fac5b2bd173b

Contents?: true

Size: 1.96 KB

Versions: 56

Compression:

Stored size: 1.96 KB

Contents

require "forwardable"

module Rack
  module Test

    # This module serves as the primary integration point for using Rack::Test
    # in a testing environment. It depends on an app method being defined in the
    # same context, and provides the Rack::Test API methods (see Rack::Test::Session
    # for their documentation).
    #
    # Example:
    #
    #   class HomepageTest < Test::Unit::TestCase
    #     include Rack::Test::Methods
    #
    #     def app
    #       MyApp.new
    #     end
    #   end
    module Methods
      extend Forwardable

      def rack_mock_session(name = :default) # :nodoc:
        return build_rack_mock_session unless name

        @_rack_mock_sessions ||= {}
        @_rack_mock_sessions[name] ||= build_rack_mock_session
      end

      def build_rack_mock_session # :nodoc:
        Rack::MockSession.new(app)
      end

      def rack_test_session(name = :default) # :nodoc:
        return build_rack_test_session(name) unless name

        @_rack_test_sessions ||= {}
        @_rack_test_sessions[name] ||= build_rack_test_session(name)
      end

      def build_rack_test_session(name) # :nodoc:
        Rack::Test::Session.new(rack_mock_session(name))
      end

      def current_session # :nodoc:
        rack_test_session(_current_session_names.last)
      end

      def with_session(name) # :nodoc:
        _current_session_names.push(name)
        yield rack_test_session(name)
        _current_session_names.pop
      end

      def _current_session_names # :nodoc:
        @_current_session_names ||= [:default]
      end

      METHODS = [
        :request,
        :get,
        :post,
        :put,
        :patch,
        :delete,
        :options,
        :head,
        :follow_redirect!,
        :header,
        :set_cookie,
        :clear_cookies,
        :authorize,
        :basic_authorize,
        :digest_authorize,
        :last_response,
        :last_request
      ]

      def_delegators :current_session, *METHODS
    end
  end
end

Version data entries

56 entries across 41 versions & 21 rubygems

Version Path
active_mailer-0.0.10 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/rack-test-0.6.2/lib/rack/test/methods.rb
judge-2.0.5 vendor/bundle/ruby/2.1.0/gems/rack-test-0.6.2/lib/rack/test/methods.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/rack-test-0.6.2/lib/rack/test/methods.rb
apl-library-0.0.90 vendor/bundle/ruby/1.9.1/gems/rack-test-0.6.2/lib/rack/test/methods.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/1.9.1/gems/rack-test-0.6.2/lib/rack/test/methods.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/2.1.0/gems/rack-test-0.6.2/lib/rack/test/methods.rb
nanumfont-rails-0.1 vendor/bundle/ruby/2.1.0/gems/rack-test-0.6.2/lib/rack/test/methods.rb
mango-0.8.0 vendor/bundler/ruby/2.1.0/gems/rack-test-0.6.2/lib/rack/test/methods.rb
challah-1.0.0 vendor/bundle/gems/rack-test-0.6.2/lib/rack/test/methods.rb
swipe-rails-0.0.5 vendor/bundle/gems/rack-test-0.6.2/lib/rack/test/methods.rb
active_mailer-0.0.9 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/rack-test-0.6.2/lib/rack/test/methods.rb
active_mailer-0.0.8 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/rack-test-0.6.2/lib/rack/test/methods.rb
active_mailer-0.0.7 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/rack-test-0.6.2/lib/rack/test/methods.rb
active_mailer-0.0.6 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/rack-test-0.6.2/lib/rack/test/methods.rb
font-awesome-rails-3.1.1.2 vendor/ruby/1.9.1/gems/rack-test-0.6.2/lib/rack/test/methods.rb
font-awesome-rails-3.1.1.2 vendor/ruby/2.0.0/gems/rack-test-0.6.2/lib/rack/test/methods.rb
font-awesome-rails-3.1.1.1 vendor/ruby/2.0.0/gems/rack-test-0.6.2/lib/rack/test/methods.rb
font-awesome-rails-3.1.1.1 vendor/ruby/1.9.1/gems/rack-test-0.6.2/lib/rack/test/methods.rb
challah-1.0.0.beta3 vendor/bundle/gems/rack-test-0.6.2/lib/rack/test/methods.rb
fc-webicons-0.0.4 vendor/bundle/ruby/1.9.1/gems/rack-test-0.6.2/lib/rack/test/methods.rb