Fix specs using shared context 'with a logger'

Correct usage of a shared_context is to use include_context
This commit is contained in:
Bill Ruddock 2017-02-03 00:58:01 +00:00
parent c1a42d4fab
commit 330cfa1c2a
3 changed files with 14 additions and 11 deletions

View File

@ -1,9 +1,12 @@
require 'spec_helper' require 'spec_helper'
require 'delegate' require 'delegate'
require 'support/logger'
describe Hashie::Mash do describe Hashie::Mash do
subject { Hashie::Mash.new } subject { Hashie::Mash.new }
include_context 'with a logger'
it 'inherits from Hash' do it 'inherits from Hash' do
expect(subject.is_a?(Hash)).to be_truthy expect(subject.is_a?(Hash)).to be_truthy
end end
@ -134,12 +137,10 @@ describe Hashie::Mash do
expect(subject.type).to eq 'Steve' expect(subject.type).to eq 'Steve'
end end
shared_context 'with a logger' do it 'logs a warning when overriding built-in methods' do
it 'logs a warning when overriding built-in methods' do Hashie::Mash.new('trust' => { 'two' => 2 })
Hashie::Mash.new('trust' => { 'two' => 2 })
expect(logger_output).to match('Hashie::Mash#trust') expect(logger_output).to match('Hashie::Mash#trust')
end
end end
context 'updating' do context 'updating' do

View File

@ -2,12 +2,12 @@ require 'spec_helper'
RSpec.describe Hashie do RSpec.describe Hashie do
describe '.logger' do describe '.logger' do
shared_context 'with a logger' do include_context 'with a logger'
it 'is available via an accessor' do
Hashie.logger.info('Fee fi fo fum')
expect(logger_output).to match('Fee fi fo fum') it 'is available via an accessor' do
end Hashie.logger.info('Fee fi fo fum')
expect(logger_output).to match('Fee fi fo fum')
end end
end end
end end

View File

@ -1,7 +1,9 @@
# A shared context that allows you to check the output of Hashie's logger. # A shared context that allows you to check the output of Hashie's logger.
# #
# @example # @example
# shared_context 'with a logger' do # include_context 'with a logger'
#
# it 'logs info message' do
# Hashie.logger.info 'What is happening in here?!' # Hashie.logger.info 'What is happening in here?!'
# #
# expect(logger_output).to match('What is happening in here?!') # expect(logger_output).to match('What is happening in here?!')