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 'delegate'
require 'support/logger'
describe Hashie::Mash do
subject { Hashie::Mash.new }
include_context 'with a logger'
it 'inherits from Hash' do
expect(subject.is_a?(Hash)).to be_truthy
end
@ -134,12 +137,10 @@ 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 })
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
expect(logger_output).to match('Hashie::Mash#trust')
end
context 'updating' do

View File

@ -2,12 +2,12 @@ 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')
include_context 'with a logger'
expect(logger_output).to match('Fee fi fo fum')
end
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

View File

@ -1,7 +1,9 @@
# A shared context that allows you to check the output of Hashie's logger.
#
# @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?!'
#
# expect(logger_output).to match('What is happening in here?!')