2015-10-28 20:13:00 +00:00
|
|
|
RSpec.describe Mutant::Matcher::Namespace, '#call' do
|
|
|
|
let(:object) { described_class.new(parse_expression('TestApp*')) }
|
|
|
|
let(:env) { instance_double(Mutant::Env) }
|
|
|
|
let(:raw_scope_a) { double('SingletonA', name: 'TestApp::Literal') }
|
|
|
|
|
|
|
|
let(:raw_scope_b) { double('SingletonB', name: 'TestApp::Foo') }
|
|
|
|
let(:raw_scope_c) { double('SingletonC', name: 'TestAppOther') }
|
|
|
|
let(:subject_a) { double('SubjectA') }
|
|
|
|
let(:subject_b) { double('SubjectB') }
|
|
|
|
|
|
|
|
before do
|
|
|
|
[
|
|
|
|
[Mutant::Matcher::Methods::Singleton, raw_scope_b, [subject_b]],
|
|
|
|
[Mutant::Matcher::Methods::Instance, raw_scope_b, []],
|
|
|
|
[Mutant::Matcher::Methods::Singleton, raw_scope_a, [subject_a]],
|
|
|
|
[Mutant::Matcher::Methods::Instance, raw_scope_a, []]
|
|
|
|
].each do |klass, scope, subjects|
|
|
|
|
matcher = instance_double(Mutant::Matcher)
|
|
|
|
expect(matcher).to receive(:call).with(env).and_return(subjects)
|
|
|
|
|
|
|
|
expect(klass).to receive(:new)
|
|
|
|
.with(scope)
|
|
|
|
.and_return(matcher)
|
2014-06-06 20:28:01 +00:00
|
|
|
end
|
2013-01-21 22:56:52 +01:00
|
|
|
|
2015-10-28 20:13:00 +00:00
|
|
|
allow(env).to receive(:matchable_scopes).and_return(
|
|
|
|
[raw_scope_a, raw_scope_b, raw_scope_c].map do |raw_scope|
|
|
|
|
Mutant::Scope.new(raw_scope, parse_expression(raw_scope.name))
|
2013-04-22 12:45:15 +02:00
|
|
|
end
|
2015-10-28 20:13:00 +00:00
|
|
|
)
|
|
|
|
end
|
2013-01-21 22:56:52 +01:00
|
|
|
|
2015-10-28 20:13:00 +00:00
|
|
|
it 'returns subjects' do
|
|
|
|
expect(object.call(env)).to eql([subject_a, subject_b])
|
2013-01-21 22:56:52 +01:00
|
|
|
end
|
|
|
|
end
|