sapience 0.2.7 → 0.2.8
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/.simplecov +15 -19
- data/.travis.yml +13 -2
- data/Rakefile +1 -0
- data/docker-compose.yml +21 -6
- data/lib/sapience/appender/stream.rb +1 -1
- data/lib/sapience/extensions/action_cable/tagged_logger_proxy.rb +6 -8
- data/lib/sapience/extensions/active_model_serializers/logging.rb +11 -13
- data/lib/sapience/extensions/grape/middleware/logging.rb +14 -16
- data/lib/sapience/rails.rb +3 -3
- data/lib/sapience/version.rb +1 -1
- data/lib/sapience.rb +0 -1
- data/lib/tasks/coverage.rake +68 -0
- data/{test_app → test_apps/grape}/.gitignore +0 -0
- data/test_apps/grape/.simplecov +25 -0
- data/test_apps/grape/Gemfile +30 -0
- data/test_apps/grape/Rakefile.rb +8 -0
- data/test_apps/grape/config.ru +5 -0
- data/test_apps/grape/lib/ping/api.rb +16 -0
- data/test_apps/grape/lib/ping.rb +3 -0
- data/test_apps/grape/spec/lib/ping/api_spec.rb +41 -0
- data/test_apps/grape/spec/spec_helper.rb +25 -0
- data/test_apps/rails/.gitignore +38 -0
- data/{test_app → test_apps/rails}/.ruby-version +0 -0
- data/test_apps/rails/.simplecov +25 -0
- data/{test_app → test_apps/rails}/Gemfile +5 -5
- data/{test_app → test_apps/rails}/README.md +0 -0
- data/{test_app → test_apps/rails}/Rakefile +0 -0
- data/{test_app → test_apps/rails}/app/assets/config/manifest.js +0 -0
- data/{test_app → test_apps/rails}/app/assets/images/.keep +0 -0
- data/{test_app → test_apps/rails}/app/assets/javascripts/posts.js +0 -0
- data/{test_app → test_apps/rails}/app/assets/stylesheets/application.css +0 -0
- data/{test_app → test_apps/rails}/app/assets/stylesheets/posts.css +0 -0
- data/{test_app → test_apps/rails}/app/assets/stylesheets/scaffold.css +0 -0
- data/{test_app → test_apps/rails}/app/channels/application_cable/channel.rb +0 -0
- data/{test_app → test_apps/rails}/app/channels/application_cable/connection.rb +0 -0
- data/{test_app → test_apps/rails}/app/controllers/application_controller.rb +0 -0
- data/{test_app → test_apps/rails}/app/controllers/concerns/.keep +0 -0
- data/{test_app → test_apps/rails}/app/controllers/posts_controller.rb +0 -0
- data/{test_app → test_apps/rails}/app/helpers/application_helper.rb +0 -0
- data/{test_app → test_apps/rails}/app/helpers/posts_helper.rb +0 -0
- data/{test_app → test_apps/rails}/app/jobs/application_job.rb +0 -0
- data/{test_app → test_apps/rails}/app/mailers/application_mailer.rb +0 -0
- data/{test_app → test_apps/rails}/app/models/application_record.rb +0 -0
- data/{test_app → test_apps/rails}/app/models/concerns/.keep +0 -0
- data/{test_app → test_apps/rails}/app/models/post.rb +0 -0
- data/{test_app → test_apps/rails}/app/models/user.rb +0 -0
- data/{test_app → test_apps/rails}/app/views/layouts/application.html.erb +0 -0
- data/{test_app → test_apps/rails}/app/views/layouts/mailer.html.erb +0 -0
- data/{test_app → test_apps/rails}/app/views/layouts/mailer.text.erb +0 -0
- data/{test_app → test_apps/rails}/app/views/posts/_form.html.slim +0 -0
- data/{test_app → test_apps/rails}/app/views/posts/edit.html.slim +0 -0
- data/{test_app → test_apps/rails}/app/views/posts/index.html.slim +0 -0
- data/{test_app → test_apps/rails}/app/views/posts/new.html.slim +0 -0
- data/{test_app → test_apps/rails}/app/views/posts/show.html.slim +0 -0
- data/{test_app → test_apps/rails}/app/workers/test_worker.rb +1 -1
- data/{test_app → test_apps/rails}/bin/bundle +0 -0
- data/{test_app → test_apps/rails}/bin/rails +0 -0
- data/{test_app → test_apps/rails}/bin/rake +0 -0
- data/{test_app → test_apps/rails}/bin/setup +0 -0
- data/{test_app → test_apps/rails}/bin/sneakers +0 -0
- data/{test_app → test_apps/rails}/bin/update +0 -0
- data/{test_app → test_apps/rails}/config/application.rb +0 -0
- data/{test_app → test_apps/rails}/config/boot.rb +0 -0
- data/{test_app → test_apps/rails}/config/cable.yml +0 -0
- data/{test_app → test_apps/rails}/config/database.yml +0 -0
- data/{test_app → test_apps/rails}/config/environment.rb +0 -0
- data/{test_app → test_apps/rails}/config/environments/development.rb +0 -0
- data/{test_app → test_apps/rails}/config/environments/production.rb +0 -0
- data/{test_app → test_apps/rails}/config/environments/test.rb +0 -0
- data/{test_app → test_apps/rails}/config/initializers/application_controller_renderer.rb +0 -0
- data/{test_app → test_apps/rails}/config/initializers/backtrace_silencers.rb +0 -0
- data/{test_app → test_apps/rails}/config/initializers/cookies_serializer.rb +0 -0
- data/{test_app → test_apps/rails}/config/initializers/filter_parameter_logging.rb +0 -0
- data/{test_app → test_apps/rails}/config/initializers/inflections.rb +0 -0
- data/{test_app → test_apps/rails}/config/initializers/mime_types.rb +0 -0
- data/{test_app → test_apps/rails}/config/initializers/new_framework_defaults.rb +0 -0
- data/{test_app → test_apps/rails}/config/initializers/session_store.rb +0 -0
- data/{test_app → test_apps/rails}/config/initializers/sneakers.rb +0 -0
- data/{test_app → test_apps/rails}/config/initializers/wrap_parameters.rb +0 -0
- data/{test_app → test_apps/rails}/config/locales/en.yml +0 -0
- data/{test_app → test_apps/rails}/config/puma.rb +0 -0
- data/{test_app → test_apps/rails}/config/routes.rb +0 -0
- data/{test_app → test_apps/rails}/config/sapience_example.yml +0 -0
- data/{test_app → test_apps/rails}/config/secrets.yml +0 -0
- data/{test_app → test_apps/rails}/config.ru +0 -0
- data/{test_app → test_apps/rails}/db/migrate/20160812092236_create_users.rb +0 -0
- data/{test_app → test_apps/rails}/db/migrate/20160902141445_create_posts.rb +0 -0
- data/{test_app → test_apps/rails}/db/schema.rb +0 -0
- data/{test_app → test_apps/rails}/db/seeds.rb +0 -0
- data/{test_app → test_apps/rails}/lib/assets/.keep +0 -0
- data/{test_app → test_apps/rails}/lib/external_sneaker.rb +0 -0
- data/{test_app → test_apps/rails}/lib/tasks/.keep +0 -0
- data/{test_app → test_apps/rails}/public/404.html +0 -0
- data/{test_app → test_apps/rails}/public/422.html +0 -0
- data/{test_app → test_apps/rails}/public/500.html +0 -0
- data/{test_app → test_apps/rails}/public/apple-touch-icon-precomposed.png +0 -0
- data/{test_app → test_apps/rails}/public/apple-touch-icon.png +0 -0
- data/{test_app → test_apps/rails}/public/favicon.ico +0 -0
- data/{test_app → test_apps/rails}/public/robots.txt +0 -0
- data/{test_app → test_apps/rails}/spec/controllers/posts_controller_spec.rb +0 -0
- data/{test_app → test_apps/rails}/spec/factories/posts.rb +0 -0
- data/{test_app → test_apps/rails}/spec/factories/users.rb +0 -0
- data/{test_app → test_apps/rails}/spec/fixtures/sapience.yml +0 -0
- data/{test_app → test_apps/rails}/spec/helpers/posts_helper_spec.rb +0 -0
- data/{test_app → test_apps/rails}/spec/integration/sapience_spec.rb +0 -0
- data/{test_app → test_apps/rails}/spec/models/post_spec.rb +0 -0
- data/{test_app → test_apps/rails}/spec/models/user_spec.rb +0 -0
- data/{test_app → test_apps/rails}/spec/rails_helper.rb +4 -2
- data/{test_app → test_apps/rails}/spec/requests/posts_spec.rb +0 -0
- data/{test_app → test_apps/rails}/spec/routing/posts_routing_spec.rb +0 -0
- data/{test_app → test_apps/rails}/spec/spec_helper.rb +0 -0
- data/{test_app → test_apps/rails}/spec/views/posts/edit.html.slim_spec.rb +0 -0
- data/{test_app → test_apps/rails}/spec/views/posts/index.html.slim_spec.rb +0 -0
- data/{test_app → test_apps/rails}/spec/views/posts/new.html.slim_spec.rb +0 -0
- data/{test_app → test_apps/rails}/spec/views/posts/show.html.slim_spec.rb +0 -0
- data/{test_app → test_apps/rails}/spec/workers/test_worker_spec.rb +0 -0
- data/{test_app/log → test_apps/rails/vendor/assets/stylesheets}/.keep +0 -0
- metadata +108 -102
- data/lib/sapience/configuration/grape.rb +0 -9
- data/test_app/.rspec +0 -2
- data/test_app/tmp/.keep +0 -0
- data/test_app/vendor/assets/stylesheets/.keep +0 -0
- data/test_app.simplecov +0 -19
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 14d3cb7ced5f31db60bee83527aa91fa14054562
|
|
4
|
+
data.tar.gz: cbdbeb2b580049917ff6914f30750ca757ba953d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d6a2d9d9e32281d0c8f74c8ba387a721e287aacbc33d4e7d3d896db74340ea9af40ca52b5defc95f6b3fe50cf9239ad582fb9544deef783e5c960312f74a9ced
|
|
7
|
+
data.tar.gz: feff9250b817af7363881bdba3311ea0b0c1c02b701e441e793840424bb7393615522b7b8570e43d5c726f2e70cdc872babf1611151736e9b4c9b4f426f97cb6
|
data/.simplecov
CHANGED
|
@@ -1,22 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
require "codeclimate-test-reporter"
|
|
3
|
-
CodeClimate::TestReporter.start
|
|
1
|
+
require "simplecov-json"
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
else
|
|
8
|
-
require "simplecov-json"
|
|
9
|
-
SimpleCov.maximum_coverage_drop 1
|
|
3
|
+
coverage_dir = './coverage/sapience'
|
|
4
|
+
FileUtils.rm_rf coverage_dir
|
|
10
5
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
6
|
+
SimpleCov.coverage_dir coverage_dir
|
|
7
|
+
SimpleCov.command_name "sapience"
|
|
8
|
+
SimpleCov.maximum_coverage_drop 1
|
|
9
|
+
SimpleCov.formatters = [
|
|
10
|
+
SimpleCov::Formatter::HTMLFormatter,
|
|
11
|
+
SimpleCov::Formatter::JSONFormatter,
|
|
12
|
+
]
|
|
15
13
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
end
|
|
14
|
+
SimpleCov.start do
|
|
15
|
+
add_filter "/spec/"
|
|
16
|
+
add_filter "/bin/"
|
|
17
|
+
add_filter "/gemfiles/"
|
|
18
|
+
end
|
data/.travis.yml
CHANGED
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
sudo: required
|
|
2
|
+
dist: trusty
|
|
2
3
|
language: ruby
|
|
3
4
|
services:
|
|
4
5
|
- docker
|
|
6
|
+
|
|
7
|
+
before_script:
|
|
8
|
+
- mkdir -p coverage/rails coverage/grape coverage/sapience
|
|
9
|
+
|
|
5
10
|
script:
|
|
6
|
-
- docker-compose run
|
|
7
|
-
- docker-compose run
|
|
11
|
+
- docker-compose run rspec
|
|
12
|
+
- docker-compose run rails
|
|
13
|
+
- docker-compose run grape
|
|
14
|
+
|
|
15
|
+
after_success:
|
|
16
|
+
- chown -R $(whoami) coverage
|
|
17
|
+
- bundle exec rake coverage:merge coverage:send
|
|
18
|
+
|
|
8
19
|
notifications:
|
|
9
20
|
slack:
|
|
10
21
|
secure: apFwkfBQ+3NDJgcLNCHQori9qtr6ePaN3Xx7Sy7NVWwYm9BHNxoX/FN8/hxR63JjXrf1C0hK0FLQ0TiA0BN9PgEEIecg78BvWUwMClDDiwhyYN3H0Bbg35PUFtgDIrOGpu/TYlxNmdHEDYEAxaWsl9wSds8pAJsN6m7VTjGfBwJUDcOiM4L1eRpbp7smPqOjmuQFuOJnO8YkPb+6nUfz53cJrMRUdha89Vgmvnw6cP4/Ms1TsL3vKmMSVbGGh/6WNKPjU6IbuUjwlsh6a9xWxQOk6Wnis/Z+kA+T0XbLMuTLLmzRDuql1tjJeMPi+wukmK1a7GjpPkpkzAgwLQ/CkjTBfIRbMyaBYSuAciuOY8PDtCcT4WLwEvdZbkFmhAdSr1RYxIBpONVfZ/5DT3bpk71+O74OIBqxG6NmkiZ0B6u9/KxbnIINLVAcVaqsN8sdSqWlWKzPm45BfGPXGjmGGgIVFU31rs+W5Zs7IYMNUjZxabYKIv9TsBONbogfbcoGZA+rWWUnQdjypNWJS9wyQDvJ4btxqy8YhDfaV6gF30Un5JcAggMutzKJiYi+qAeh0uN3/9XoXV2N6XBnh58h8ny1NY+0vklWhtFGR1wfFAqkDskvCIZabSeJ5bFM6FtNbNKq9tYciS+eAO1vEYQVDFt9eY2uZF2mFDKRnEegHMU=
|
data/Rakefile
CHANGED
data/docker-compose.yml
CHANGED
|
@@ -10,7 +10,9 @@ services:
|
|
|
10
10
|
RABBITMQ_DEFAULT_USER: sapience
|
|
11
11
|
RABBITMQ_DEFAULT_PASS: tests
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
base:
|
|
14
16
|
image: ruby:2.3
|
|
15
17
|
cpu_shares: 4
|
|
16
18
|
# Specify the directory from where all commands sent to the container will be
|
|
@@ -27,14 +29,14 @@ services:
|
|
|
27
29
|
# Mount our app code directory (".") into our app containers at the
|
|
28
30
|
# "/usr/src/app" folder:
|
|
29
31
|
- .:/usr/src/app
|
|
30
|
-
|
|
31
32
|
# Mount the 'gems' volume on the folder that stores bundled gems:
|
|
32
33
|
- gems:/usr/local/bundle
|
|
33
34
|
|
|
34
35
|
|
|
36
|
+
|
|
35
37
|
rspec:
|
|
36
38
|
extends:
|
|
37
|
-
service:
|
|
39
|
+
service: base
|
|
38
40
|
entrypoint: /usr/src/app/dev-entrypoint.sh
|
|
39
41
|
command: bundle exec rake
|
|
40
42
|
depends_on:
|
|
@@ -43,10 +45,12 @@ services:
|
|
|
43
45
|
CODECLIMATE_REPO_TOKEN: 204dc055302da6aed94379e249aa0645636d1d1794920c62db05c5fa968215de
|
|
44
46
|
PATH: /usr/src/app/bin:/usr/local/bundle/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
|
45
47
|
|
|
46
|
-
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
rails:
|
|
47
51
|
extends:
|
|
48
|
-
service:
|
|
49
|
-
working_dir: /usr/src/app/
|
|
52
|
+
service: base
|
|
53
|
+
working_dir: /usr/src/app/test_apps/rails
|
|
50
54
|
entrypoint: /usr/src/app/dev-entrypoint.sh
|
|
51
55
|
command: bundle exec rspec
|
|
52
56
|
depends_on:
|
|
@@ -54,3 +58,14 @@ services:
|
|
|
54
58
|
environment:
|
|
55
59
|
AMQP: amqp://sapience:tests@rabbitmq:5672
|
|
56
60
|
PATH: /usr/src/app/bin:/usr/local/bundle/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
grape:
|
|
65
|
+
extends:
|
|
66
|
+
service: base
|
|
67
|
+
working_dir: /usr/src/app/test_apps/grape
|
|
68
|
+
entrypoint: /usr/src/app/dev-entrypoint.sh
|
|
69
|
+
command: bundle exec rspec
|
|
70
|
+
environment:
|
|
71
|
+
PATH: /usr/src/app/bin:/usr/local/bundle/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
|
@@ -61,7 +61,7 @@ module Sapience
|
|
|
61
61
|
# rubocop:disable AbcSize, CyclomaticComplexity, PerceivedComplexity
|
|
62
62
|
def initialize(options = {}, &block)
|
|
63
63
|
unless options[:io] || options[:file_name]
|
|
64
|
-
fail "
|
|
64
|
+
fail ArgumentError, "missing mandatory argument :file_name or :io"
|
|
65
65
|
end
|
|
66
66
|
|
|
67
67
|
opts = options.dup
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
alias_method :orig_tag, :tag
|
|
1
|
+
class ActionCable::Connection::TaggedLoggerProxy # rubocop:disable ClassAndModuleChildren
|
|
2
|
+
alias_method :orig_tag, :tag
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
end
|
|
4
|
+
def tag(logger, &block)
|
|
5
|
+
current_tags = tags - logger.tags
|
|
6
|
+
logger.tagged(*current_tags, &block)
|
|
9
7
|
end
|
|
10
|
-
end
|
|
8
|
+
end
|
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
# Patch ActiveModelSerializers logger
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
require "active_model_serializers/logging"
|
|
3
|
+
require "active_model_serializers/logging"
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
module ActiveModelSerializers::Logging # rubocop:disable ClassAndModuleChildren
|
|
6
|
+
def self.included(base)
|
|
7
|
+
base.send(:include, Sapience::Loggable)
|
|
8
|
+
end
|
|
10
9
|
|
|
11
|
-
|
|
10
|
+
private
|
|
12
11
|
|
|
13
|
-
|
|
12
|
+
alias_method :orig_tag_logger, :tag_logger
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
end
|
|
14
|
+
def tag_logger(*tags, &block)
|
|
15
|
+
logger.tagged(*tags, &block)
|
|
18
16
|
end
|
|
19
|
-
|
|
20
|
-
ActiveModelSerializers.send(:include, Sapience::Loggable)
|
|
21
17
|
end
|
|
18
|
+
|
|
19
|
+
ActiveModelSerializers.send(:include, Sapience::Loggable)
|
|
@@ -26,30 +26,28 @@ module Sapience
|
|
|
26
26
|
nil
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
-
def call!(env)
|
|
30
|
-
super
|
|
31
|
-
end
|
|
32
|
-
|
|
33
29
|
protected
|
|
34
30
|
|
|
35
|
-
def response
|
|
36
|
-
super
|
|
37
|
-
rescue
|
|
38
|
-
nil
|
|
39
|
-
end
|
|
40
|
-
|
|
41
31
|
def parameters # rubocop:disable AbcSize
|
|
42
32
|
{
|
|
43
|
-
status: (response.nil? ? "fail" : response.status),
|
|
44
|
-
db_runtime: db_runtime,
|
|
45
|
-
view_runtime: view_runtime,
|
|
46
|
-
total_runtime: total_runtime,
|
|
47
33
|
method: request.request_method,
|
|
48
|
-
|
|
49
|
-
|
|
34
|
+
request_path: request.path,
|
|
35
|
+
format: "json",
|
|
36
|
+
status: response.try(:status),
|
|
37
|
+
class_name: env['api.endpoint'].options[:for].to_s,
|
|
38
|
+
action: "index",
|
|
50
39
|
host: request.host,
|
|
51
40
|
ip: (request.env["HTTP_X_FORWARDED_FOR"] || request.env["REMOTE_ADDR"]),
|
|
52
41
|
ua: request.env["HTTP_USER_AGENT"],
|
|
42
|
+
# route: "test_controller#index",
|
|
43
|
+
# message: "Completed #index",
|
|
44
|
+
tags: Sapience.tags,
|
|
45
|
+
params: request.params,
|
|
46
|
+
runtimes: {
|
|
47
|
+
total: total_runtime,
|
|
48
|
+
view: view_runtime,
|
|
49
|
+
db: db_runtime,
|
|
50
|
+
},
|
|
53
51
|
}
|
|
54
52
|
end
|
|
55
53
|
|
data/lib/sapience/rails.rb
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
require "sapience"
|
|
2
|
-
require "sapience/extensions/action_cable/tagged_logger_proxy"
|
|
3
2
|
require "sapience/extensions/action_controller/live"
|
|
4
3
|
require "sapience/extensions/action_controller/log_subscriber"
|
|
5
4
|
require "sapience/extensions/action_dispatch/debug_exceptions"
|
|
6
5
|
require "sapience/extensions/action_view/streaming_template_renderer"
|
|
7
|
-
require "sapience/extensions/active_job/logging"
|
|
8
|
-
require "sapience/extensions/active_model_serializers/logging"
|
|
9
6
|
require "sapience/extensions/active_record/log_subscriber"
|
|
10
7
|
require "sapience/extensions/rails/rack/logger"
|
|
11
8
|
require "sapience/extensions/rails/rack/logger_info_as_debug"
|
|
@@ -57,6 +54,9 @@ module Sapience
|
|
|
57
54
|
|
|
58
55
|
# Before any initializers run, but after the gems have been loaded
|
|
59
56
|
config.after_initialize do
|
|
57
|
+
require "sapience/extensions/action_cable/tagged_logger_proxy" if defined?(ActionCable)
|
|
58
|
+
require "sapience/extensions/active_model_serializers/logging" if defined?(ActiveModelSerializers)
|
|
59
|
+
require "sapience/extensions/active_job/logging" if defined?(ActiveJob)
|
|
60
60
|
# Replace the Bugsnag logger
|
|
61
61
|
Bugsnag.configure { |config| config.logger = Sapience[Bugsnag] } if defined?(Bugsnag)
|
|
62
62
|
Sapience::Extensions::ActionController::LogSubscriber.attach_to :action_controller
|
data/lib/sapience/version.rb
CHANGED
data/lib/sapience.rb
CHANGED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
COVERAGE_FILE = ".simplecov".freeze
|
|
2
|
+
COVERAGE_BKP_FILE = ".simplecov.bkp".freeze
|
|
3
|
+
|
|
4
|
+
def coverage_dir
|
|
5
|
+
p File.join(Dir.pwd, "coverage")
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def hide_coverage_config
|
|
9
|
+
FileUtils.mv COVERAGE_FILE, COVERAGE_BKP_FILE if File.exist?(COVERAGE_FILE)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def unhide_coverage_config
|
|
13
|
+
FileUtils.mv COVERAGE_BKP_FILE, COVERAGE_FILE if File.exist?(COVERAGE_BKP_FILE)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
namespace :coverage do
|
|
17
|
+
task :merge do
|
|
18
|
+
hide_coverage_config
|
|
19
|
+
require "json"
|
|
20
|
+
require "simplecov/version"
|
|
21
|
+
require "simplecov/result"
|
|
22
|
+
require "simplecov-html"
|
|
23
|
+
require "simplecov-json"
|
|
24
|
+
|
|
25
|
+
coverage_file_pattern = "{rails,sapience,grape}/.resultset.json"
|
|
26
|
+
json_files = Dir[File.join(coverage_dir, coverage_file_pattern)]
|
|
27
|
+
|
|
28
|
+
merged_hash = {}
|
|
29
|
+
json_files.each do |json_file|
|
|
30
|
+
content = File.read(json_file)
|
|
31
|
+
content.gsub!(%r{\/usr\/src\/app}, Dir.pwd) # not inside docker anymore
|
|
32
|
+
JSON.parse(content).each do |command_name, data|
|
|
33
|
+
puts "#{json_file} –> '#{command_name}'"
|
|
34
|
+
merged_hash = SimpleCov::Result.from_hash(command_name => data).original_result.merge_resultset(merged_hash)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
merged_result = SimpleCov::Result.new(merged_hash)
|
|
39
|
+
result_file = File.join(coverage_dir, ".resultset.json")
|
|
40
|
+
FileUtils.rm result_file if File.exist?(result_file)
|
|
41
|
+
File.write(result_file, merged_result.to_hash.to_json)
|
|
42
|
+
|
|
43
|
+
SimpleCov.coverage_dir coverage_dir
|
|
44
|
+
[SimpleCov::Formatter::JSONFormatter, SimpleCov::Formatter::HTMLFormatter].each do |formatter|
|
|
45
|
+
formatter.new.format(merged_result)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
unhide_coverage_config
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
task :send do
|
|
52
|
+
hide_coverage_config
|
|
53
|
+
require "json"
|
|
54
|
+
require "codeclimate-test-reporter"
|
|
55
|
+
CodeClimate::TestReporter.configure do |config|
|
|
56
|
+
config.branch = "master"
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
require "code_climate/test_reporter/ci" if ENV["CI"]
|
|
60
|
+
ENV["CODECLIMATE_REPO_TOKEN"] = "204dc055302da6aed94379e249aa0645636d1d1794920c62db05c5fa968215de"
|
|
61
|
+
resultset_file = File.join(coverage_dir, ".resultset.json")
|
|
62
|
+
result_hash = JSON.parse(File.read(resultset_file))
|
|
63
|
+
simplecov_result = SimpleCov::Result.from_hash(result_hash)
|
|
64
|
+
|
|
65
|
+
CodeClimate::TestReporter::Formatter.new.format(simplecov_result)
|
|
66
|
+
unhide_coverage_config
|
|
67
|
+
end
|
|
68
|
+
end
|
|
File without changes
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require "simplecov-json"
|
|
2
|
+
|
|
3
|
+
coverage_dir = '../../coverage/grape'
|
|
4
|
+
FileUtils.rm_rf coverage_dir
|
|
5
|
+
|
|
6
|
+
SimpleCov.coverage_dir coverage_dir
|
|
7
|
+
SimpleCov.command_name "grape"
|
|
8
|
+
SimpleCov.maximum_coverage_drop 1
|
|
9
|
+
SimpleCov.formatters = [
|
|
10
|
+
SimpleCov::Formatter::HTMLFormatter,
|
|
11
|
+
SimpleCov::Formatter::JSONFormatter,
|
|
12
|
+
]
|
|
13
|
+
SimpleCov.start do
|
|
14
|
+
profiles.delete(:root_filter)
|
|
15
|
+
filters.clear
|
|
16
|
+
add_filter do |src|
|
|
17
|
+
if src.filename =~ %r{sapience\-rb|\/usr\/src\/app/}
|
|
18
|
+
src.filename.include?("test_apps/grape")
|
|
19
|
+
else
|
|
20
|
+
true
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
add_group "Sapience", "../"
|
|
25
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
source "https://rubygems.org"
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
|
|
5
|
+
gem "grape"
|
|
6
|
+
# Use Puma as the app server
|
|
7
|
+
gem "puma", "~> 3.0"
|
|
8
|
+
|
|
9
|
+
# Use Capistrano for deployment
|
|
10
|
+
# gem 'capistrano-rails', group: :development
|
|
11
|
+
gem "sapience", path: "../.."
|
|
12
|
+
gem "sentry-raven"
|
|
13
|
+
gem "statsd-ruby"
|
|
14
|
+
gem "active_model_serializers"
|
|
15
|
+
|
|
16
|
+
group :development, :test do
|
|
17
|
+
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
|
|
18
|
+
gem "byebug", platform: :mri
|
|
19
|
+
# gem "pry-nav"
|
|
20
|
+
gem "pry-byebug", platform: :mri
|
|
21
|
+
gem "rspec"
|
|
22
|
+
gem "racksh"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
group :test do
|
|
26
|
+
gem "rspec-its"
|
|
27
|
+
gem "simplecov"
|
|
28
|
+
gem "simplecov-json"
|
|
29
|
+
gem "fuubar"
|
|
30
|
+
end
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
|
2
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
|
3
|
+
require_relative "lib/ping"
|
|
4
|
+
|
|
5
|
+
require "rspec/core/rake_task"
|
|
6
|
+
RSpec::Core::RakeTask.new(:spec)
|
|
7
|
+
|
|
8
|
+
task default: [:spec]
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require "grape"
|
|
2
|
+
require "grape/api"
|
|
3
|
+
require "sapience/grape"
|
|
4
|
+
|
|
5
|
+
module Ping
|
|
6
|
+
class API < ::Grape::API
|
|
7
|
+
format :json
|
|
8
|
+
use Sapience::Extensions::Grape::Middleware::Logging, logger: Grape::API.logger
|
|
9
|
+
prefix :api
|
|
10
|
+
|
|
11
|
+
desc "Returns pong."
|
|
12
|
+
get :ping do
|
|
13
|
+
{ ping: "PONG" }
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe Ping::API do
|
|
4
|
+
include Rack::Test::Methods
|
|
5
|
+
|
|
6
|
+
def app
|
|
7
|
+
Ping::API
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
context "GET /api/ping" do
|
|
11
|
+
let(:logger) { Grape::API.logger }
|
|
12
|
+
|
|
13
|
+
specify do
|
|
14
|
+
get "/api/ping"
|
|
15
|
+
expect(last_response.body).to match(/PONG/)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "logs something" do
|
|
19
|
+
expect(logger).to receive(:info).with(
|
|
20
|
+
method: "GET",
|
|
21
|
+
request_path: "/api/ping",
|
|
22
|
+
format: "json",
|
|
23
|
+
status: 200,
|
|
24
|
+
class_name: "Ping::API",
|
|
25
|
+
action: "index",
|
|
26
|
+
host: "example.org",
|
|
27
|
+
ip: "127.0.0.1",
|
|
28
|
+
ua: nil,
|
|
29
|
+
tags: [],
|
|
30
|
+
params: {},
|
|
31
|
+
runtimes: a_hash_including(
|
|
32
|
+
total: kind_of(Float),
|
|
33
|
+
view: kind_of(Float),
|
|
34
|
+
db: kind_of(Float),
|
|
35
|
+
),
|
|
36
|
+
)
|
|
37
|
+
get "/api/ping"
|
|
38
|
+
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require "simplecov"
|
|
2
|
+
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
|
|
3
|
+
require "sapience/grape"
|
|
4
|
+
require "rspec/its"
|
|
5
|
+
require "ping"
|
|
6
|
+
|
|
7
|
+
RSpec.configure do |config|
|
|
8
|
+
config.expect_with :rspec do |expectations|
|
|
9
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
config.mock_with :rspec do |mocks|
|
|
13
|
+
mocks.verify_partial_doubles = true
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
|
17
|
+
config.filter_run_when_matching :focus
|
|
18
|
+
config.example_status_persistence_file_path = "spec/examples.txt"
|
|
19
|
+
config.default_formatter = "doc" if config.files_to_run.one?
|
|
20
|
+
config.order = :random
|
|
21
|
+
Kernel.srand config.seed
|
|
22
|
+
config.before(:each) do
|
|
23
|
+
Sapience.reset!
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
*.rbc
|
|
2
|
+
capybara-*.html
|
|
3
|
+
.rspec
|
|
4
|
+
/log
|
|
5
|
+
/tmp
|
|
6
|
+
/db/*.sqlite3
|
|
7
|
+
/db/*.sqlite3-journal
|
|
8
|
+
/public/system
|
|
9
|
+
/coverage/
|
|
10
|
+
/spec/tmp
|
|
11
|
+
**.orig
|
|
12
|
+
rerun.txt
|
|
13
|
+
pickle-email-*.html
|
|
14
|
+
|
|
15
|
+
# dotenv
|
|
16
|
+
# TODO Comment out this rule if environment variables can be committed
|
|
17
|
+
.env
|
|
18
|
+
|
|
19
|
+
## Environment normalization:
|
|
20
|
+
/.bundle
|
|
21
|
+
/vendor/bundle
|
|
22
|
+
|
|
23
|
+
# these should all be checked in to normalize the environment:
|
|
24
|
+
# Gemfile.lock, .ruby-version, .ruby-gemset
|
|
25
|
+
|
|
26
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
|
27
|
+
.rvmrc
|
|
28
|
+
|
|
29
|
+
# if using bower-rails ignore default bower_components path bower.json files
|
|
30
|
+
/vendor/assets/bower_components
|
|
31
|
+
*.bowerrc
|
|
32
|
+
bower.json
|
|
33
|
+
|
|
34
|
+
# Ignore pow environment settings
|
|
35
|
+
.powenv
|
|
36
|
+
|
|
37
|
+
# Ignore Byebug command history file.
|
|
38
|
+
.byebug_history
|
|
File without changes
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require "simplecov-json"
|
|
2
|
+
|
|
3
|
+
coverage_dir = '../../coverage/rails'
|
|
4
|
+
FileUtils.rm_rf coverage_dir
|
|
5
|
+
|
|
6
|
+
SimpleCov.coverage_dir coverage_dir
|
|
7
|
+
SimpleCov.command_name "rails"
|
|
8
|
+
SimpleCov.maximum_coverage_drop 1
|
|
9
|
+
SimpleCov.formatters = [
|
|
10
|
+
SimpleCov::Formatter::HTMLFormatter,
|
|
11
|
+
SimpleCov::Formatter::JSONFormatter,
|
|
12
|
+
]
|
|
13
|
+
SimpleCov.start do
|
|
14
|
+
profiles.delete(:root_filter)
|
|
15
|
+
filters.clear
|
|
16
|
+
add_filter do |src|
|
|
17
|
+
if src.filename =~ %r{sapience\-rb|\/usr\/src\/app/}
|
|
18
|
+
src.filename.include?("test_apps/rails")
|
|
19
|
+
else
|
|
20
|
+
true
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
add_group "Sapience", "../"
|
|
25
|
+
end
|
|
@@ -14,18 +14,18 @@ gem "puma", "~> 3.0"
|
|
|
14
14
|
|
|
15
15
|
# Use Capistrano for deployment
|
|
16
16
|
# gem 'capistrano-rails', group: :development
|
|
17
|
-
gem "sapience", path: "
|
|
17
|
+
gem "sapience", path: "../..", require: "sapience/rails"
|
|
18
18
|
gem "sentry-raven"
|
|
19
19
|
gem "statsd-ruby"
|
|
20
|
+
gem "active_model_serializers"
|
|
20
21
|
gem "sneakers"
|
|
21
22
|
gem "slim-rails"
|
|
22
|
-
gem "active_model_serializers"
|
|
23
23
|
|
|
24
24
|
group :development, :test do
|
|
25
25
|
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
|
|
26
26
|
gem "byebug", platform: :mri
|
|
27
27
|
# gem "pry-nav"
|
|
28
|
-
gem "pry-byebug"
|
|
28
|
+
gem "pry-byebug", platform: :mri
|
|
29
29
|
gem "rspec-rails"
|
|
30
30
|
gem "factory_girl_rails"
|
|
31
31
|
end
|
|
@@ -38,9 +38,9 @@ end
|
|
|
38
38
|
|
|
39
39
|
group :test do
|
|
40
40
|
gem "rspec-its"
|
|
41
|
-
gem "bunny-mock"
|
|
42
|
-
gem "rspec-wait"
|
|
43
41
|
gem "rails-controller-testing"
|
|
42
|
+
gem "simplecov"
|
|
43
|
+
gem "simplecov-json"
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|