Module: RubyPitaya::AppSpecHelper

Included in:
AppSpecHelperClass
Defined in:
lib/rubypitaya/core/spec-helpers/app_spec_helper.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.finalize_after_suiteObject



42
43
44
45
# File 'lib/rubypitaya/core/spec-helpers/app_spec_helper.rb', line 42

def self.finalize_after_suite
  clear_all_services_data
  disconnect_services
end

.initialize_before_suiteObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rubypitaya/core/spec-helpers/app_spec_helper.rb', line 16

def self.initialize_before_suite
  default_setup = Setup.new.get_config
  default_config = ConfigCore.new

  @@log = Logger.new('/dev/null')
  @@setup = SetupSpecHelper.new(default_setup)
  @@config = ConfigSpecHelper.new(default_config)
  @@session = Session.new
  @@postman = PostmanSpecHelper.new
  @@services = ServiceHolder.new

  is_cheats_enabled = @@setup.fetch('rubypitaya.server.cheats', true)
  @@handler_router ||= HandlerRouter.new(is_cheats_enabled)


  @@initializer_content = InitializerContent.new(@@log,
                                                 @@services,
                                                 @@setup,
                                                 @@config,
                                                 @@handler_router.handlers)
  @@initializer_broadcast = InitializerBroadcast.new
  @@initializer_broadcast.run(@@initializer_content)

  connect_services
end

.sessionObject



12
13
14
# File 'lib/rubypitaya/core/spec-helpers/app_spec_helper.rb', line 12

def self.session
  @@session
end

.update_before_eachObject



47
48
49
50
51
52
53
# File 'lib/rubypitaya/core/spec-helpers/app_spec_helper.rb', line 47

def self.update_before_each
  @@response = {}
  @@setup.clear
  @@config.clear
  @@session.clear
  clear_all_services_data
end

Instance Method Details

#add_config(*keys, value) ⇒ Object



91
92
93
# File 'lib/rubypitaya/core/spec-helpers/app_spec_helper.rb', line 91

def add_config(*keys, value)
  @@config.add(*keys, value)
end

#add_setup(*keys, value) ⇒ Object



95
96
97
# File 'lib/rubypitaya/core/spec-helpers/app_spec_helper.rb', line 95

def add_setup(*keys, value)
  @@setup.add(*keys, value)
end

#authenticate(user_id) ⇒ Object



75
76
77
# File 'lib/rubypitaya/core/spec-helpers/app_spec_helper.rb', line 75

def authenticate(user_id)
  @@session.uid = user_id
end

#configObject



107
108
109
# File 'lib/rubypitaya/core/spec-helpers/app_spec_helper.rb', line 107

def config
  @@config
end

#initialize(context) ⇒ Object



55
56
# File 'lib/rubypitaya/core/spec-helpers/app_spec_helper.rb', line 55

def initialize(context)
end

#logObject



99
100
101
# File 'lib/rubypitaya/core/spec-helpers/app_spec_helper.rb', line 99

def log
  @@log
end

#postmanObject



115
116
117
# File 'lib/rubypitaya/core/spec-helpers/app_spec_helper.rb', line 115

def postman
  @@postman
end

#request(route, params = {}) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/rubypitaya/core/spec-helpers/app_spec_helper.rb', line 58

def request(route, params = {})
  handler_name, action_name = route.split('.')[1..-1]

  @@response = @@handler_router.call(handler_name, action_name, @@session,
                                     @@postman, @@services, @@setup,
                                     @@config, @@log, params)
  rescue RouteError => error
    @@response = {
      code: error.code,
      message: error.message
    }
end

#responseObject



71
72
73
# File 'lib/rubypitaya/core/spec-helpers/app_spec_helper.rb', line 71

def response
  @@response
end

#servicesObject



119
120
121
# File 'lib/rubypitaya/core/spec-helpers/app_spec_helper.rb', line 119

def services
  @@services
end

#sessionObject



111
112
113
# File 'lib/rubypitaya/core/spec-helpers/app_spec_helper.rb', line 111

def session
  @@session
end

#set_config(config) ⇒ Object



79
80
81
# File 'lib/rubypitaya/core/spec-helpers/app_spec_helper.rb', line 79

def set_config(config)
  @@config.config_mock = config
end

#set_postman(postman) ⇒ Object



87
88
89
# File 'lib/rubypitaya/core/spec-helpers/app_spec_helper.rb', line 87

def set_postman(postman)
  @@postman.postman_mock = postman
end

#set_setup(setup) ⇒ Object



83
84
85
# File 'lib/rubypitaya/core/spec-helpers/app_spec_helper.rb', line 83

def set_setup(setup)
  @@setup.setup_mock = setup
end

#setupObject



103
104
105
# File 'lib/rubypitaya/core/spec-helpers/app_spec_helper.rb', line 103

def setup
  @@setup
end