跳至内容 跳至搜索
方法
C
D
I
N
O
R
包含的模块

常量

APP_SESSIONS = {}
 

属性

[R] app

类公共方法

new(*args, &blk)

# File actionpack/lib/action_dispatch/testing/integration.rb, line 342
def initialize(*args, &blk)
  super(*args, &blk)
  @integration_session = nil
end

实例公共方法

create_session(app)

# File actionpack/lib/action_dispatch/testing/integration.rb, line 362
def create_session(app)
  klass = APP_SESSIONS[app] ||= Class.new(Integration::Session) {
    # If the app is a Rails app, make url_helpers available on the session. This
    # makes app.url_for and app.foo_path available in the console.
    if app.respond_to?(:routes) && app.routes.is_a?(ActionDispatch::Routing::RouteSet)
      include app.routes.url_helpers
      include app.routes.mounted_helpers
    end
  }
  klass.new(app)
end

default_url_options()

# File actionpack/lib/action_dispatch/testing/integration.rb, line 428
def default_url_options
  integration_session.default_url_options
end

default_url_options=(options)

# File actionpack/lib/action_dispatch/testing/integration.rb, line 432
def default_url_options=(options)
  integration_session.default_url_options = options
end

integration_session()

# File actionpack/lib/action_dispatch/testing/integration.rb, line 352
def integration_session
  @integration_session ||= create_session(app)
end

open_session()

打开一个新的会话实例。如果提供了块,则在返回新会话之前将其传递给块。

session = open_session do |sess|
  sess.extend(CustomAssertions)
end

默认情况下,会自动为您创建一个单一会话,但您可以使用此方法打开多个应同时测试的会话。

# File actionpack/lib/action_dispatch/testing/integration.rb, line 404
def open_session
  dup.tap do |session|
    session.reset!
    session.root_session = self.root_session || self
    yield session if block_given?
  end
end

reset!()

重置当前会话。这对于在一个测试用例中测试多个会话很有用。

# File actionpack/lib/action_dispatch/testing/integration.rb, line 358
def reset!
  @integration_session = create_session(app)
end