Class: RSpectacles::Adapter::RedisLogger
- Inherits:
-
Object
- Object
- RSpectacles::Adapter::RedisLogger
- Defined in:
- lib/rspectacles/adapter/redis_logger.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#redis ⇒ Object
readonly
Returns the value of attribute redis.
-
#test_run_key ⇒ Object
readonly
Returns the value of attribute test_run_key.
Instance Method Summary collapse
- #config ⇒ Object
- #delete_last_log ⇒ Object
- #format_example(example) ⇒ Object
-
#initialize(test_run_key: nil) ⇒ RedisLogger
constructor
A new instance of RedisLogger.
- #log(message) ⇒ Object
- #log_formatted(example) ⇒ Object
- #message(text) ⇒ Object
- #queue(message) ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
- #uri ⇒ Object
Constructor Details
#initialize(test_run_key: nil) ⇒ RedisLogger
Returns a new instance of RedisLogger.
11 12 13 14 |
# File 'lib/rspectacles/adapter/redis_logger.rb', line 11 def initialize(test_run_key: nil) @redis = ::Redis.new host: uri.host, port: uri.port, password: uri.password, username: uri.user @test_run_key = test_run_key || config.last_run_primary_key end |
Instance Attribute Details
#redis ⇒ Object (readonly)
Returns the value of attribute redis.
9 10 11 |
# File 'lib/rspectacles/adapter/redis_logger.rb', line 9 def redis @redis end |
#test_run_key ⇒ Object (readonly)
Returns the value of attribute test_run_key.
9 10 11 |
# File 'lib/rspectacles/adapter/redis_logger.rb', line 9 def test_run_key @test_run_key end |
Instance Method Details
#config ⇒ Object
16 17 18 |
# File 'lib/rspectacles/adapter/redis_logger.rb', line 16 def config RSpectacles.config end |
#delete_last_log ⇒ Object
24 25 26 |
# File 'lib/rspectacles/adapter/redis_logger.rb', line 24 def delete_last_log redis.del config.last_run_primary_key end |
#format_example(example) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/rspectacles/adapter/redis_logger.rb', line 54 def format_example(example) { rspec_run: test_run_key, description: example.description, full_description: example.full_description, status: example.execution_result.status, duration: example.execution_result.run_time, file_path: example.[:file_path], line_number: example.[:line_number] }.to_json end |
#log(message) ⇒ Object
40 41 42 |
# File 'lib/rspectacles/adapter/redis_logger.rb', line 40 def log() queue "#{test_run_key}:#{}" end |
#log_formatted(example) ⇒ Object
44 45 46 47 |
# File 'lib/rspectacles/adapter/redis_logger.rb', line 44 def log_formatted(example) = format_example(example) queue end |
#message(text) ⇒ Object
36 37 38 |
# File 'lib/rspectacles/adapter/redis_logger.rb', line 36 def (text) log "message:#{text}" end |
#queue(message) ⇒ Object
49 50 51 52 |
# File 'lib/rspectacles/adapter/redis_logger.rb', line 49 def queue() redis.publish config.pubsub_channel_name, redis.lpush test_run_key, end |
#start ⇒ Object
32 33 34 |
# File 'lib/rspectacles/adapter/redis_logger.rb', line 32 def start log 'status:start' end |
#stop ⇒ Object
28 29 30 |
# File 'lib/rspectacles/adapter/redis_logger.rb', line 28 def stop log 'status:stop' end |
#uri ⇒ Object
20 21 22 |
# File 'lib/rspectacles/adapter/redis_logger.rb', line 20 def uri @uri ||= URI.parse config.redis_uri end |