reality-core 1.5.0 → 1.6.0

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
  SHA1:
3
- metadata.gz: f0001afc36f924a295d6b3461b1cdcd78ac7546a
4
- data.tar.gz: 739121f92b960be4f5f27f18c0378a23a4727fa5
3
+ metadata.gz: 43244fb34b6e74b1281a583f71cdd1ba308391ce
4
+ data.tar.gz: 1cdbdaf9304e69c358f6f7448164cfcb84932e91
5
5
  SHA512:
6
- metadata.gz: 4a968ddcf90298e09ba2ca6d2d6037e33819ffe73f214f30fbcf3cb9f44debdc1113e71d01aba8e3843da9f0981781200f060009082f924b6f6f384092ce8517
7
- data.tar.gz: 5e69567c10388ea9e4a0b52819582fbf6dad1c38d8913853b913273075378167ba04d95e37591cb5858b21f8be2ef80e208c9d646b1799a1588e976ec3fbd0e1
6
+ metadata.gz: eb5958c12e4396ac98014749fc3063482d3822f5a1a0769ae70964a293ff7d2b6c82f0be585c2f958250781f3f78882d5d5bb02938727516cf2b68e99d56f18e
7
+ data.tar.gz: 8b7750bacc77d561bc64578d0d6775a29edb00262e3cede212da6d1a713f4e43090f897cae29550ca471dc7fdf14b8bdf3fe08de0baa85bef6c31070179c680e
@@ -75,5 +75,53 @@ module Reality
75
75
  end
76
76
  end
77
77
  end
78
+
79
+ # Module that should be mixed into base test class to test dependent libraries.
80
+ # It is expected that the class this is mixed into supplies a assert_raise method.
81
+ module Assertions
82
+ # for the specified log container capture the log output during blocks
83
+ # execution and return as a string
84
+ def capture_logging(log_container, &block)
85
+ raise 'capture_logging called but no block supplied.' unless block_given?
86
+ logger = log_container.const_get(:Logger)
87
+
88
+ logdev = logger.instance_variable_get('@logdev')
89
+ original_dev = logdev.instance_variable_get('@dev')
90
+
91
+ capture_io = StringIO.new
92
+ begin
93
+ logdev.instance_variable_set('@dev', capture_io)
94
+ yield block
95
+ return capture_io.string
96
+ ensure
97
+ logdev.instance_variable_set('@dev', original_dev)
98
+ end
99
+ end
100
+
101
+ # For the specified log container, capture the log output during blocks
102
+ # execution and match specified message. A new line is appended to
103
+ # expected_message as the logging system appends one.
104
+ def assert_logging_message(log_container, expected_message, &block)
105
+ raise 'assert_logging_message called but no block supplied.' unless block_given?
106
+
107
+ result = capture_logging(log_container) do
108
+ yield block
109
+ end
110
+
111
+ assert_equal "#{expected_message}\n", result
112
+ end
113
+
114
+ # For the specified log container, capture the log output during blocks
115
+ # execution and match specified message. Also ensure an exception is raised
116
+ # with the same message
117
+ def assert_logging_error(log_container, expected_message, &block)
118
+ raise 'assert_logging_error called but no block supplied.' unless block_given?
119
+ assert_logging_message(log_container, expected_message) do
120
+ assert_raise(RuntimeError.new(expected_message)) do
121
+ yield block
122
+ end
123
+ end
124
+ end
125
+ end
78
126
  end
79
127
  end
data/reality-core.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{reality-core}
5
- s.version = '1.5.0'
5
+ s.version = '1.6.0'
6
6
  s.platform = Gem::Platform::RUBY
7
7
 
8
8
  s.authors = ['Peter Donald']
data/test/test_logging.rb CHANGED
@@ -65,4 +65,59 @@ class Reality::TestLogging < Reality::TestCase
65
65
  assert_equal ::Logger::DEBUG, logger1.level
66
66
  assert_equal ::Logger::INFO, logger2.level
67
67
  end
68
+
69
+ class MyModule2
70
+ end
71
+
72
+ class MyFakeTest
73
+ include Test::Unit::Assertions
74
+ include Reality::Logging::Assertions
75
+ end
76
+
77
+ def test_assertions
78
+ mytest = MyFakeTest.new
79
+
80
+ io = StringIO.new('', 'w')
81
+ Reality::Logging.configure(MyModule2, ::Logger::INFO, io)
82
+
83
+ assert_raise(RuntimeError.new('capture_logging called but no block supplied.')) do
84
+ mytest.capture_logging(MyModule2)
85
+ end
86
+ assert_raise(RuntimeError.new('assert_logging_message called but no block supplied.')) do
87
+ mytest.assert_logging_message(MyModule2, 'X')
88
+ end
89
+ assert_raise(RuntimeError.new('assert_logging_error called but no block supplied.')) do
90
+ mytest.assert_logging_error(MyModule2, 'X')
91
+ end
92
+
93
+ messages = mytest.capture_logging(MyModule2) do
94
+ MyModule2.info('Hello from log system')
95
+ end
96
+ assert_equal "Hello from log system\n", messages
97
+
98
+ assert_raise(RuntimeError.new('assert_logging_message called but no block supplied.')) do
99
+ mytest.assert_logging_message(MyModule2, 'Hello from log system')
100
+ end
101
+
102
+ mytest.assert_logging_message(MyModule2, 'Hello from log system') do
103
+ MyModule2.info('Hello from log system')
104
+ end
105
+
106
+ assert_raise(Test::Unit::AssertionFailedError.new("<\"Hello from log system\\n\"> expected but was\n<\"\">.")) do
107
+ mytest.assert_logging_message(MyModule2, 'Hello from log system') do
108
+ # There is no message
109
+ end
110
+ end
111
+
112
+ assert_raise(Test::Unit::AssertionFailedError.new('<RuntimeError(<Hello from log system>)> exception expected but none was thrown.')) do
113
+ mytest.assert_logging_error(MyModule2, 'Hello from log system') do
114
+ # Should fail as there is only a message and not an error
115
+ MyModule2.info('Hello from log system')
116
+ end
117
+ end
118
+
119
+ mytest.assert_logging_error(MyModule2, 'Error!') do
120
+ MyModule2.error('Error!')
121
+ end
122
+ end
68
123
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reality-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Donald
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-07 00:00:00.000000000 Z
11
+ date: 2016-12-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest