2013-01-21 22:56:52 +01:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2014-06-06 20:28:01 +00:00
|
|
|
describe Mutant::Matcher::Namespace do
|
2014-06-02 12:45:29 +00:00
|
|
|
let(:object) { described_class.new(cache, 'TestApp::Literal') }
|
2014-06-06 20:28:01 +00:00
|
|
|
let(:yields) { [] }
|
2013-06-27 22:18:07 +02:00
|
|
|
|
|
|
|
let(:cache) { Mutant::Cache.new }
|
2013-01-21 22:56:52 +01:00
|
|
|
|
2014-06-06 20:28:01 +00:00
|
|
|
subject { object.each { |item| yields << item } }
|
|
|
|
|
|
|
|
describe '#each' do
|
|
|
|
|
|
|
|
let(:singleton_a) { double('SingletonA', name: 'TestApp::Literal') }
|
|
|
|
let(:singleton_b) { double('SingletonB', name: 'TestApp::Foo') }
|
|
|
|
let(:singleton_c) { double('SingletonC', name: 'TestApp::LiteralOther') }
|
|
|
|
let(:subject_a) { double('SubjectA') }
|
|
|
|
let(:subject_b) { double('SubjectB') }
|
|
|
|
|
|
|
|
before do
|
2014-06-29 00:23:54 +00:00
|
|
|
allow(Mutant::Matcher::Methods::Singleton).to receive(:new).with(cache, singleton_a).and_return([subject_a])
|
|
|
|
allow(Mutant::Matcher::Methods::Instance).to receive(:new).with(cache, singleton_a).and_return([subject_b])
|
2014-06-06 20:28:01 +00:00
|
|
|
ObjectSpace.stub(each_object: [singleton_a, singleton_b, singleton_c])
|
|
|
|
end
|
2013-01-21 22:56:52 +01:00
|
|
|
|
2014-06-06 20:28:01 +00:00
|
|
|
context 'with no block' do
|
|
|
|
subject { object.each }
|
2013-04-22 12:45:15 +02:00
|
|
|
|
2014-06-06 20:28:01 +00:00
|
|
|
it { should be_instance_of(to_enum.class) }
|
2013-04-22 12:45:15 +02:00
|
|
|
|
2014-06-29 00:25:27 +00:00
|
|
|
it 'yields the expected values' do
|
|
|
|
expect(subject.to_a).to eql(object.to_a)
|
2013-04-22 12:45:15 +02:00
|
|
|
end
|
|
|
|
end
|
2013-01-21 22:56:52 +01:00
|
|
|
|
2014-06-06 20:28:01 +00:00
|
|
|
it 'should yield subjects' do
|
|
|
|
expect { subject }.to change { yields }.from([]).to([subject_a, subject_b])
|
|
|
|
end
|
2013-01-21 22:56:52 +01:00
|
|
|
end
|
|
|
|
end
|