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.



12
13
14
15
16
# File 'lib/rails_twirp/testing/integration_test.rb', line 12

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

Instance Attribute Details

#controllerObject (readonly)

Returns the value of attribute controller.



8
9
10
# File 'lib/rails_twirp/testing/integration_test.rb', line 8

def controller
  @controller
end

#hostObject



18
19
20
# File 'lib/rails_twirp/testing/integration_test.rb', line 18

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.



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

def mount_path=(value)
  @mount_path = value
end

#requestObject (readonly)

Returns the value of attribute request.



8
9
10
# File 'lib/rails_twirp/testing/integration_test.rb', line 8

def request
  @request
end

#responseObject (readonly)

Returns the value of attribute response.



8
9
10
# File 'lib/rails_twirp/testing/integration_test.rb', line 8

def response
  @response
end

Instance Method Details

#appObject



60
61
62
# File 'lib/rails_twirp/testing/integration_test.rb', line 60

def app
  RailsTwirp.test_app
end

#before_rpc(&block) ⇒ Object



41
42
43
# File 'lib/rails_twirp/testing/integration_test.rb', line 41

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

#https!(value = true) ⇒ Object



28
29
30
# File 'lib/rails_twirp/testing/integration_test.rb', line 28

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

#https?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/rails_twirp/testing/integration_test.rb', line 24

def https?
  @https
end

#reset!Object



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

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

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



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

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