summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorMichael Herold <michael.j.herold+github@gmail.com>2016-11-02 05:47:33 -0500
committerDaniel Doubrovkine (dB.) @dblockdotorg <dblock@dblock.org>2016-11-02 06:47:33 -0400
commite35e628dddcc0439948a78189a90d057da7f59fb (patch)
tree5460cbdafa1024b9889c0a5a316c2ee066d01d8f /spec
parentaa4f809c03c0be694bb31b7e85e29cc74e1ee83a (diff)
downloadhashie-e35e628dddcc0439948a78189a90d057da7f59fb.tar.gz
Add a logging layer to address common issues (#381)
Diffstat (limited to 'spec')
-rw-r--r--spec/hashie/mash_spec.rb8
-rw-r--r--spec/hashie/utils_spec.rb25
-rw-r--r--spec/hashie_spec.rb13
-rw-r--r--spec/support/logger.rb22
4 files changed, 68 insertions, 0 deletions
diff --git a/spec/hashie/mash_spec.rb b/spec/hashie/mash_spec.rb
index f187d1f..c0fffe1 100644
--- a/spec/hashie/mash_spec.rb
+++ b/spec/hashie/mash_spec.rb
@@ -134,6 +134,14 @@ describe Hashie::Mash do
expect(subject.type).to eq 'Steve'
end
+ shared_context 'with a logger' do
+ it 'logs a warning when overriding built-in methods' do
+ Hashie::Mash.new('trust' => { 'two' => 2 })
+
+ expect(logger_output).to match('Hashie::Mash#trust')
+ end
+ end
+
context 'updating' do
subject do
described_class.new(
diff --git a/spec/hashie/utils_spec.rb b/spec/hashie/utils_spec.rb
new file mode 100644
index 0000000..0499aa7
--- /dev/null
+++ b/spec/hashie/utils_spec.rb
@@ -0,0 +1,25 @@
+require 'spec_helper'
+
+def a_method_to_match_against
+ 'Hello world!'
+end
+
+RSpec.describe Hashie::Utils do
+ describe '.method_information' do
+ it 'states the module or class that a native method was defined in' do
+ bound_method = method(:trust)
+
+ message = Hashie::Utils.method_information(bound_method)
+
+ expect(message).to match('Kernel')
+ end
+
+ it 'states the line a Ruby method was defined at' do
+ bound_method = method(:a_method_to_match_against)
+
+ message = Hashie::Utils.method_information(bound_method)
+
+ expect(message).to match('spec/hashie/utils_spec.rb')
+ end
+ end
+end
diff --git a/spec/hashie_spec.rb b/spec/hashie_spec.rb
new file mode 100644
index 0000000..bc999b9
--- /dev/null
+++ b/spec/hashie_spec.rb
@@ -0,0 +1,13 @@
+require 'spec_helper'
+
+RSpec.describe Hashie do
+ describe '.logger' do
+ shared_context 'with a logger' do
+ it 'is available via an accessor' do
+ Hashie.logger.info('Fee fi fo fum')
+
+ expect(logger_output).to match('Fee fi fo fum')
+ end
+ end
+ end
+end
diff --git a/spec/support/logger.rb b/spec/support/logger.rb
new file mode 100644
index 0000000..4fd355a
--- /dev/null
+++ b/spec/support/logger.rb
@@ -0,0 +1,22 @@
+# A shared context that allows you to check the output of Hashie's logger.
+#
+# @example
+# shared_context 'with a logger' do
+# Hashie.logger.info 'What is happening in here?!'
+#
+# expect(logger_output).to match('What is happening in here?!')
+# end
+RSpec.shared_context 'with a logger' do
+ # @private
+ let(:log) { StringIO.new }
+
+ # The output string from the logger
+ let(:logger_output) { log.rewind && log.string }
+
+ around(:each) do |example|
+ original_logger = Hashie.logger
+ Hashie.logger = Logger.new(log)
+ example.run
+ Hashie.logger = original_logger
+ end
+end