Class: RailsTwirp::IntegrationTest

Inherits:
ActiveSupport::TestCase
  • Object
show all
Defined in:
lib/rails_twirp/testing/integration_test.rb

Defined Under Namespace

Classes: Response

Constant Summary collapse

DEFAULT_HOST =
"www.example.com"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ IntegrationTest

Returns a new instance of IntegrationTest.



14
15
16
17
18
# File 'lib/rails_twirp/testing/integration_test.rb', line 14

def initialize(name)
  super
  reset!
  @before_rpc = []
end

Instance Attribute Details

#controllerObject (readonly)

Returns the value of attribute controller.



10
11
12
# File 'lib/rails_twirp/testing/integration_test.rb', line 10

def controller
  @controller
end

#hostObject



20
21
22
# File 'lib/rails_twirp/testing/integration_test.rb', line 20

def host
  @host || DEFAULT_HOST
end

#mount_path=(value) ⇒ Object (writeonly) Also known as: mount_path!

Sets the attribute mount_path

Parameters:

  • value

    the value to set the attribute mount_path to.



11
12
13
# File 'lib/rails_twirp/testing/integration_test.rb', line 11

def mount_path=(value)
  @mount_path = value
end

#requestObject (readonly)

Returns the value of attribute request.



10
11
12
# File 'lib/rails_twirp/testing/integration_test.rb', line 10

def request
  @request
end

#responseObject (readonly)

Returns the value of attribute response.



10
11
12
# File 'lib/rails_twirp/testing/integration_test.rb', line 10

def response
  @response
end

Instance Method Details

#appObject



62
63
64
# File 'lib/rails_twirp/testing/integration_test.rb', line 62

def app
  RailsTwirp.test_app
end

#before_rpc(&block) ⇒ Object



43
44
45
# File 'lib/rails_twirp/testing/integration_test.rb', line 43

def before_rpc(&block)
  @before_rpc << block
end

#https!(value = true) ⇒ Object



30
31
32
# File 'lib/rails_twirp/testing/integration_test.rb', line 30

def https!(value = true)
  @https = value
end

#https?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/rails_twirp/testing/integration_test.rb', line 26

def https?
  @https
end

#reset!Object



34
35
36
37
38
39
40
41
# File 'lib/rails_twirp/testing/integration_test.rb', line 34

def reset!
  @request = nil
  @response = nil
  @host = nil
  @host = nil
  @https = false
  @mount_path = "/twirp"
end

#rpc(service, rpc, request, headers: nil) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/rails_twirp/testing/integration_test.rb', line 47

def rpc(service, rpc, request, headers: nil)
  @request = request

  env = build_rack_env(service, rpc, request, headers)
  @before_rpc.each do |hook|
    hook.call(env)
  end

  status, headers, body = app.call(env)
  @response = decode_rack_response(service, rpc, status, headers, body)
  set_controller_from_rack_env(env)

  @response
end