2014-08-10 21:04:05 +00:00
|
|
|
RSpec.describe Mutant::Matcher::Namespace do
|
2014-06-30 13:06:57 +00:00
|
|
|
let(:object) { described_class.new(env, Mutant::Expression.parse('TestApp*')) }
|
|
|
|
let(:yields) { [] }
|
2014-07-02 17:47:51 +00:00
|
|
|
let(:env) { double('Env') }
|
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
|
|
|
|
|
2014-06-30 12:39:18 +00:00
|
|
|
let(:singleton_a) { double('SingletonA', name: 'TestApp::Literal') }
|
|
|
|
let(:singleton_b) { double('SingletonB', name: 'TestApp::Foo') }
|
|
|
|
let(:singleton_c) { double('SingletonC', name: 'TestAppOther') }
|
|
|
|
let(:subject_a) { double('SubjectA') }
|
|
|
|
let(:subject_b) { double('SubjectB') }
|
2014-06-06 20:28:01 +00:00
|
|
|
|
|
|
|
before do
|
2014-06-30 13:06:57 +00:00
|
|
|
allow(Mutant::Matcher::Methods::Singleton).to receive(:new).with(env, singleton_b).and_return([subject_b])
|
|
|
|
allow(Mutant::Matcher::Methods::Instance).to receive(:new).with(env, singleton_b).and_return([])
|
2014-06-29 22:33:40 +00:00
|
|
|
|
2014-07-02 17:47:51 +00:00
|
|
|
allow(Mutant::Matcher::Methods::Singleton).to receive(:new).with(env, singleton_a).and_return([subject_a])
|
|
|
|
allow(Mutant::Matcher::Methods::Instance).to receive(:new).with(env, singleton_a).and_return([])
|
|
|
|
|
|
|
|
allow(env).to receive(:matchable_scopes).and_return(
|
|
|
|
[singleton_a, singleton_b, singleton_c].map do |scope|
|
|
|
|
Mutant::Matcher::Scope.new(env, scope, Mutant::Expression.parse(scope.name))
|
|
|
|
end
|
|
|
|
)
|
2014-06-06 20:28:01 +00:00
|
|
|
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
|
2014-07-02 17:47:51 +00:00
|
|
|
expect { subject }.to change { yields }.from([]).to([subject_a, subject_b])
|
2014-06-06 20:28:01 +00:00
|
|
|
end
|
2013-01-21 22:56:52 +01:00
|
|
|
end
|
|
|
|
end
|