rubypitaya 2.9.1 → 2.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/rubypitaya/app-template/Gemfile +2 -1
- data/lib/rubypitaya/app-template/Gemfile.lock +23 -6
- data/lib/rubypitaya/app-template/Makefile +39 -14
- data/lib/rubypitaya/app-template/Rakefile +17 -5
- data/lib/rubypitaya/app-template/app/handlers/hello_world_handler.rb +3 -1
- data/lib/rubypitaya/app-template/bin/console +3 -1
- data/lib/rubypitaya/app-template/features/hello_world.feature +8 -0
- data/lib/rubypitaya/app-template/features/player.feature +29 -0
- data/lib/rubypitaya/app-template/features/step_definitions/application_steps.rb +12 -0
- data/lib/rubypitaya/app-template/features/step_definitions/rubypitaya_steps.rb +43 -0
- data/lib/rubypitaya/app-template/features/support/env.rb +0 -0
- data/lib/rubypitaya/app-template/spec/hello_world_handler_spec.rb +19 -0
- data/lib/rubypitaya/app-template/spec/player_handler_spec.rb +50 -0
- data/lib/rubypitaya/app-template/spec/spec_helper.rb +102 -0
- data/lib/rubypitaya/core/handler_router.rb +2 -0
- data/lib/rubypitaya/core/helpers/setup_helper.rb +37 -0
- data/lib/rubypitaya/core/setup.rb +5 -5
- data/lib/rubypitaya/core/spec-helpers/config_spec_helper.rb +41 -0
- data/lib/rubypitaya/core/spec-helpers/handler_spec_helper.rb +87 -0
- data/lib/rubypitaya/core/spec-helpers/handler_spec_helper_class.rb +8 -0
- data/lib/rubypitaya/core/spec-helpers/postman_spec_helper.rb +21 -0
- data/lib/rubypitaya/core/spec-helpers/rubypitaya_spec_helper.rb +14 -0
- data/lib/rubypitaya/core/spec-helpers/setup_spec_helper.rb +37 -0
- data/lib/rubypitaya/version.rb +1 -1
- metadata +31 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 484a04f94edf96a0610d7756b48a08ac349f1a2e72a244ff07046bec55f1f7be
|
4
|
+
data.tar.gz: 9951a60c18f4baaa0e34e88ef29c97a140aa00e328efb4bfdc9661a257ce6960
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 275cfad81877d43ada6941369801ffb438e88d825bd9a1d7f4bdd777bbef56a4a9fcb2e1a06b7753d1d100c716da1b8ce61e5e331f1e27a471df1ae91e7a5182
|
7
|
+
data.tar.gz: cc9b47f3f138bb73474fcd726a88644c806b7c79c908b4334734fbd3171da6fc03db17735de3121af3ad7cde73bb57982b991d0b3cd32e67b295e9b29fa0f3f3
|
@@ -12,20 +12,33 @@ GEM
|
|
12
12
|
minitest (~> 5.1)
|
13
13
|
tzinfo (~> 1.1)
|
14
14
|
zeitwerk (~> 2.2)
|
15
|
+
builder (3.2.4)
|
15
16
|
coderay (1.1.3)
|
16
17
|
concurrent-ruby (1.1.7)
|
18
|
+
cucumber (2.4.0)
|
19
|
+
builder (>= 2.1.2)
|
20
|
+
cucumber-core (~> 1.5.0)
|
21
|
+
cucumber-wire (~> 0.0.1)
|
22
|
+
diff-lcs (>= 1.1.3)
|
23
|
+
gherkin (~> 4.0)
|
24
|
+
multi_json (>= 1.7.5, < 2.0)
|
25
|
+
multi_test (>= 0.1.2)
|
26
|
+
cucumber-core (1.5.0)
|
27
|
+
gherkin (~> 4.0)
|
28
|
+
cucumber-wire (0.0.1)
|
17
29
|
diff-lcs (1.4.4)
|
18
30
|
etcdv3 (0.10.2)
|
19
31
|
grpc (~> 1.17)
|
20
32
|
eventmachine (1.2.7)
|
21
|
-
ffi (1.
|
33
|
+
ffi (1.14.2)
|
34
|
+
gherkin (4.1.3)
|
22
35
|
google-protobuf (3.14.0)
|
23
36
|
googleapis-common-protos-types (1.0.5)
|
24
37
|
google-protobuf (~> 3.11)
|
25
|
-
grpc (1.
|
38
|
+
grpc (1.34.0)
|
26
39
|
google-protobuf (~> 3.13)
|
27
40
|
googleapis-common-protos-types (~> 1.0)
|
28
|
-
i18n (1.8.
|
41
|
+
i18n (1.8.6)
|
29
42
|
concurrent-ruby (~> 1.0)
|
30
43
|
listen (3.2.1)
|
31
44
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
@@ -34,10 +47,12 @@ GEM
|
|
34
47
|
middleware (0.1.0)
|
35
48
|
minitest (5.14.2)
|
36
49
|
multi_json (1.15.0)
|
50
|
+
multi_test (0.1.2)
|
37
51
|
mustermann (1.1.1)
|
38
52
|
ruby2_keywords (~> 0.0.1)
|
39
53
|
nats (0.11.0)
|
40
54
|
eventmachine (~> 1.2, >= 1.2)
|
55
|
+
ostruct (0.1.0)
|
41
56
|
pg (0.21.0)
|
42
57
|
protobuf (3.10.0)
|
43
58
|
activesupport (>= 3.2)
|
@@ -69,11 +84,12 @@ GEM
|
|
69
84
|
rspec-support (~> 3.8.0)
|
70
85
|
rspec-support (3.8.3)
|
71
86
|
ruby2_keywords (0.0.2)
|
72
|
-
rubypitaya (2.
|
87
|
+
rubypitaya (2.11.1)
|
73
88
|
activerecord (= 6.0.2)
|
74
89
|
etcdv3 (= 0.10.2)
|
75
90
|
eventmachine (= 1.2.7)
|
76
91
|
nats (= 0.11.0)
|
92
|
+
ostruct (= 0.1.0)
|
77
93
|
pg (= 0.21.0)
|
78
94
|
protobuf (= 3.10.0)
|
79
95
|
rake (= 10.0)
|
@@ -94,7 +110,7 @@ GEM
|
|
94
110
|
thor (1.0.1)
|
95
111
|
thread_safe (0.3.6)
|
96
112
|
tilt (2.0.10)
|
97
|
-
tzinfo (1.2.
|
113
|
+
tzinfo (1.2.9)
|
98
114
|
thread_safe (~> 0.1)
|
99
115
|
zeitwerk (2.4.2)
|
100
116
|
|
@@ -103,10 +119,11 @@ PLATFORMS
|
|
103
119
|
|
104
120
|
DEPENDENCIES
|
105
121
|
bundler (= 1.17.2)
|
122
|
+
cucumber (= 2.4.0)
|
106
123
|
listen (= 3.2.1)
|
107
124
|
pry (= 0.12.2)
|
108
125
|
rspec (= 3.8.0)
|
109
|
-
rubypitaya (= 2.
|
126
|
+
rubypitaya (= 2.11.1)
|
110
127
|
|
111
128
|
BUNDLED WITH
|
112
129
|
1.17.2
|
@@ -4,6 +4,8 @@ KUBE_NAMESPACE ?= [put-your-namespace-here]
|
|
4
4
|
KUBE_DEPLOYMENT_SERVER ?= rubypitaya
|
5
5
|
KUBECONTEXT ?= ''
|
6
6
|
|
7
|
+
## + Server Commands
|
8
|
+
|
7
9
|
## Run ruby pitaya metagame project
|
8
10
|
run:
|
9
11
|
@docker-compose run --service-ports --rm rubypitaya bundle exec rubypitaya run
|
@@ -12,14 +14,6 @@ run:
|
|
12
14
|
build:
|
13
15
|
@docker-compose build
|
14
16
|
|
15
|
-
## Kill all containers
|
16
|
-
kill:
|
17
|
-
@docker rm -f $$(docker-compose ps -aq)
|
18
|
-
|
19
|
-
## Run tests
|
20
|
-
test:
|
21
|
-
@docker-compose run --service-ports --rm rubypitaya bundle exec rspec
|
22
|
-
|
23
17
|
## Run ruby irb console
|
24
18
|
console:
|
25
19
|
@docker-compose run --service-ports --rm rubypitaya-console bundle exec ruby ./bin/console
|
@@ -27,6 +21,29 @@ console:
|
|
27
21
|
## Run bash on container
|
28
22
|
bash:
|
29
23
|
@docker-compose run --service-ports --rm rubypitaya bash
|
24
|
+
## Kill all containers
|
25
|
+
kill:
|
26
|
+
@docker rm -f $$(docker-compose ps -aq)
|
27
|
+
|
28
|
+
## + Test Commands
|
29
|
+
|
30
|
+
## Run all tests
|
31
|
+
test: test-rspec test-cucumber
|
32
|
+
|
33
|
+
## Run rspec tests. FILE=spec.rb:10
|
34
|
+
test-rspec:
|
35
|
+
@docker-compose run --service-ports --rm rubypitaya bundle exec rspec $(FILE)
|
36
|
+
|
37
|
+
## Run cucumber tests. FILE=something.feature
|
38
|
+
test-cucumber:
|
39
|
+
@docker-compose run --service-ports --rm rubypitaya bundle exec cucumber $(FILE)
|
40
|
+
|
41
|
+
## Update gems dependencies on Gemfile.lock
|
42
|
+
update-dependencies:
|
43
|
+
@rm -f Gemfile.lock
|
44
|
+
@docker run --rm -v "$(PWD)":/usr/src/app -w /usr/src/app ruby:2.6.6 bundle install
|
45
|
+
|
46
|
+
## + Improve metagame
|
30
47
|
|
31
48
|
## Create new migrgation. NAME=[migration-name]
|
32
49
|
create-migration:
|
@@ -36,6 +53,8 @@ create-migration:
|
|
36
53
|
add-plugin:
|
37
54
|
@docker-compose run --service-ports --rm rubypitaya-console bundle exec rubypitaya add-plugin $(GIT)
|
38
55
|
|
56
|
+
## + Database Commands
|
57
|
+
|
39
58
|
## Create database
|
40
59
|
db-create:
|
41
60
|
@docker-compose run --service-ports --rm rubypitaya bundle exec rake db:create
|
@@ -60,9 +79,11 @@ db-drop:
|
|
60
79
|
db-reset:
|
61
80
|
@docker-compose run --service-ports --rm rubypitaya bundle exec rake db:reset
|
62
81
|
|
63
|
-
##
|
64
|
-
|
65
|
-
@docker run --rm
|
82
|
+
## Setup test database
|
83
|
+
db-test-setup:
|
84
|
+
@docker-compose run --service-ports --rm rubypitaya bundle exec rake db:test:setup
|
85
|
+
|
86
|
+
## + Deployment commands
|
66
87
|
|
67
88
|
## Build image to production environment
|
68
89
|
prod-build-image:
|
@@ -81,7 +102,6 @@ prod-deploy-image:
|
|
81
102
|
.PHONY: show-help
|
82
103
|
show-help:
|
83
104
|
@echo "$$(tput bold)Commands:$$(tput sgr0)"
|
84
|
-
@echo
|
85
105
|
@sed -n -e "/^## / { \
|
86
106
|
h; \
|
87
107
|
s/.*//; \
|
@@ -96,14 +116,16 @@ show-help:
|
|
96
116
|
s/\\n/ /g; \
|
97
117
|
p; \
|
98
118
|
}" ${MAKEFILE_LIST} \
|
99
|
-
| LC_ALL='C' sort --ignore-case \
|
100
119
|
| awk -F '---' \
|
101
120
|
-v ncol=$$(tput cols) \
|
102
|
-
-v indent=
|
121
|
+
-v indent=19 \
|
103
122
|
-v col_on="$$(tput setaf 6)" \
|
104
123
|
-v col_off="$$(tput sgr0)" \
|
105
124
|
'{ \
|
106
125
|
printf "%s%*s%s ", col_on, -indent, $$1, col_off; \
|
126
|
+
if (length($$1) == 0) { \
|
127
|
+
printf "\n"; \
|
128
|
+
} \
|
107
129
|
n = split($$2, words, " "); \
|
108
130
|
line_length = ncol - indent; \
|
109
131
|
for (i = 1; i <= n; i++) { \
|
@@ -116,3 +138,6 @@ show-help:
|
|
116
138
|
} \
|
117
139
|
printf "\n"; \
|
118
140
|
}'
|
141
|
+
|
142
|
+
|
143
|
+
|
@@ -16,7 +16,7 @@ namespace :db do
|
|
16
16
|
ActiveRecord::Base.connection.create_database(database_config.database_name)
|
17
17
|
ActiveRecord::Base.connection.close
|
18
18
|
|
19
|
-
puts
|
19
|
+
puts "Database #{database_config.database_name} created."
|
20
20
|
end
|
21
21
|
|
22
22
|
desc 'Migrate the database'
|
@@ -32,7 +32,8 @@ namespace :db do
|
|
32
32
|
ActiveRecord::Migrator.migrations_paths = migrations_paths
|
33
33
|
ActiveRecord::Tasks::DatabaseTasks.migrate
|
34
34
|
ActiveRecord::Base.connection.close
|
35
|
-
|
35
|
+
|
36
|
+
puts "Database #{database_config.database_name} migrated."
|
36
37
|
end
|
37
38
|
|
38
39
|
desc 'Rollback migrations'
|
@@ -72,7 +73,7 @@ namespace :db do
|
|
72
73
|
ActiveRecord::Base.connection.drop_database(database_config.database_name)
|
73
74
|
ActiveRecord::Base.connection.close
|
74
75
|
|
75
|
-
puts
|
76
|
+
puts "Database #{database_config.database_name} deleted."
|
76
77
|
end
|
77
78
|
|
78
79
|
desc 'migration status'
|
@@ -90,8 +91,6 @@ namespace :db do
|
|
90
91
|
puts "#{status.center(8)} #{version.ljust(14)} #{name}"
|
91
92
|
end
|
92
93
|
ActiveRecord::Base.connection.close
|
93
|
-
|
94
|
-
puts 'Rollback done.'
|
95
94
|
end
|
96
95
|
|
97
96
|
desc 'Reset the database'
|
@@ -102,4 +101,17 @@ namespace :db do
|
|
102
101
|
|
103
102
|
puts 'Database reset finish.'
|
104
103
|
end
|
104
|
+
|
105
|
+
namespace :test do
|
106
|
+
desc 'Setup test database'
|
107
|
+
task :setup do
|
108
|
+
ENV['RUBYPITAYA_ENV'] = 'test'
|
109
|
+
|
110
|
+
Rake::Task['db:drop'].invoke
|
111
|
+
Rake::Task['db:create'].invoke
|
112
|
+
Rake::Task['db:migrate'].invoke
|
113
|
+
|
114
|
+
puts 'Database reset finish.'
|
115
|
+
end
|
116
|
+
end
|
105
117
|
end
|
@@ -18,6 +18,7 @@ Gem.find_files('rubypitaya/**/*.rb').each do |path|
|
|
18
18
|
require path unless path.end_with?('spec.rb') ||
|
19
19
|
path.include?('db/migration') ||
|
20
20
|
path.include?('core/templates') ||
|
21
|
+
path.include?('core/spec-helpers') ||
|
21
22
|
path.include?('app-template')
|
22
23
|
end
|
23
24
|
|
@@ -28,7 +29,8 @@ app_folder_paths.each do |app_folder_path|
|
|
28
29
|
|
29
30
|
Dir[app_files_path].each do |path|
|
30
31
|
require path unless path.end_with?('spec.rb') ||
|
31
|
-
path.include?('db/migration')
|
32
|
+
path.include?('db/migration') ||
|
33
|
+
path.include?('spec_helper.rb')
|
32
34
|
end
|
33
35
|
end
|
34
36
|
|
@@ -0,0 +1,8 @@
|
|
1
|
+
Feature: Hello World
|
2
|
+
|
3
|
+
As a developer I want to see the hello world messages
|
4
|
+
|
5
|
+
Scenario: Hello World message
|
6
|
+
Given client call route 'rubypitaya.helloWorldHandler.sayHello'
|
7
|
+
Then server should response 'code' as 'RP-200'
|
8
|
+
And server should response 'data.message' as 'Hello!'
|
@@ -0,0 +1,29 @@
|
|
1
|
+
Feature: Player
|
2
|
+
|
3
|
+
As a game player I want to have a player on database
|
4
|
+
|
5
|
+
Scenario: Create new player
|
6
|
+
Given setup key 'initial_player.wallet.gold' is '10'
|
7
|
+
And config key 'initial_player.name' is 'Guest'
|
8
|
+
When client call route 'rubypitaya.playerHandler.authenticate'
|
9
|
+
Then server should response 'code' as 'RP-200'
|
10
|
+
And server should response 'data.name' as 'Guest'
|
11
|
+
And server should response 'data.gold' as '10'
|
12
|
+
|
13
|
+
Scenario: Get player info
|
14
|
+
Given the following player:
|
15
|
+
| name | gold | user_id |
|
16
|
+
| Someone | 15 | 00000000-0000-0000-0000-000000000001 |
|
17
|
+
And the player 'Someone' is authenticated
|
18
|
+
When client call route 'rubypitaya.playerHandler.getInfo'
|
19
|
+
Then server should response the following json:
|
20
|
+
"""
|
21
|
+
{
|
22
|
+
'code': 'RP-200',
|
23
|
+
'data': {
|
24
|
+
'name': 'Someone',
|
25
|
+
'gold': 15,
|
26
|
+
'userId': '00000000-0000-0000-0000-000000000001'
|
27
|
+
}
|
28
|
+
}
|
29
|
+
"""
|
@@ -0,0 +1,12 @@
|
|
1
|
+
Given(/^[Tt]he [Pp]layer ["'](.+)["'] is authenticated$/) do |player_name|
|
2
|
+
player = MyApp::Player.find_by_name(player_name)
|
3
|
+
@handler_helper.authenticate(player.user_id)
|
4
|
+
end
|
5
|
+
|
6
|
+
Given(/^[Tt]he following [Pp]layer[s]*[:]*$/) do |table|
|
7
|
+
player_hashes = table.hashes
|
8
|
+
player_hashes.each do |player_hash|
|
9
|
+
player_hash[:user] = User.new(id: player_hash[:user_id])
|
10
|
+
MyApp::Player.create(player_hash)
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
|
3
|
+
ENV['RUBYPITAYA_ENV'] = 'test'
|
4
|
+
|
5
|
+
require 'rubypitaya/core/helpers/setup_helper'
|
6
|
+
require 'rubypitaya/core/spec-helpers/handler_spec_helper_class'
|
7
|
+
|
8
|
+
Given(/^[Cc]lient call route ["'](.+)["']$/) do |route|
|
9
|
+
@handler_helper.request(route)
|
10
|
+
end
|
11
|
+
|
12
|
+
Given(/^[Ss]erver should response ["'](.+)["'] as ["'](.+)["']$/) do |response_key, expected_value|
|
13
|
+
response_value = @handler_helper.response.dig(*response_key.split('.').map(&:to_sym))
|
14
|
+
|
15
|
+
expect(response_value.to_s).to eq(expected_value)
|
16
|
+
end
|
17
|
+
|
18
|
+
Given(/^[Ss]erver should response the following json[:]*$/) do |expected_json|
|
19
|
+
expected_json = expected_json.delete("\n").delete(' ')
|
20
|
+
response_json = @handler_helper.response.to_json.gsub("\"", "'")
|
21
|
+
|
22
|
+
expect(response_json).to eq(expected_json)
|
23
|
+
end
|
24
|
+
|
25
|
+
Given(/^[Ss]etup key ["'](.+)["'] is ["'](.+)["']$/) do |key, value|
|
26
|
+
@handler_helper.add_setup(key, value)
|
27
|
+
end
|
28
|
+
|
29
|
+
Given(/^[Cc]onfig key ["'](.+)["'] is ["'](.+)["']$/) do |key, value|
|
30
|
+
@handler_helper.add_config(key, value)
|
31
|
+
end
|
32
|
+
|
33
|
+
Given(/^[Pp]rint server response$/) do
|
34
|
+
puts "response: #{@handler_helper.response}"
|
35
|
+
end
|
36
|
+
|
37
|
+
Before do
|
38
|
+
ActiveRecord::Base.descendants.each { |c| c.delete_all unless c == ActiveRecord::SchemaMigration }
|
39
|
+
@handler_helper = RubyPitaya::HandlerSpecHelperClass.new('cucumber')
|
40
|
+
end
|
41
|
+
|
42
|
+
# After do
|
43
|
+
# end
|
File without changes
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module MyApp
|
4
|
+
|
5
|
+
RSpec.describe 'HelloWorldHandler', type: :request do
|
6
|
+
context 'sayHello' do
|
7
|
+
it 'success' do
|
8
|
+
request("rubypitaya.helloWorldHandler.sayHello")
|
9
|
+
|
10
|
+
expected_response = {
|
11
|
+
code: 'RP-200',
|
12
|
+
data: { message: 'Hello!' }
|
13
|
+
}
|
14
|
+
|
15
|
+
expect(response).to eq(expected_response)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module MyApp
|
4
|
+
|
5
|
+
RSpec.describe 'PlayerHandler', type: :request do
|
6
|
+
context 'authenticate' do
|
7
|
+
it 'create_new_user' do
|
8
|
+
setup = {'initial_player' => {'wallet' => {'gold' => 10}}}
|
9
|
+
config = {'initial_player' => {'name' => 'Guest'}}
|
10
|
+
|
11
|
+
set_setup(setup)
|
12
|
+
set_config(config)
|
13
|
+
|
14
|
+
params = {}
|
15
|
+
request("rubypitaya.playerHandler.authenticate", params)
|
16
|
+
|
17
|
+
player = ::MyApp::Player.last
|
18
|
+
|
19
|
+
expect(response[:code]).to eq('RP-200')
|
20
|
+
expect(response[:data][:name]).to eq('Guest')
|
21
|
+
expect(response[:data][:gold]).to eq(10)
|
22
|
+
|
23
|
+
expect(::User.count).to eq(1)
|
24
|
+
expect(::MyApp::Player.count).to eq(1)
|
25
|
+
expect(player.name).to eq('Guest')
|
26
|
+
expect(player.gold).to eq(10)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'getInfo' do
|
31
|
+
it 'success' do
|
32
|
+
player = ::MyApp::Player.create(name: 'Someone', gold: 12, user: User.new)
|
33
|
+
|
34
|
+
authenticate(player.user_id)
|
35
|
+
|
36
|
+
request("rubypitaya.playerHandler.getInfo")
|
37
|
+
|
38
|
+
expect(response[:code]).to eq('RP-200')
|
39
|
+
expect(response[:data]).to eq(player.to_hash)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'error_not_authenticated' do
|
43
|
+
request("rubypitaya.playerHandler.getInfo")
|
44
|
+
|
45
|
+
expect(response[:code]).to eq(RubyPitaya::StatusCodes::CODE_NOT_AUTHENTICATED)
|
46
|
+
expect(response[:msg]).to eq('Not authenticated')
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'rubypitaya/core/spec-helpers/rubypitaya_spec_helper'
|
2
|
+
|
3
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
4
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
5
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
6
|
+
# this file to always be loaded, without a need to explicitly require it in any
|
7
|
+
# files.
|
8
|
+
#
|
9
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
10
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
11
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
12
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
13
|
+
# a separate helper file that requires the additional dependencies and performs
|
14
|
+
# the additional setup, and require it from the spec files that actually need
|
15
|
+
# it.
|
16
|
+
#
|
17
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
18
|
+
RSpec.configure do |config|
|
19
|
+
# rspec-expectations config goes here. You can use an alternate
|
20
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
21
|
+
# assertions if you prefer.
|
22
|
+
config.expect_with :rspec do |expectations|
|
23
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
24
|
+
# and `failure_message` of custom matchers include text for helper methods
|
25
|
+
# defined using `chain`, e.g.:
|
26
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
27
|
+
# # => "be bigger than 2 and smaller than 4"
|
28
|
+
# ...rather than:
|
29
|
+
# # => "be bigger than 2"
|
30
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
31
|
+
end
|
32
|
+
|
33
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
34
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
35
|
+
config.mock_with :rspec do |mocks|
|
36
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
37
|
+
# a real object. This is generally recommended, and will default to
|
38
|
+
# `true` in RSpec 4.
|
39
|
+
mocks.verify_partial_doubles = true
|
40
|
+
end
|
41
|
+
|
42
|
+
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
|
43
|
+
# have no way to turn it off -- the option exists only for backwards
|
44
|
+
# compatibility in RSpec 3). It causes shared context metadata to be
|
45
|
+
# inherited by the metadata hash of host groups and examples, rather than
|
46
|
+
# triggering implicit auto-inclusion in groups with matching metadata.
|
47
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
48
|
+
|
49
|
+
# The settings below are suggested to provide a good initial experience
|
50
|
+
# with RSpec, but feel free to customize to your heart's content.
|
51
|
+
=begin
|
52
|
+
# This allows you to limit a spec run to individual examples or groups
|
53
|
+
# you care about by tagging them with `:focus` metadata. When nothing
|
54
|
+
# is tagged with `:focus`, all examples get run. RSpec also provides
|
55
|
+
# aliases for `it`, `describe`, and `context` that include `:focus`
|
56
|
+
# metadata: `fit`, `fdescribe` and `fcontext`, respectively.
|
57
|
+
config.filter_run_when_matching :focus
|
58
|
+
|
59
|
+
# Allows RSpec to persist some state between runs in order to support
|
60
|
+
# the `--only-failures` and `--next-failure` CLI options. We recommend
|
61
|
+
# you configure your source control system to ignore this file.
|
62
|
+
config.example_status_persistence_file_path = "spec/examples.txt"
|
63
|
+
|
64
|
+
# Limits the available syntax to the non-monkey patched syntax that is
|
65
|
+
# recommended. For more details, see:
|
66
|
+
# - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
|
67
|
+
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
68
|
+
# - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
|
69
|
+
config.disable_monkey_patching!
|
70
|
+
|
71
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
72
|
+
# be too noisy due to issues in dependencies.
|
73
|
+
config.warnings = true
|
74
|
+
|
75
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
76
|
+
# file, and it's useful to allow more verbose output when running an
|
77
|
+
# individual spec file.
|
78
|
+
if config.files_to_run.one?
|
79
|
+
# Use the documentation formatter for detailed output,
|
80
|
+
# unless a formatter has already been configured
|
81
|
+
# (e.g. via a command-line flag).
|
82
|
+
config.default_formatter = "doc"
|
83
|
+
end
|
84
|
+
|
85
|
+
# Print the 10 slowest examples and example groups at the
|
86
|
+
# end of the spec run, to help surface which specs are running
|
87
|
+
# particularly slow.
|
88
|
+
config.profile_examples = 10
|
89
|
+
|
90
|
+
# Run specs in random order to surface order dependencies. If you find an
|
91
|
+
# order dependency and want to debug it, you can fix the order by providing
|
92
|
+
# the seed, which is printed after each run.
|
93
|
+
# --seed 1234
|
94
|
+
config.order = :random
|
95
|
+
|
96
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
97
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
98
|
+
# test failures related to randomization by passing the same `--seed` value
|
99
|
+
# as the one that triggered the failure.
|
100
|
+
Kernel.srand config.seed
|
101
|
+
=end
|
102
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
|
3
|
+
require 'rubypitaya/core/database_config'
|
4
|
+
|
5
|
+
# Database connection
|
6
|
+
environment_name = ENV.fetch("RUBYPITAYA_ENV") { 'development' }
|
7
|
+
database_config = RubyPitaya::DatabaseConfig.new(environment_name, RubyPitaya::Path::DATABASE_CONFIG_PATH)
|
8
|
+
ActiveRecord::Base.establish_connection(database_config.connection_data)
|
9
|
+
# ActiveRecord::Base.logger = ActiveSupport::Logger.new(STDOUT)
|
10
|
+
# ActiveSupport::LogSubscriber.colorize_logging = true
|
11
|
+
|
12
|
+
connection_data = database_config.connection_data
|
13
|
+
migrations_paths = [RubyPitaya::Path::Core::MIGRATIONS_FOLDER_PATH]
|
14
|
+
migrations_paths += RubyPitaya::Path::Plugins::MIGRATIONS_FOLDER_PATHS
|
15
|
+
migrations_paths += [RubyPitaya::Path::MIGRATIONS_FOLDER_PATH]
|
16
|
+
ActiveRecord::Migrator.migrations_paths = migrations_paths
|
17
|
+
ActiveRecord::Migration.maintain_test_schema!
|
18
|
+
|
19
|
+
# Loading core files
|
20
|
+
Gem.find_files('rubypitaya/**/*.rb').each do |path|
|
21
|
+
require path unless path.end_with?('spec.rb') ||
|
22
|
+
path.include?('db/migration') ||
|
23
|
+
path.include?('core/templates') ||
|
24
|
+
path.include?('core/spec-helpers') ||
|
25
|
+
path.include?('app-template')
|
26
|
+
end
|
27
|
+
|
28
|
+
# Loading application files
|
29
|
+
app_folder_paths = RubyPitaya::Path::Plugins::APP_FOLDER_PATHS + [RubyPitaya::Path::APP_FOLDER_PATH]
|
30
|
+
app_folder_paths.each do |app_folder_path|
|
31
|
+
app_files_path = File.join(app_folder_path, '**/*.rb')
|
32
|
+
|
33
|
+
Dir[app_files_path].each do |path|
|
34
|
+
require path unless path.end_with?('spec.rb') ||
|
35
|
+
path.include?('db/migration')
|
36
|
+
end
|
37
|
+
end
|
@@ -24,11 +24,6 @@ module RubyPitaya
|
|
24
24
|
@config.dig(*split_key)
|
25
25
|
end
|
26
26
|
|
27
|
-
def get_config_from_env_var(key)
|
28
|
-
env_key = key.gsub('.', '_').upcase
|
29
|
-
ENV.fetch(env_key) { nil }
|
30
|
-
end
|
31
|
-
|
32
27
|
def auto_reload
|
33
28
|
require 'listen'
|
34
29
|
|
@@ -48,6 +43,11 @@ module RubyPitaya
|
|
48
43
|
|
49
44
|
private
|
50
45
|
|
46
|
+
def get_config_from_env_var(key)
|
47
|
+
env_key = key.gsub('.', '_').upcase
|
48
|
+
ENV.fetch(env_key) { nil }
|
49
|
+
end
|
50
|
+
|
51
51
|
def load_config_file(configs_folder_path, file_path)
|
52
52
|
config_text = File.open(file_path, &:read)
|
53
53
|
config_hash = YAML.load(ERB.new(config_text).result)
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module RubyPitaya
|
2
|
+
|
3
|
+
class ConfigSpecHelper
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@config_mock = {}
|
7
|
+
end
|
8
|
+
|
9
|
+
def [](key)
|
10
|
+
split_key = key.split('.')
|
11
|
+
@config_mock.dig(*split_key)
|
12
|
+
end
|
13
|
+
|
14
|
+
def auto_reload
|
15
|
+
end
|
16
|
+
|
17
|
+
def config_mock=(value)
|
18
|
+
@config_mock = value
|
19
|
+
end
|
20
|
+
|
21
|
+
def config_core_override=(value)
|
22
|
+
@config_mock = value
|
23
|
+
end
|
24
|
+
|
25
|
+
def add(key, value)
|
26
|
+
keys = key.split('.')
|
27
|
+
add_hash = undig(*keys, value)
|
28
|
+
@config_mock = merge_recursively(@config_mock, add_hash)
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def undig(*keys, value)
|
34
|
+
keys.empty? ? value : { keys.first=>undig(*keys.drop(1), value) }
|
35
|
+
end
|
36
|
+
|
37
|
+
def merge_recursively(a, b)
|
38
|
+
a.merge(b) {|key, a_item, b_item| merge_recursively(a_item, b_item) }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'rubypitaya/core/handler_router'
|
2
|
+
require 'rubypitaya/core/redis_connector'
|
3
|
+
require 'rubypitaya/core/spec-helpers/setup_spec_helper'
|
4
|
+
require 'rubypitaya/core/spec-helpers/config_spec_helper'
|
5
|
+
require 'rubypitaya/core/spec-helpers/postman_spec_helper'
|
6
|
+
|
7
|
+
module RubyPitaya
|
8
|
+
|
9
|
+
module HandlerSpecHelper
|
10
|
+
|
11
|
+
def initialize(context)
|
12
|
+
@@context = context
|
13
|
+
|
14
|
+
@@bll = InstanceHolder.new
|
15
|
+
@@log = Logger.new('/dev/null')
|
16
|
+
@@setup = SetupSpecHelper.new
|
17
|
+
@@config = ConfigSpecHelper.new
|
18
|
+
@@session = Session.new
|
19
|
+
@@postman = PostmanSpecHelper.new
|
20
|
+
|
21
|
+
@@response = {}
|
22
|
+
|
23
|
+
initialize_redis
|
24
|
+
|
25
|
+
@@handler_router ||= HandlerRouter.new()
|
26
|
+
|
27
|
+
|
28
|
+
@@initializer_content = InitializerContent.new(@@bll,
|
29
|
+
@@log,
|
30
|
+
@@redis_connector.redis,
|
31
|
+
@@setup,
|
32
|
+
@@config)
|
33
|
+
@@initializer_broadcast = InitializerBroadcast.new
|
34
|
+
@@initializer_broadcast.run(@@initializer_content)
|
35
|
+
end
|
36
|
+
|
37
|
+
def request(route, params = {})
|
38
|
+
handler_name, action_name = route.split('.')[1..-1]
|
39
|
+
|
40
|
+
@@response = @@handler_router.call(handler_name, action_name, @@session,
|
41
|
+
@@postman, @@redis_connector.redis,
|
42
|
+
@@setup, @@config, @@bll, @@log, params)
|
43
|
+
end
|
44
|
+
|
45
|
+
def response
|
46
|
+
@@response
|
47
|
+
end
|
48
|
+
|
49
|
+
def authenticate(user_id)
|
50
|
+
@@session.uid = user_id
|
51
|
+
end
|
52
|
+
|
53
|
+
def set_config(config)
|
54
|
+
@@config.config_mock = config
|
55
|
+
end
|
56
|
+
|
57
|
+
def set_setup(setup)
|
58
|
+
@@setup.setup_mock = setup
|
59
|
+
end
|
60
|
+
|
61
|
+
def set_postman(postman)
|
62
|
+
@@postman.postman_mock = postman
|
63
|
+
end
|
64
|
+
|
65
|
+
def add_config(*keys, value)
|
66
|
+
@@config.add(*keys, value)
|
67
|
+
end
|
68
|
+
|
69
|
+
def add_setup(*keys, value)
|
70
|
+
@@setup.add(*keys, value)
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def initialize_redis
|
76
|
+
@@redis_connector ||= nil
|
77
|
+
|
78
|
+
if @@redis_connector.nil?
|
79
|
+
redis_address = ENV['REDIS_URL']
|
80
|
+
@@redis_connector = RedisConnector.new(redis_address)
|
81
|
+
@@redis_connector.connect
|
82
|
+
end
|
83
|
+
|
84
|
+
@@redis_connector.redis.flushall
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module RubyPitaya
|
2
|
+
|
3
|
+
class PostmanSpecHelper
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@postman_mock = nil
|
7
|
+
end
|
8
|
+
|
9
|
+
def bind_session(session)
|
10
|
+
response = @postman_mock&.bind_session(session)
|
11
|
+
response ||= {}
|
12
|
+
response
|
13
|
+
end
|
14
|
+
|
15
|
+
def push_to_user(uid, message_route, payload)
|
16
|
+
response = @postman_mock&.push_to_user(uid, message_route, payload)
|
17
|
+
response ||= {}
|
18
|
+
response
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
|
3
|
+
ENV['RUBYPITAYA_ENV'] = 'test'
|
4
|
+
|
5
|
+
require 'rubypitaya/core/helpers/setup_helper'
|
6
|
+
require 'rubypitaya/core/spec-helpers/handler_spec_helper'
|
7
|
+
|
8
|
+
RSpec.configure do |config|
|
9
|
+
config.include RubyPitaya::HandlerSpecHelper
|
10
|
+
|
11
|
+
config.before(:each) do
|
12
|
+
ActiveRecord::Base.descendants.each { |c| c.delete_all unless c == ActiveRecord::SchemaMigration }
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module RubyPitaya
|
2
|
+
|
3
|
+
class SetupSpecHelper
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@setup_mock = {}
|
7
|
+
end
|
8
|
+
|
9
|
+
def [](key)
|
10
|
+
split_key = key.split('.')
|
11
|
+
@setup_mock.dig(*split_key)
|
12
|
+
end
|
13
|
+
|
14
|
+
def auto_reload
|
15
|
+
end
|
16
|
+
|
17
|
+
def setup_mock=(value)
|
18
|
+
@setup_mock = value
|
19
|
+
end
|
20
|
+
|
21
|
+
def add(key, value)
|
22
|
+
keys = key.split('.')
|
23
|
+
add_hash = undig(*keys, value)
|
24
|
+
@setup_mock = merge_recursively(@setup_mock, add_hash)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def undig(*keys, value)
|
30
|
+
keys.empty? ? value : { keys.first=>undig(*keys.drop(1), value) }
|
31
|
+
end
|
32
|
+
|
33
|
+
def merge_recursively(a, b)
|
34
|
+
a.merge(b) {|key, a_item, b_item| merge_recursively(a_item, b_item) }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/rubypitaya/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubypitaya
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.11.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luciano Prestes Cavalcanti
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|
@@ -220,6 +220,20 @@ dependencies:
|
|
220
220
|
- - '='
|
221
221
|
- !ruby/object:Gem::Version
|
222
222
|
version: 3.2.1
|
223
|
+
- !ruby/object:Gem::Dependency
|
224
|
+
name: cucumber
|
225
|
+
requirement: !ruby/object:Gem::Requirement
|
226
|
+
requirements:
|
227
|
+
- - '='
|
228
|
+
- !ruby/object:Gem::Version
|
229
|
+
version: 2.4.0
|
230
|
+
type: :development
|
231
|
+
prerelease: false
|
232
|
+
version_requirements: !ruby/object:Gem::Requirement
|
233
|
+
requirements:
|
234
|
+
- - '='
|
235
|
+
- !ruby/object:Gem::Version
|
236
|
+
version: 2.4.0
|
223
237
|
description: RubyPitaya is an application to create servers using the pitaya protocol.
|
224
238
|
email:
|
225
239
|
- lucianopcbr@gmail.com
|
@@ -254,6 +268,11 @@ files:
|
|
254
268
|
- "./lib/rubypitaya/app-template/docker/dev/Dockerfile"
|
255
269
|
- "./lib/rubypitaya/app-template/docker/entrypoint.sh"
|
256
270
|
- "./lib/rubypitaya/app-template/docker/prod/Dockerfile"
|
271
|
+
- "./lib/rubypitaya/app-template/features/hello_world.feature"
|
272
|
+
- "./lib/rubypitaya/app-template/features/player.feature"
|
273
|
+
- "./lib/rubypitaya/app-template/features/step_definitions/application_steps.rb"
|
274
|
+
- "./lib/rubypitaya/app-template/features/step_definitions/rubypitaya_steps.rb"
|
275
|
+
- "./lib/rubypitaya/app-template/features/support/env.rb"
|
257
276
|
- "./lib/rubypitaya/app-template/kubernetes/README.md"
|
258
277
|
- "./lib/rubypitaya/app-template/kubernetes/deployment-connector.yaml"
|
259
278
|
- "./lib/rubypitaya/app-template/kubernetes/deployment-rubypitaya.yaml"
|
@@ -274,6 +293,9 @@ files:
|
|
274
293
|
- "./lib/rubypitaya/app-template/kubernetes/statefulset-nats.yaml"
|
275
294
|
- "./lib/rubypitaya/app-template/kubernetes/statefulset-postgres.yaml"
|
276
295
|
- "./lib/rubypitaya/app-template/kubernetes/statefulset-redis.yaml"
|
296
|
+
- "./lib/rubypitaya/app-template/spec/hello_world_handler_spec.rb"
|
297
|
+
- "./lib/rubypitaya/app-template/spec/player_handler_spec.rb"
|
298
|
+
- "./lib/rubypitaya/app-template/spec/spec_helper.rb"
|
277
299
|
- "./lib/rubypitaya/core/app/models/user.rb"
|
278
300
|
- "./lib/rubypitaya/core/application_files_importer.rb"
|
279
301
|
- "./lib/rubypitaya/core/config.rb"
|
@@ -284,6 +306,7 @@ files:
|
|
284
306
|
- "./lib/rubypitaya/core/etcd_connector.rb"
|
285
307
|
- "./lib/rubypitaya/core/handler_base.rb"
|
286
308
|
- "./lib/rubypitaya/core/handler_router.rb"
|
309
|
+
- "./lib/rubypitaya/core/helpers/setup_helper.rb"
|
287
310
|
- "./lib/rubypitaya/core/http_routes.rb"
|
288
311
|
- "./lib/rubypitaya/core/initializer_base.rb"
|
289
312
|
- "./lib/rubypitaya/core/initializer_broadcast.rb"
|
@@ -298,6 +321,12 @@ files:
|
|
298
321
|
- "./lib/rubypitaya/core/routes_base.rb"
|
299
322
|
- "./lib/rubypitaya/core/session.rb"
|
300
323
|
- "./lib/rubypitaya/core/setup.rb"
|
324
|
+
- "./lib/rubypitaya/core/spec-helpers/config_spec_helper.rb"
|
325
|
+
- "./lib/rubypitaya/core/spec-helpers/handler_spec_helper.rb"
|
326
|
+
- "./lib/rubypitaya/core/spec-helpers/handler_spec_helper_class.rb"
|
327
|
+
- "./lib/rubypitaya/core/spec-helpers/postman_spec_helper.rb"
|
328
|
+
- "./lib/rubypitaya/core/spec-helpers/rubypitaya_spec_helper.rb"
|
329
|
+
- "./lib/rubypitaya/core/spec-helpers/setup_spec_helper.rb"
|
301
330
|
- "./lib/rubypitaya/core/status_codes.rb"
|
302
331
|
- "./lib/rubypitaya/core/templates/template_migration.rb.erb"
|
303
332
|
- "./lib/rubypitaya/version.rb"
|