startback 0.7.3 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2d65380f7ea4b39a35b08380ac7ed9a87631fb5c01245f32a028a923abebc59b
4
- data.tar.gz: 5b056e6070ddc12cd91b4becd0a391c14a16f0e6838248ca18f2b85b920c9510
3
+ metadata.gz: 9b347e51559a1cc815fd5ce01c77cd3acaf4cbcae59f2b037cd01ff083eb9a18
4
+ data.tar.gz: 1a74994268d32e7f795af8c3cf39e039119a5824081bb9ff1bacda1762bff5d5
5
5
  SHA512:
6
- metadata.gz: bc045c79fed04af08a3be350d5b946f6718b6d4dc97a3c2dbe8efd36bf337562ba146120f4e801dccbe5143e50e9fbdb1eb610cd46716b3b8b72afa8994d670a
7
- data.tar.gz: 1733c1c0e2cd88c9f2bbd40fc095e3a324505e52f8552353e3611a1621674261afd2d1a08143f48416b65278ec7c4ef6339e53fac9be83c0a1134536c63406b2
6
+ metadata.gz: 9047b0a83951b21911cf9310527899c15e99d974f44bccb7dbaa69fba8c2f4fcb048143b904addeaf9ac65c176c1f955d1f9c76ff0e4bf5f39138d792678b7c6
7
+ data.tar.gz: ce4ab603961bf77992820847b144495193e02c149a3d1bb07570b1802c0cdec2feb5a30b06854b330d81a6025b96daef0d7f64a14d5f6fe5684f68699e73e521
data/lib/startback.rb CHANGED
@@ -5,6 +5,7 @@ require 'logger'
5
5
  require 'path'
6
6
  require 'ostruct'
7
7
  require 'benchmark'
8
+
8
9
  # Provides a reusable backend framework for backend components written
9
10
  # in ruby.
10
11
  #
@@ -27,6 +28,7 @@ module Startback
27
28
  end
28
29
  end
29
30
 
31
+ require_relative 'startback/version'
30
32
  require_relative 'startback/ext'
31
33
  require_relative 'startback/errors'
32
34
  require_relative 'startback/support'
@@ -25,31 +25,62 @@ module Startback
25
25
  class Prometheus
26
26
 
27
27
  def initialize(options = {})
28
+ @prefix = options[:prefix] || "startback"
29
+ @options = options
28
30
  @registry = ::Prometheus::Client.registry
31
+ all_labels = [:operation, :startback_version] + option_labels.keys
29
32
  @errors = @registry.counter(
30
- :operation_errors,
33
+ :"#{prefix}_operation_errors",
31
34
  docstring: 'A counter of operation errors',
32
- labels: [:operation])
35
+ labels: all_labels)
33
36
  @calls = @registry.histogram(
34
- :operation_calls,
37
+ :"#{prefix}_operation_calls",
35
38
  docstring: 'A histogram of operation latency',
36
- labels: [:operation])
39
+ labels: all_labels)
37
40
  end
38
- attr_reader :registry, :calls, :errors
41
+ attr_reader :registry, :calls, :errors, :options, :prefix
39
42
 
40
43
  def call(runner, op)
41
44
  name = op_name(op)
42
45
  result = nil
43
- time = Benchmark.realtime{ result = yield }
44
- @calls.observe(time, labels: { operation: name }) rescue nil
46
+ time = Benchmark.realtime{
47
+ result = yield
48
+ }
49
+ ignore_safely {
50
+ @calls.observe(time, labels: get_labels(name))
51
+ }
45
52
  result
46
53
  rescue => ex
47
- @errors.increment(labels: { operation: name }) rescue nil
54
+ ignore_safely {
55
+ @errors.increment(labels: get_labels(name))
56
+ }
48
57
  raise
49
58
  end
50
59
 
51
60
  protected
52
61
 
62
+ def ignore_safely
63
+ yield
64
+ rescue => ex
65
+ puts ex.class.to_s + "\n" + ex.message + "\n" + ex.backtrace.join("\n")
66
+ nil
67
+ end
68
+
69
+ def get_labels(op_name)
70
+ option_labels.merge({
71
+ operation: op_name,
72
+ startback_version: version
73
+ })
74
+ end
75
+
76
+ def option_labels
77
+ @options[:labels] || {}
78
+ end
79
+
80
+ def version
81
+ Startback::VERSION
82
+ end
83
+
53
84
  def op_name(op)
54
85
  case op
55
86
  when String then op
@@ -1,8 +1,8 @@
1
1
  module Startback
2
2
  module Version
3
3
  MAJOR = 0
4
- MINOR = 7
5
- TINY = 3
4
+ MINOR = 8
5
+ TINY = 1
6
6
  end
7
7
  VERSION = "#{Version::MAJOR}.#{Version::MINOR}.#{Version::TINY}"
8
8
  end
@@ -75,13 +75,24 @@ module Startback
75
75
  elsif entity.respond_to?(:to_dto)
76
76
  ct, body = entity.to_dto(context).to(env['HTTP_ACCEPT'], ct)
77
77
  content_type ct
78
- body
78
+ _serve(body)
79
+ elsif entity.is_a?(Path)
80
+ _serve(entity)
79
81
  else
80
82
  content_type ct || "application/json"
81
83
  entity.to_json
82
84
  end
83
85
  end
84
86
 
87
+ def _serve(body)
88
+ case body
89
+ when Path
90
+ send_file(body)
91
+ else
92
+ body
93
+ end
94
+ end
95
+
85
96
  end # class Api
86
97
  end # module Web
87
98
  end # module Startback
data/spec/rspec-unit.xml CHANGED
@@ -1,102 +1,107 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
- <testsuite name="rspec" tests="96" skipped="0" failures="0" errors="0" time="3.289165" timestamp="2020-12-10T14:27:44+01:00" hostname="Cassiopeia.local">
2
+ <testsuite name="rspec" tests="101" skipped="0" failures="0" errors="0" time="3.196954" timestamp="2021-04-24T09:14:41+02:00" hostname="xpertis">
3
3
  <properties>
4
- <property name="seed" value="3348"/>
4
+ <property name="seed" value="47015"/>
5
5
  </properties>
6
- <testcase classname="spec.unit.audit.test_prometheus" name="Startback::Audit::Prometheus The ideal case runs the operation" file="./spec/unit/audit/test_prometheus.rb" time="0.007001"></testcase>
7
- <testcase classname="spec.unit.audit.test_prometheus" name="Startback::Audit::Prometheus The exceptional case let errors bubble up" file="./spec/unit/audit/test_prometheus.rb" time="0.001250"></testcase>
8
- <testcase classname="spec.unit.audit.test_trailer" name="Startback::Audit::Trailer op_data uses to_trail in priority if provided" file="./spec/unit/audit/test_trailer.rb" time="0.000319"></testcase>
9
- <testcase classname="spec.unit.audit.test_trailer" name="Startback::Audit::Trailer op_data uses input then" file="./spec/unit/audit/test_trailer.rb" time="0.000115"></testcase>
10
- <testcase classname="spec.unit.audit.test_trailer" name="Startback::Audit::Trailer op_data uses request then" file="./spec/unit/audit/test_trailer.rb" time="0.000131"></testcase>
11
- <testcase classname="spec.unit.audit.test_trailer" name="Startback::Audit::Trailer op_data applies default blacklists for security reasons" file="./spec/unit/audit/test_trailer.rb" time="0.000107"></testcase>
12
- <testcase classname="spec.unit.audit.test_trailer" name="Startback::Audit::Trailer op_data applies default blacklists to data arrays too" file="./spec/unit/audit/test_trailer.rb" time="0.000127"></testcase>
13
- <testcase classname="spec.unit.audit.test_trailer" name="Startback::Audit::Trailer op_data uses the stop words provided at construction" file="./spec/unit/audit/test_trailer.rb" time="0.000101"></testcase>
14
- <testcase classname="spec.unit.audit.test_trailer" name="Startback::Audit::Trailer op_context applies default blacklists for security reasons" file="./spec/unit/audit/test_trailer.rb" time="0.000137"></testcase>
15
- <testcase classname="spec.unit.bus.memory.test_async" name="Startback::Bus::Memory allows emiting an receiving" file="./spec/unit/bus/memory/test_async.rb" time="0.000591"></testcase>
16
- <testcase classname="spec.unit.bus.memory.test_async" name="Startback::Bus::Memory allows mixin Symbol vs. String for event type" file="./spec/unit/bus/memory/test_async.rb" time="0.000075"></testcase>
17
- <testcase classname="spec.unit.bus.memory.test_async" name="Startback::Bus::Memory does not raise errors synchronously" file="./spec/unit/bus/memory/test_async.rb" time="0.000701"></testcase>
18
- <testcase classname="spec.unit.bus.memory.test_sync" name="Startback::Bus::Memory allows emiting an receiving" file="./spec/unit/bus/memory/test_sync.rb" time="0.000078"></testcase>
19
- <testcase classname="spec.unit.bus.memory.test_sync" name="Startback::Bus::Memory allows mixin Symbol vs. String for event type" file="./spec/unit/bus/memory/test_sync.rb" time="0.000078"></testcase>
20
- <testcase classname="spec.unit.bus.memory.test_sync" name="Startback::Bus::Memory raises emit errors synchronously" file="./spec/unit/bus/memory/test_sync.rb" time="0.000082"></testcase>
21
- <testcase classname="spec.unit.caching.test_entity_cache" name="Startback::Caching::EntityCache default_ttl has a default ttl of one hour" file="./spec/unit/caching/test_entity_cache.rb" time="0.000049"></testcase>
22
- <testcase classname="spec.unit.caching.test_entity_cache" name="Startback::Caching::EntityCache default_ttl allows overriding it" file="./spec/unit/caching/test_entity_cache.rb" time="0.000068"></testcase>
23
- <testcase classname="spec.unit.caching.test_entity_cache" name="Startback::Caching::EntityCache default_ttl is accessible as default_caching_options on the instance" file="./spec/unit/caching/test_entity_cache.rb" time="0.000050"></testcase>
24
- <testcase classname="spec.unit.caching.test_entity_cache" name="Startback::Caching::EntityCache get yields to load_raw_data only once with the short key" file="./spec/unit/caching/test_entity_cache.rb" time="0.000106"></testcase>
6
+ <testcase classname="spec.unit.audit.test_prometheus" name="Startback::Audit::Prometheus The ideal case runs the operation" file="./spec/unit/audit/test_prometheus.rb" time="0.003781"></testcase>
7
+ <testcase classname="spec.unit.audit.test_prometheus" name="Startback::Audit::Prometheus The exceptional case let errors bubble up" file="./spec/unit/audit/test_prometheus.rb" time="0.001005"></testcase>
8
+ <testcase classname="spec.unit.audit.test_trailer" name="Startback::Audit::Trailer op_data uses to_trail in priority if provided" file="./spec/unit/audit/test_trailer.rb" time="0.000148"></testcase>
9
+ <testcase classname="spec.unit.audit.test_trailer" name="Startback::Audit::Trailer op_data uses input then" file="./spec/unit/audit/test_trailer.rb" time="0.000649"></testcase>
10
+ <testcase classname="spec.unit.audit.test_trailer" name="Startback::Audit::Trailer op_data uses request then" file="./spec/unit/audit/test_trailer.rb" time="0.000105"></testcase>
11
+ <testcase classname="spec.unit.audit.test_trailer" name="Startback::Audit::Trailer op_data applies default blacklists for security reasons" file="./spec/unit/audit/test_trailer.rb" time="0.000154"></testcase>
12
+ <testcase classname="spec.unit.audit.test_trailer" name="Startback::Audit::Trailer op_data applies default blacklists to data arrays too" file="./spec/unit/audit/test_trailer.rb" time="0.000120"></testcase>
13
+ <testcase classname="spec.unit.audit.test_trailer" name="Startback::Audit::Trailer op_data uses the stop words provided at construction" file="./spec/unit/audit/test_trailer.rb" time="0.000099"></testcase>
14
+ <testcase classname="spec.unit.audit.test_trailer" name="Startback::Audit::Trailer op_context applies default blacklists for security reasons" file="./spec/unit/audit/test_trailer.rb" time="0.000713"></testcase>
15
+ <testcase classname="spec.unit.bus.memory.test_async" name="Startback::Bus::Memory allows emiting an receiving" file="./spec/unit/bus/memory/test_async.rb" time="0.000327"></testcase>
16
+ <testcase classname="spec.unit.bus.memory.test_async" name="Startback::Bus::Memory allows mixin Symbol vs. String for event type" file="./spec/unit/bus/memory/test_async.rb" time="0.000070"></testcase>
17
+ <testcase classname="spec.unit.bus.memory.test_async" name="Startback::Bus::Memory does not raise errors synchronously" file="./spec/unit/bus/memory/test_async.rb" time="0.000842"></testcase>
18
+ <testcase classname="spec.unit.bus.memory.test_sync" name="Startback::Bus::Memory allows emiting an receiving" file="./spec/unit/bus/memory/test_sync.rb" time="0.000067"></testcase>
19
+ <testcase classname="spec.unit.bus.memory.test_sync" name="Startback::Bus::Memory allows mixin Symbol vs. String for event type" file="./spec/unit/bus/memory/test_sync.rb" time="0.000058"></testcase>
20
+ <testcase classname="spec.unit.bus.memory.test_sync" name="Startback::Bus::Memory raises emit errors synchronously" file="./spec/unit/bus/memory/test_sync.rb" time="0.000065"></testcase>
21
+ <testcase classname="spec.unit.caching.test_entity_cache" name="Startback::Caching::EntityCache default_ttl has a default ttl of one hour" file="./spec/unit/caching/test_entity_cache.rb" time="0.000052"></testcase>
22
+ <testcase classname="spec.unit.caching.test_entity_cache" name="Startback::Caching::EntityCache default_ttl allows overriding it" file="./spec/unit/caching/test_entity_cache.rb" time="0.000043"></testcase>
23
+ <testcase classname="spec.unit.caching.test_entity_cache" name="Startback::Caching::EntityCache default_ttl is accessible as default_caching_options on the instance" file="./spec/unit/caching/test_entity_cache.rb" time="0.000051"></testcase>
24
+ <testcase classname="spec.unit.caching.test_entity_cache" name="Startback::Caching::EntityCache get yields to load_raw_data only once with the short key" file="./spec/unit/caching/test_entity_cache.rb" time="0.000614"></testcase>
25
25
  <testcase classname="spec.unit.caching.test_entity_cache" name="Startback::Caching::EntityCache primary_key allows using candidate keys" file="./spec/unit/caching/test_entity_cache.rb" time="0.000095"></testcase>
26
- <testcase classname="spec.unit.caching.test_entity_cache" name="Startback::Caching::EntityCache invalidate strips the key on the store, yielding a cache miss" file="./spec/unit/caching/test_entity_cache.rb" time="0.000109"></testcase>
27
- <testcase classname="spec.unit.caching.test_entity_cache" name="Startback::Caching::EntityCache valid? override yields to load_raw_data only once with the extend key" file="./spec/unit/caching/test_entity_cache.rb" time="0.000127"></testcase>
28
- <testcase classname="spec.unit.context.test_abstraction_factory" name="Startback::Context factor is a factory for other context-related abstractions" file="./spec/unit/context/test_abstraction_factory.rb" time="0.000851"></testcase>
29
- <testcase classname="spec.unit.context.test_abstraction_factory" name="Startback::Context factor is takes cares of abstraction arguments" file="./spec/unit/context/test_abstraction_factory.rb" time="0.000088"></testcase>
30
- <testcase classname="spec.unit.context.test_abstraction_factory" name="Startback::Context factor is caches even in presence ofabstraction arguments" file="./spec/unit/context/test_abstraction_factory.rb" time="0.000054"></testcase>
31
- <testcase classname="spec.unit.context.test_abstraction_factory" name="Startback::Context factor is distinguishes different abstraction arguments" file="./spec/unit/context/test_abstraction_factory.rb" time="0.000053"></testcase>
32
- <testcase classname="spec.unit.context.test_dup" name="Startback::Context dup yields a dup of the original context" file="./spec/unit/context/test_dup.rb" time="0.000085"></testcase>
33
- <testcase classname="spec.unit.context.test_dup" name="Startback::Context dup cleans all factored cache" file="./spec/unit/context/test_dup.rb" time="0.000053"></testcase>
34
- <testcase classname="spec.unit.context.test_h_factory" name="Startback::Context h information contract has a to_json that dumps it" file="./spec/unit/context/test_h_factory.rb" time="0.000045"></testcase>
35
- <testcase classname="spec.unit.context.test_h_factory" name="Startback::Context h information contract allows installing factories" file="./spec/unit/context/test_h_factory.rb" time="0.001958"></testcase>
36
- <testcase classname="spec.unit.context.test_h_factory" name="Startback::Context h information contract has a `to_h` information contract that works as expected" file="./spec/unit/context/test_h_factory.rb" time="0.000092"></testcase>
26
+ <testcase classname="spec.unit.caching.test_entity_cache" name="Startback::Caching::EntityCache invalidate strips the key on the store, yielding a cache miss" file="./spec/unit/caching/test_entity_cache.rb" time="0.000368"></testcase>
27
+ <testcase classname="spec.unit.caching.test_entity_cache" name="Startback::Caching::EntityCache valid? override yields to load_raw_data only once with the extend key" file="./spec/unit/caching/test_entity_cache.rb" time="0.000143"></testcase>
28
+ <testcase classname="spec.unit.context.test_abstraction_factory" name="Startback::Context factor is a factory for other context-related abstractions" file="./spec/unit/context/test_abstraction_factory.rb" time="0.000929"></testcase>
29
+ <testcase classname="spec.unit.context.test_abstraction_factory" name="Startback::Context factor is takes cares of abstraction arguments" file="./spec/unit/context/test_abstraction_factory.rb" time="0.000102"></testcase>
30
+ <testcase classname="spec.unit.context.test_abstraction_factory" name="Startback::Context factor is caches even in presence ofabstraction arguments" file="./spec/unit/context/test_abstraction_factory.rb" time="0.000068"></testcase>
31
+ <testcase classname="spec.unit.context.test_abstraction_factory" name="Startback::Context factor is distinguishes different abstraction arguments" file="./spec/unit/context/test_abstraction_factory.rb" time="0.000058"></testcase>
32
+ <testcase classname="spec.unit.context.test_dup" name="Startback::Context dup yields a dup of the original context" file="./spec/unit/context/test_dup.rb" time="0.000066"></testcase>
33
+ <testcase classname="spec.unit.context.test_dup" name="Startback::Context dup cleans all factored cache" file="./spec/unit/context/test_dup.rb" time="0.000059"></testcase>
34
+ <testcase classname="spec.unit.context.test_h_factory" name="Startback::Context h information contract has a to_json that dumps it" file="./spec/unit/context/test_h_factory.rb" time="0.000048"></testcase>
35
+ <testcase classname="spec.unit.context.test_h_factory" name="Startback::Context h information contract allows installing factories" file="./spec/unit/context/test_h_factory.rb" time="0.002412"></testcase>
36
+ <testcase classname="spec.unit.context.test_h_factory" name="Startback::Context h information contract has a `to_h` information contract that works as expected" file="./spec/unit/context/test_h_factory.rb" time="0.000059"></testcase>
37
37
  <testcase classname="spec.unit.context.test_h_factory" name="Startback::Context h information contract has a `h` information contract that works as expected" file="./spec/unit/context/test_h_factory.rb" time="0.000053"></testcase>
38
- <testcase classname="spec.unit.context.test_middleware" name="Startback::Context::Middleware when used without option sets the default context class" file="./spec/unit/context/test_middleware.rb" time="0.003862"></testcase>
39
- <testcase classname="spec.unit.context.test_middleware" name="Startback::Context::Middleware when specifying the context class sets the default context class" file="./spec/unit/context/test_middleware.rb" time="0.000190"></testcase>
40
- <testcase classname="spec.unit.support.hooks.test_after_hook" name="Startback::Support::Hooks after_xxx works as expected" file="./spec/unit/support/hooks/test_after_hook.rb" time="0.000053"></testcase>
41
- <testcase classname="spec.unit.support.hooks.test_after_hook" name="Startback::Support::Hooks after_xxx works as expected on subclass" file="./spec/unit/support/hooks/test_after_hook.rb" time="0.000076"></testcase>
42
- <testcase classname="spec.unit.support.hooks.test_before_hook" name="Startback::Support::Hooks before_xxx works as expected" file="./spec/unit/support/hooks/test_before_hook.rb" time="0.000047"></testcase>
43
- <testcase classname="spec.unit.support.hooks.test_before_hook" name="Startback::Support::Hooks before_xxx works as expected on subclass" file="./spec/unit/support/hooks/test_before_hook.rb" time="0.000047"></testcase>
44
- <testcase classname="spec.unit.support.operation_runner.test_around_run" name="Startback::Support::OperationRunner around_run the simplest contract lets run an operation with world bound" file="./spec/unit/support/operation_runner/test_around_run.rb" time="0.000063"></testcase>
45
- <testcase classname="spec.unit.support.operation_runner.test_around_run" name="Startback::Support::OperationRunner around_run the around feature calls the around before the operation itself" file="./spec/unit/support/operation_runner/test_around_run.rb" time="0.000066"></testcase>
46
- <testcase classname="spec.unit.support.operation_runner.test_around_run" name="Startback::Support::OperationRunner around_run the around feature with a class calls the proc with expected parameters" file="./spec/unit/support/operation_runner/test_around_run.rb" time="0.000060"></testcase>
47
- <testcase classname="spec.unit.support.operation_runner.test_around_run" name="Startback::Support::OperationRunner around_run the around feature with a subclass executes all hooks" file="./spec/unit/support/operation_runner/test_around_run.rb" time="0.000066"></testcase>
48
- <testcase classname="spec.unit.support.operation_runner.test_before_after_call" name="Startback::Support::OperationRunner before_call runs before the around hooks" file="./spec/unit/support/operation_runner/test_before_after_call.rb" time="0.000058"></testcase>
49
- <testcase classname="spec.unit.support.test_robusteness" name="Startback::Support::Robustness monitor works" file="./spec/unit/support/test_robusteness.rb" time="0.000087"></testcase>
50
- <testcase classname="spec.unit.support.test_robusteness" name="Startback::Support::Robustness stop_errors works and logs the error" file="./spec/unit/support/test_robusteness.rb" time="0.000076"></testcase>
51
- <testcase classname="spec.unit.support.test_robusteness" name="Startback::Support::Robustness stop_errors returns the result if no error" file="./spec/unit/support/test_robusteness.rb" time="0.000081"></testcase>
52
- <testcase classname="spec.unit.support.test_robusteness" name="Startback::Support::Robustness try_max_times fails if n errors are seen" file="./spec/unit/support/test_robusteness.rb" time="1.004719"></testcase>
53
- <testcase classname="spec.unit.support.test_robusteness" name="Startback::Support::Robustness try_max_times suceeds if an attemps succeeds" file="./spec/unit/support/test_robusteness.rb" time="1.004261"></testcase>
54
- <testcase classname="spec.unit.support.test_robusteness" name="Startback::Support::Robustness try_max_times suceeds if first attemps succeeds" file="./spec/unit/support/test_robusteness.rb" time="0.000095"></testcase>
55
- <testcase classname="spec.unit.support.test_robusteness" name="Startback::Support::Robustness parse_args works fine with full op and no context" file="./spec/unit/support/test_robusteness.rb" time="0.000059"></testcase>
56
- <testcase classname="spec.unit.support.test_robusteness" name="Startback::Support::Robustness parse_args works fine with an string and a method name" file="./spec/unit/support/test_robusteness.rb" time="0.000071"></testcase>
57
- <testcase classname="spec.unit.support.test_robusteness" name="Startback::Support::Robustness parse_args works fine with an string, a method name, and a message" file="./spec/unit/support/test_robusteness.rb" time="0.000046"></testcase>
58
- <testcase classname="spec.unit.support.test_robusteness" name="Startback::Support::Robustness parse_args works fine with a string only" file="./spec/unit/support/test_robusteness.rb" time="0.000044"></testcase>
59
- <testcase classname="spec.unit.support.test_robusteness" name="Startback::Support::Robustness parse_args works fine with a string and a context with logger" file="./spec/unit/support/test_robusteness.rb" time="0.000081"></testcase>
60
- <testcase classname="spec.unit.support.test_robusteness" name="Startback::Support::Robustness parse_args works fine with a string and an extra hash" file="./spec/unit/support/test_robusteness.rb" time="0.000044"></testcase>
61
- <testcase classname="spec.unit.support.test_robusteness" name="Startback::Support::Robustness parse_args works fine with a module and method" file="./spec/unit/support/test_robusteness.rb" time="0.000044"></testcase>
62
- <testcase classname="spec.unit.support.test_robusteness" name="Startback::Support::Robustness parse_args works fine with a class and method" file="./spec/unit/support/test_robusteness.rb" time="0.000076"></testcase>
63
- <testcase classname="spec.unit.support.test_robusteness" name="Startback::Support::Robustness parse_args works fine with an instance and method" file="./spec/unit/support/test_robusteness.rb" time="0.000048"></testcase>
64
- <testcase classname="spec.unit.support.test_robusteness" name="Startback::Support::Robustness parse_args when a hash is passed as last arg" file="./spec/unit/support/test_robusteness.rb" time="0.000045"></testcase>
65
- <testcase classname="spec.unit.support.test_robusteness" name="Startback::Support::Robustness logger_for works on a logger" file="./spec/unit/support/test_robusteness.rb" time="0.000048"></testcase>
66
- <testcase classname="spec.unit.support.test_robusteness" name="Startback::Support::Robustness logger_for works on a Context responding to logger" file="./spec/unit/support/test_robusteness.rb" time="0.000044"></testcase>
67
- <testcase classname="spec.unit.support.test_robusteness" name="Startback::Support::Robustness logger_for works on an object having a Context responding to logger" file="./spec/unit/support/test_robusteness.rb" time="0.000063"></testcase>
68
- <testcase classname="spec.unit.support.test_robusteness" name="Startback::Support::Robustness logger_for works on an object having a Context but no logger" file="./spec/unit/support/test_robusteness.rb" time="0.000087"></testcase>
69
- <testcase classname="spec.unit.test_event" name="Startback::Event presents an ostruct on top of its data" file="./spec/unit/test_event.rb" time="0.000055"></testcase>
70
- <testcase classname="spec.unit.test_event" name="Startback::Event the json information contract has a to_json method that works as expected" file="./spec/unit/test_event.rb" time="0.000080"></testcase>
71
- <testcase classname="spec.unit.test_event" name="Startback::Event the json information contract has a to_json that dumps the context if any" file="./spec/unit/test_event.rb" time="0.000055"></testcase>
72
- <testcase classname="spec.unit.test_event" name="Startback::Event the json information contract has a json class method that works as expected" file="./spec/unit/test_event.rb" time="0.000086"></testcase>
73
- <testcase classname="spec.unit.test_event" name="Startback::Event the json information contract accepts an explicit context in the world" file="./spec/unit/test_event.rb" time="0.000048"></testcase>
74
- <testcase classname="spec.unit.test_event" name="Startback::Event the json information contract accepts an context factory in the world" file="./spec/unit/test_event.rb" time="0.000054"></testcase>
75
- <testcase classname="spec.unit.test_operation" name="Startback::Operation can be bound, which returns a new operation" file="./spec/unit/test_operation.rb" time="0.000046"></testcase>
76
- <testcase classname="spec.unit.test_operation" name="Startback::Operation::MultiOperation lets chain with +" file="./spec/unit/test_operation.rb" time="0.000051"></testcase>
77
- <testcase classname="spec.unit.test_operation" name="Startback::Operation::MultiOperation calls and collects the result on call" file="./spec/unit/test_operation.rb" time="0.000043"></testcase>
78
- <testcase classname="spec.unit.test_operation" name="Startback::Operation::MultiOperation binds every sub operation recursively" file="./spec/unit/test_operation.rb" time="0.000042"></testcase>
79
- <testcase classname="spec.unit.test_support" name="Startback::Support deep_merge works as expected" file="./spec/unit/test_support.rb" time="0.000048"></testcase>
80
- <testcase classname="spec.unit.web.test_auto_caching" name="Startback::Web::AutoCaching when used without options sets the development Cache-Control since this is a test" file="./spec/unit/web/test_auto_caching.rb" time="0.000202"></testcase>
81
- <testcase classname="spec.unit.web.test_auto_caching" name="Startback::Web::AutoCaching when forcing production sets the production Cache-Control" file="./spec/unit/web/test_auto_caching.rb" time="0.000145"></testcase>
82
- <testcase classname="spec.unit.web.test_auto_caching" name="Startback::Web::AutoCaching when forcing development headers sets the production Cache-Control" file="./spec/unit/web/test_auto_caching.rb" time="0.000148"></testcase>
83
- <testcase classname="spec.unit.web.test_auto_caching" name="Startback::Web::AutoCaching when setting the Cache-Control header only sets the production Cache-Control" file="./spec/unit/web/test_auto_caching.rb" time="0.000142"></testcase>
84
- <testcase classname="spec.unit.web.test_auto_caching" name="Startback::Web::AutoCaching when a Cache-Control header is already set by the app sets the production Cache-Control" file="./spec/unit/web/test_auto_caching.rb" time="0.000117"></testcase>
85
- <testcase classname="spec.unit.web.test_catch_all" name="Startback::Web::CatchAll when used without context returns a 500 with json explanation" file="./spec/unit/web/test_catch_all.rb" time="0.000403"></testcase>
38
+ <testcase classname="spec.unit.context.test_middleware" name="Startback::Context::Middleware when used without option sets the default context class" file="./spec/unit/context/test_middleware.rb" time="0.005282"></testcase>
39
+ <testcase classname="spec.unit.context.test_middleware" name="Startback::Context::Middleware when specifying the context class sets the default context class" file="./spec/unit/context/test_middleware.rb" time="0.000778"></testcase>
40
+ <testcase classname="spec.unit.support.hooks.test_after_hook" name="Startback::Support::Hooks after_xxx works as expected" file="./spec/unit/support/hooks/test_after_hook.rb" time="0.000056"></testcase>
41
+ <testcase classname="spec.unit.support.hooks.test_after_hook" name="Startback::Support::Hooks after_xxx works as expected on subclass" file="./spec/unit/support/hooks/test_after_hook.rb" time="0.000053"></testcase>
42
+ <testcase classname="spec.unit.support.hooks.test_before_hook" name="Startback::Support::Hooks before_xxx works as expected" file="./spec/unit/support/hooks/test_before_hook.rb" time="0.000050"></testcase>
43
+ <testcase classname="spec.unit.support.hooks.test_before_hook" name="Startback::Support::Hooks before_xxx works as expected on subclass" file="./spec/unit/support/hooks/test_before_hook.rb" time="0.000049"></testcase>
44
+ <testcase classname="spec.unit.support.operation_runner.test_around_run" name="Startback::Support::OperationRunner around_run the simplest contract lets run an operation with world bound" file="./spec/unit/support/operation_runner/test_around_run.rb" time="0.000070"></testcase>
45
+ <testcase classname="spec.unit.support.operation_runner.test_around_run" name="Startback::Support::OperationRunner around_run the around feature calls the around before the operation itself" file="./spec/unit/support/operation_runner/test_around_run.rb" time="0.000065"></testcase>
46
+ <testcase classname="spec.unit.support.operation_runner.test_around_run" name="Startback::Support::OperationRunner around_run the around feature with a class calls the proc with expected parameters" file="./spec/unit/support/operation_runner/test_around_run.rb" time="0.000504"></testcase>
47
+ <testcase classname="spec.unit.support.operation_runner.test_around_run" name="Startback::Support::OperationRunner around_run the around feature with a subclass executes all hooks" file="./spec/unit/support/operation_runner/test_around_run.rb" time="0.000073"></testcase>
48
+ <testcase classname="spec.unit.support.operation_runner.test_before_after_call" name="Startback::Support::OperationRunner before_call runs before the around hooks" file="./spec/unit/support/operation_runner/test_before_after_call.rb" time="0.000061"></testcase>
49
+ <testcase classname="spec.unit.support.test_robusteness" name="Startback::Support::Robustness monitor works" file="./spec/unit/support/test_robusteness.rb" time="0.000590"></testcase>
50
+ <testcase classname="spec.unit.support.test_robusteness" name="Startback::Support::Robustness stop_errors works and logs the error" file="./spec/unit/support/test_robusteness.rb" time="0.000094"></testcase>
51
+ <testcase classname="spec.unit.support.test_robusteness" name="Startback::Support::Robustness stop_errors returns the result if no error" file="./spec/unit/support/test_robusteness.rb" time="0.000123"></testcase>
52
+ <testcase classname="spec.unit.support.test_robusteness" name="Startback::Support::Robustness try_max_times fails if n errors are seen" file="./spec/unit/support/test_robusteness.rb" time="1.001608"></testcase>
53
+ <testcase classname="spec.unit.support.test_robusteness" name="Startback::Support::Robustness try_max_times suceeds if an attemps succeeds" file="./spec/unit/support/test_robusteness.rb" time="1.001888"></testcase>
54
+ <testcase classname="spec.unit.support.test_robusteness" name="Startback::Support::Robustness try_max_times suceeds if first attemps succeeds" file="./spec/unit/support/test_robusteness.rb" time="0.000360"></testcase>
55
+ <testcase classname="spec.unit.support.test_robusteness" name="Startback::Support::Robustness parse_args works fine with full op and no context" file="./spec/unit/support/test_robusteness.rb" time="0.000259"></testcase>
56
+ <testcase classname="spec.unit.support.test_robusteness" name="Startback::Support::Robustness parse_args works fine with an string and a method name" file="./spec/unit/support/test_robusteness.rb" time="0.000225"></testcase>
57
+ <testcase classname="spec.unit.support.test_robusteness" name="Startback::Support::Robustness parse_args works fine with an string, a method name, and a message" file="./spec/unit/support/test_robusteness.rb" time="0.000262"></testcase>
58
+ <testcase classname="spec.unit.support.test_robusteness" name="Startback::Support::Robustness parse_args works fine with a string only" file="./spec/unit/support/test_robusteness.rb" time="0.000250"></testcase>
59
+ <testcase classname="spec.unit.support.test_robusteness" name="Startback::Support::Robustness parse_args works fine with a string and a context with logger" file="./spec/unit/support/test_robusteness.rb" time="0.000253"></testcase>
60
+ <testcase classname="spec.unit.support.test_robusteness" name="Startback::Support::Robustness parse_args works fine with a string and an extra hash" file="./spec/unit/support/test_robusteness.rb" time="0.000214"></testcase>
61
+ <testcase classname="spec.unit.support.test_robusteness" name="Startback::Support::Robustness parse_args works fine with a module and method" file="./spec/unit/support/test_robusteness.rb" time="0.000215"></testcase>
62
+ <testcase classname="spec.unit.support.test_robusteness" name="Startback::Support::Robustness parse_args works fine with a class and method" file="./spec/unit/support/test_robusteness.rb" time="0.000253"></testcase>
63
+ <testcase classname="spec.unit.support.test_robusteness" name="Startback::Support::Robustness parse_args works fine with an instance and method" file="./spec/unit/support/test_robusteness.rb" time="0.000233"></testcase>
64
+ <testcase classname="spec.unit.support.test_robusteness" name="Startback::Support::Robustness parse_args when a hash is passed as last arg" file="./spec/unit/support/test_robusteness.rb" time="0.000598"></testcase>
65
+ <testcase classname="spec.unit.support.test_robusteness" name="Startback::Support::Robustness logger_for works on a logger" file="./spec/unit/support/test_robusteness.rb" time="0.000325"></testcase>
66
+ <testcase classname="spec.unit.support.test_robusteness" name="Startback::Support::Robustness logger_for works on a Context responding to logger" file="./spec/unit/support/test_robusteness.rb" time="0.000309"></testcase>
67
+ <testcase classname="spec.unit.support.test_robusteness" name="Startback::Support::Robustness logger_for works on an object having a Context responding to logger" file="./spec/unit/support/test_robusteness.rb" time="0.001518"></testcase>
68
+ <testcase classname="spec.unit.support.test_robusteness" name="Startback::Support::Robustness logger_for works on an object having a Context but no logger" file="./spec/unit/support/test_robusteness.rb" time="0.000365"></testcase>
69
+ <testcase classname="spec.unit.test_event" name="Startback::Event presents an ostruct on top of its data" file="./spec/unit/test_event.rb" time="0.000282"></testcase>
70
+ <testcase classname="spec.unit.test_event" name="Startback::Event the json information contract has a to_json method that works as expected" file="./spec/unit/test_event.rb" time="0.000385"></testcase>
71
+ <testcase classname="spec.unit.test_event" name="Startback::Event the json information contract has a to_json that dumps the context if any" file="./spec/unit/test_event.rb" time="0.001013"></testcase>
72
+ <testcase classname="spec.unit.test_event" name="Startback::Event the json information contract has a json class method that works as expected" file="./spec/unit/test_event.rb" time="0.000326"></testcase>
73
+ <testcase classname="spec.unit.test_event" name="Startback::Event the json information contract accepts an explicit context in the world" file="./spec/unit/test_event.rb" time="0.000231"></testcase>
74
+ <testcase classname="spec.unit.test_event" name="Startback::Event the json information contract accepts an context factory in the world" file="./spec/unit/test_event.rb" time="0.000258"></testcase>
75
+ <testcase classname="spec.unit.test_operation" name="Startback::Operation can be bound, which returns a new operation" file="./spec/unit/test_operation.rb" time="0.000215"></testcase>
76
+ <testcase classname="spec.unit.test_operation" name="Startback::Operation::MultiOperation lets chain with +" file="./spec/unit/test_operation.rb" time="0.000355"></testcase>
77
+ <testcase classname="spec.unit.test_operation" name="Startback::Operation::MultiOperation calls and collects the result on call" file="./spec/unit/test_operation.rb" time="0.000225"></testcase>
78
+ <testcase classname="spec.unit.test_operation" name="Startback::Operation::MultiOperation binds every sub operation recursively" file="./spec/unit/test_operation.rb" time="0.000210"></testcase>
79
+ <testcase classname="spec.unit.test_support" name="Startback::Support deep_merge works as expected" file="./spec/unit/test_support.rb" time="0.000168"></testcase>
80
+ <testcase classname="spec.unit.web.test_api" name="Startback::Web::Api convert nil to 404" file="./spec/unit/web/test_api.rb" time="0.012897"></testcase>
81
+ <testcase classname="spec.unit.web.test_api" name="Startback::Web::Api supports serving entities" file="./spec/unit/web/test_api.rb" time="0.000273"></testcase>
82
+ <testcase classname="spec.unit.web.test_api" name="Startback::Web::Api supports serving paths" file="./spec/unit/web/test_api.rb" time="0.000406"></testcase>
83
+ <testcase classname="spec.unit.web.test_api" name="Startback::Web::Api supports serving DTO-able objects" file="./spec/unit/web/test_api.rb" time="0.000240"></testcase>
84
+ <testcase classname="spec.unit.web.test_api" name="Startback::Web::Api supports serving DTO-able objects eventually returning paths" file="./spec/unit/web/test_api.rb" time="0.000412"></testcase>
85
+ <testcase classname="spec.unit.web.test_auto_caching" name="Startback::Web::AutoCaching when used without options sets the development Cache-Control since this is a test" file="./spec/unit/web/test_auto_caching.rb" time="0.000144"></testcase>
86
+ <testcase classname="spec.unit.web.test_auto_caching" name="Startback::Web::AutoCaching when forcing production sets the production Cache-Control" file="./spec/unit/web/test_auto_caching.rb" time="0.000127"></testcase>
87
+ <testcase classname="spec.unit.web.test_auto_caching" name="Startback::Web::AutoCaching when forcing development headers sets the production Cache-Control" file="./spec/unit/web/test_auto_caching.rb" time="0.000128"></testcase>
88
+ <testcase classname="spec.unit.web.test_auto_caching" name="Startback::Web::AutoCaching when setting the Cache-Control header only sets the production Cache-Control" file="./spec/unit/web/test_auto_caching.rb" time="0.000125"></testcase>
89
+ <testcase classname="spec.unit.web.test_auto_caching" name="Startback::Web::AutoCaching when a Cache-Control header is already set by the app sets the production Cache-Control" file="./spec/unit/web/test_auto_caching.rb" time="0.000123"></testcase>
90
+ <testcase classname="spec.unit.web.test_catch_all" name="Startback::Web::CatchAll when used without context returns a 500 with json explanation" file="./spec/unit/web/test_catch_all.rb" time="0.000293"></testcase>
86
91
  <testcase classname="spec.unit.web.test_catch_all" name="Startback::Web::CatchAll when used with a context providing an error handler returns a 500 with json explanation" file="./spec/unit/web/test_catch_all.rb" time="0.000194"></testcase>
87
- <testcase classname="spec.unit.web.test_cors_headers" name="Startback::Web::CorsHeaders when used without options sets the CORS headers to default values" file="./spec/unit/web/test_cors_headers.rb" time="0.000163"></testcase>
88
- <testcase classname="spec.unit.web.test_cors_headers" name="Startback::Web::CorsHeaders when used without options strips everything when option" file="./spec/unit/web/test_cors_headers.rb" time="0.000155"></testcase>
89
- <testcase classname="spec.unit.web.test_cors_headers" name="Startback::Web::CorsHeaders when used with the :bounce option sets the CORS Origin header to the caller" file="./spec/unit/web/test_cors_headers.rb" time="0.000197"></testcase>
90
- <testcase classname="spec.unit.web.test_cors_headers" name="Startback::Web::CorsHeaders when overriding a header sets the CORS Origin header to the caller" file="./spec/unit/web/test_cors_headers.rb" time="0.000165"></testcase>
91
- <testcase classname="spec.unit.web.test_cors_headers" name="Startback::Web::CorsHeaders when the app sets specific headers does not override them" file="./spec/unit/web/test_cors_headers.rb" time="0.000149"></testcase>
92
- <testcase classname="spec.unit.web.test_healthcheck" name="Startback::Web::HealthCheck when used without a block and no failure returns a 204 when ok" file="./spec/unit/web/test_healthcheck.rb" time="0.000131"></testcase>
93
- <testcase classname="spec.unit.web.test_healthcheck" name="Startback::Web::HealthCheck when used without a block a failure raises when ko" file="./spec/unit/web/test_healthcheck.rb" time="0.000132"></testcase>
94
- <testcase classname="spec.unit.web.test_healthcheck" name="Startback::Web::HealthCheck when used with a block returning a debug message returns a 200 with plain text message" file="./spec/unit/web/test_healthcheck.rb" time="0.000136"></testcase>
95
- <testcase classname="spec.unit.web.test_healthcheck" name="Startback::Web::HealthCheck when used with a block raising an exception re-raises it" file="./spec/unit/web/test_healthcheck.rb" time="0.000106"></testcase>
96
- <testcase classname="spec.unit.web.test_magic_assets" name="Startback::Web::MagicAssets when used as an app works as expected" file="./spec/unit/web/test_magic_assets.rb" time="0.484773"></testcase>
97
- <testcase classname="spec.unit.web.test_magic_assets" name="Startback::Web::MagicAssets when used as an app delegates a [] call to sprockets" file="./spec/unit/web/test_magic_assets.rb" time="0.254095"></testcase>
98
- <testcase classname="spec.unit.web.test_magic_assets" name="Startback::Web::MagicAssets when used as an app returns a 404 on unknown" file="./spec/unit/web/test_magic_assets.rb" time="0.000667"></testcase>
99
- <testcase classname="spec.unit.web.test_magic_assets" name="Startback::Web::MagicAssets when used as a middleware lets unrelated things pass" file="./spec/unit/web/test_magic_assets.rb" time="0.000389"></testcase>
100
- <testcase classname="spec.unit.web.test_magic_assets" name="Startback::Web::MagicAssets when used as a middleware serves the assets under the chosen path" file="./spec/unit/web/test_magic_assets.rb" time="0.251977"></testcase>
101
- <testcase classname="spec.unit.web.test_magic_assets" name="Startback::Web::MagicAssets when registering the NgHtmlTransformer works as expected" file="./spec/unit/web/test_magic_assets.rb" time="0.252322"></testcase>
92
+ <testcase classname="spec.unit.web.test_cors_headers" name="Startback::Web::CorsHeaders when used without options sets the CORS headers to default values" file="./spec/unit/web/test_cors_headers.rb" time="0.000153"></testcase>
93
+ <testcase classname="spec.unit.web.test_cors_headers" name="Startback::Web::CorsHeaders when used without options strips everything when option" file="./spec/unit/web/test_cors_headers.rb" time="0.000141"></testcase>
94
+ <testcase classname="spec.unit.web.test_cors_headers" name="Startback::Web::CorsHeaders when used with the :bounce option sets the CORS Origin header to the caller" file="./spec/unit/web/test_cors_headers.rb" time="0.000138"></testcase>
95
+ <testcase classname="spec.unit.web.test_cors_headers" name="Startback::Web::CorsHeaders when overriding a header sets the CORS Origin header to the caller" file="./spec/unit/web/test_cors_headers.rb" time="0.000140"></testcase>
96
+ <testcase classname="spec.unit.web.test_cors_headers" name="Startback::Web::CorsHeaders when the app sets specific headers does not override them" file="./spec/unit/web/test_cors_headers.rb" time="0.000137"></testcase>
97
+ <testcase classname="spec.unit.web.test_healthcheck" name="Startback::Web::HealthCheck when used without a block and no failure returns a 204 when ok" file="./spec/unit/web/test_healthcheck.rb" time="0.000142"></testcase>
98
+ <testcase classname="spec.unit.web.test_healthcheck" name="Startback::Web::HealthCheck when used without a block a failure raises when ko" file="./spec/unit/web/test_healthcheck.rb" time="0.000124"></testcase>
99
+ <testcase classname="spec.unit.web.test_healthcheck" name="Startback::Web::HealthCheck when used with a block returning a debug message returns a 200 with plain text message" file="./spec/unit/web/test_healthcheck.rb" time="0.000124"></testcase>
100
+ <testcase classname="spec.unit.web.test_healthcheck" name="Startback::Web::HealthCheck when used with a block raising an exception re-raises it" file="./spec/unit/web/test_healthcheck.rb" time="0.000115"></testcase>
101
+ <testcase classname="spec.unit.web.test_magic_assets" name="Startback::Web::MagicAssets when used as an app works as expected" file="./spec/unit/web/test_magic_assets.rb" time="0.373353"></testcase>
102
+ <testcase classname="spec.unit.web.test_magic_assets" name="Startback::Web::MagicAssets when used as an app delegates a [] call to sprockets" file="./spec/unit/web/test_magic_assets.rb" time="0.251155"></testcase>
103
+ <testcase classname="spec.unit.web.test_magic_assets" name="Startback::Web::MagicAssets when used as an app returns a 404 on unknown" file="./spec/unit/web/test_magic_assets.rb" time="0.000450"></testcase>
104
+ <testcase classname="spec.unit.web.test_magic_assets" name="Startback::Web::MagicAssets when used as a middleware lets unrelated things pass" file="./spec/unit/web/test_magic_assets.rb" time="0.000250"></testcase>
105
+ <testcase classname="spec.unit.web.test_magic_assets" name="Startback::Web::MagicAssets when used as a middleware serves the assets under the chosen path" file="./spec/unit/web/test_magic_assets.rb" time="0.244319"></testcase>
106
+ <testcase classname="spec.unit.web.test_magic_assets" name="Startback::Web::MagicAssets when registering the NgHtmlTransformer works as expected" file="./spec/unit/web/test_magic_assets.rb" time="0.244951"></testcase>
102
107
  </testsuite>
@@ -4,7 +4,12 @@ module Startback
4
4
  module Audit
5
5
  describe Prometheus do
6
6
 
7
- EXPORTER = Prometheus.new
7
+ EXPORTER = Prometheus.new({
8
+ prefix: "hello",
9
+ labels: {
10
+ app_version: "1.0"
11
+ }
12
+ })
8
13
 
9
14
  class Runner
10
15
  include Startback::Support::OperationRunner
@@ -32,7 +37,13 @@ module Startback
32
37
 
33
38
  describe 'The ideal case' do
34
39
  before do
35
- expect(EXPORTER.calls).to receive(:observe)
40
+ expect(EXPORTER.calls).to receive(:observe).with(
41
+ kind_of(Numeric),
42
+ hash_including(labels: {
43
+ operation: "Startback::Audit::Runner::IdealOp",
44
+ startback_version: Startback::VERSION,
45
+ app_version: "1.0"
46
+ }))
36
47
  expect(EXPORTER.errors).not_to receive(:increment)
37
48
  end
38
49
  it 'runs the operation' do
@@ -42,7 +53,13 @@ module Startback
42
53
 
43
54
  describe 'The exceptional case' do
44
55
  before do
45
- expect(EXPORTER.errors).to receive(:increment)
56
+ expect(EXPORTER.errors).to receive(:increment).with(
57
+ hash_including(labels: {
58
+ operation: "Startback::Audit::Runner::ExceptionalOp",
59
+ startback_version: Startback::VERSION,
60
+ app_version: "1.0"
61
+ })
62
+ )
46
63
  expect(EXPORTER.calls).not_to receive(:observe)
47
64
  end
48
65
  it 'let errors bubble up' do
@@ -0,0 +1,82 @@
1
+ require 'spec_helper'
2
+ require 'startback/web/api'
3
+
4
+ module Startback
5
+ module Web
6
+ describe Api do
7
+ include Rack::Test::Methods
8
+
9
+ class JsonDto
10
+ def to(accept, content_type)
11
+ ["application/json", %Q{{"foo":"bar"}}]
12
+ end
13
+ end
14
+
15
+ class PathDto
16
+ def to(accept, content_type)
17
+ ["text/plain", Path.file]
18
+ end
19
+ end
20
+
21
+ class DtoAble
22
+ def initialize(dto)
23
+ @dto = dto
24
+ end
25
+ def to_dto(context)
26
+ @dto
27
+ end
28
+ end
29
+
30
+ class TestedApi < ::Startback::Web::Api
31
+ get '/no-such-one' do
32
+ serve("Something", nil)
33
+ end
34
+
35
+ get '/entity' do
36
+ serve('Entity', {foo: "bar"})
37
+ end
38
+
39
+ get '/path' do
40
+ serve('Path', Path.file)
41
+ end
42
+
43
+ get '/dto-able' do
44
+ serve('DTO', DtoAble.new(JsonDto.new))
45
+ end
46
+
47
+ get '/dto-path' do
48
+ serve('DTO', DtoAble.new(PathDto.new))
49
+ end
50
+ end
51
+
52
+ let(:app) {
53
+ TestedApi
54
+ }
55
+
56
+ it 'convert nil to 404' do
57
+ get '/no-such-one'
58
+ expect(last_response.status).to eql(404)
59
+ end
60
+
61
+ it 'supports serving entities' do
62
+ get '/entity'
63
+ expect(last_response.body).to eql(%Q{{"foo":"bar"}})
64
+ end
65
+
66
+ it 'supports serving paths' do
67
+ get '/path'
68
+ expect(last_response.body).to eql(Path.file.read)
69
+ end
70
+
71
+ it 'supports serving DTO-able objects' do
72
+ get '/dto-able'
73
+ expect(last_response.body).to eql(%Q{{"foo":"bar"}})
74
+ end
75
+
76
+ it 'supports serving DTO-able objects eventually returning paths' do
77
+ get '/dto-path'
78
+ expect(last_response.body).to eql(Path.file.read)
79
+ end
80
+ end
81
+ end # module Web
82
+ end # module Startback
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: startback
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.3
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bernard Lambeau
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-10 00:00:00.000000000 Z
11
+ date: 2021-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -56,34 +56,20 @@ dependencies:
56
56
  requirements:
57
57
  - - ">="
58
58
  - !ruby/object:Gem::Version
59
- version: 0.15.2
59
+ version: 0.20.5
60
60
  - - "<"
61
61
  - !ruby/object:Gem::Version
62
- version: '0.16'
62
+ version: '0.21'
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - ">="
68
68
  - !ruby/object:Gem::Version
69
- version: 0.15.2
69
+ version: 0.20.5
70
70
  - - "<"
71
71
  - !ruby/object:Gem::Version
72
- version: '0.16'
73
- - !ruby/object:Gem::Dependency
74
- name: rack-test
75
- requirement: !ruby/object:Gem::Requirement
76
- requirements:
77
- - - ">="
78
- - !ruby/object:Gem::Version
79
- version: '0'
80
- type: :development
81
- prerelease: false
82
- version_requirements: !ruby/object:Gem::Requirement
83
- requirements:
84
- - - ">="
85
- - !ruby/object:Gem::Version
86
- version: '0'
72
+ version: '0.21'
87
73
  - !ruby/object:Gem::Dependency
88
74
  name: rake
89
75
  requirement: !ruby/object:Gem::Requirement
@@ -144,20 +130,20 @@ dependencies:
144
130
  requirements:
145
131
  - - ">="
146
132
  - !ruby/object:Gem::Version
147
- version: '0.8'
133
+ version: '0.10'
148
134
  - - "<"
149
135
  - !ruby/object:Gem::Version
150
- version: '0.9'
136
+ version: '0.11'
151
137
  type: :runtime
152
138
  prerelease: false
153
139
  version_requirements: !ruby/object:Gem::Requirement
154
140
  requirements:
155
141
  - - ">="
156
142
  - !ruby/object:Gem::Version
157
- version: '0.8'
143
+ version: '0.10'
158
144
  - - "<"
159
145
  - !ruby/object:Gem::Version
160
- version: '0.9'
146
+ version: '0.11'
161
147
  - !ruby/object:Gem::Dependency
162
148
  name: path
163
149
  requirement: !ruby/object:Gem::Requirement
@@ -284,20 +270,20 @@ dependencies:
284
270
  requirements:
285
271
  - - ">="
286
272
  - !ruby/object:Gem::Version
287
- version: 0.17.5
273
+ version: 0.18.0
288
274
  - - "<"
289
275
  - !ruby/object:Gem::Version
290
- version: 0.18.0
276
+ version: 0.19.0
291
277
  type: :runtime
292
278
  prerelease: false
293
279
  version_requirements: !ruby/object:Gem::Requirement
294
280
  requirements:
295
281
  - - ">="
296
282
  - !ruby/object:Gem::Version
297
- version: 0.17.5
283
+ version: 0.18.0
298
284
  - - "<"
299
285
  - !ruby/object:Gem::Version
300
- version: 0.18.0
286
+ version: 0.19.0
301
287
  - !ruby/object:Gem::Dependency
302
288
  name: tzinfo
303
289
  requirement: !ruby/object:Gem::Requirement
@@ -372,6 +358,20 @@ dependencies:
372
358
  - - "<"
373
359
  - !ruby/object:Gem::Version
374
360
  version: '2.0'
361
+ - !ruby/object:Gem::Dependency
362
+ name: prometheus-client
363
+ requirement: !ruby/object:Gem::Requirement
364
+ requirements:
365
+ - - ">="
366
+ - !ruby/object:Gem::Version
367
+ version: '2.1'
368
+ type: :runtime
369
+ prerelease: false
370
+ version_requirements: !ruby/object:Gem::Requirement
371
+ requirements:
372
+ - - ">="
373
+ - !ruby/object:Gem::Version
374
+ version: '2.1'
375
375
  description: Yet another ruby backend framework, I'm afraid
376
376
  email: blambeau@gmail.com
377
377
  executables: []
@@ -444,6 +444,7 @@ files:
444
444
  - spec/unit/web/fixtures/assets/app/hello.es6
445
445
  - spec/unit/web/fixtures/assets/app/hello.html
446
446
  - spec/unit/web/fixtures/assets/index.es6
447
+ - spec/unit/web/test_api.rb
447
448
  - spec/unit/web/test_auto_caching.rb
448
449
  - spec/unit/web/test_catch_all.rb
449
450
  - spec/unit/web/test_cors_headers.rb
@@ -454,7 +455,7 @@ homepage: http://www.enspirit.be
454
455
  licenses:
455
456
  - MIT
456
457
  metadata: {}
457
- post_install_message:
458
+ post_install_message:
458
459
  rdoc_options: []
459
460
  require_paths:
460
461
  - lib
@@ -469,8 +470,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
469
470
  - !ruby/object:Gem::Version
470
471
  version: '0'
471
472
  requirements: []
472
- rubygems_version: 3.1.4
473
- signing_key:
473
+ rubygems_version: 3.0.8
474
+ signing_key:
474
475
  specification_version: 4
475
476
  summary: Got Your Ruby Back
476
477
  test_files: []