free_mutant/spec/unit/mutant/require_highjack_spec.rb
Markus Schirp 6df5811a87 Use RSpec as receiver for rspec DSL methods
* I dislike the global infection RSpec does. This commit is a first step
  to get a rid of it.
* Also remove the need for `require 'spec_helper` in each spec file with
  adjusting `.rspec`.
2014-08-10 21:04:07 +00:00

52 lines
1.3 KiB
Ruby

RSpec.describe Mutant::RequireHighjack do
let(:object) { described_class.new(target, highjacked_calls.method(:push)) }
let(:highjacked_calls) { [] }
let(:require_calls) { [] }
let(:target) do
require_calls = self.require_calls
Module.new do
define_method(:require) do |logical_name|
require_calls << logical_name
end
module_function :require
end
end
describe '#run' do
let(:block) { -> {} }
let(:logical_name) { double('Logical Name') }
subject do
object.run(&block)
end
context 'require calls before run' do
it 'does not highjack anything' do
target.require(logical_name)
expect(require_calls).to eql([logical_name])
expect(highjacked_calls).to eql([])
end
end
context 'require calls during run' do
let(:block) { -> { target.require(logical_name) } }
it 'does highjack the calls' do
expect { subject }.to change { highjacked_calls }.from([]).to([logical_name])
expect(require_calls).to eql([])
end
end
context 'require calls after run' do
it 'does not the calls anything' do
subject
target.require(logical_name)
expect(require_calls).to eql([logical_name])
expect(highjacked_calls).to eql([])
end
end
end
end