2013-07-28 19:03:06 -04:00
|
|
|
# encoding: utf-8
|
|
|
|
|
2013-01-21 16:56:52 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Mutant::Matcher::Namespace, '#each' do
|
|
|
|
subject { object.each { |item| yields << item } }
|
|
|
|
|
2014-06-02 08:45:29 -04:00
|
|
|
let(:yields) { [] }
|
|
|
|
let(:object) { described_class.new(cache, 'TestApp::Literal') }
|
2013-06-27 16:18:07 -04:00
|
|
|
|
|
|
|
let(:cache) { Mutant::Cache.new }
|
2013-01-21 16:56:52 -05:00
|
|
|
|
2013-09-08 16:12:23 -04:00
|
|
|
let(:singleton_a) { double('SingletonA', name: 'TestApp::Literal') }
|
|
|
|
let(:singleton_b) { double('SingletonB', name: 'TestApp::Foo') }
|
|
|
|
let(:subject_a) { double('SubjectA') }
|
|
|
|
let(:subject_b) { double('SubjectB') }
|
2013-01-21 16:56:52 -05:00
|
|
|
|
|
|
|
before do
|
2013-07-28 17:52:05 -04:00
|
|
|
Mutant::Matcher::Methods::Singleton.stub(:each)
|
|
|
|
.with(cache, singleton_a)
|
|
|
|
.and_yield(subject_a)
|
|
|
|
Mutant::Matcher::Methods::Instance.stub(:each)
|
|
|
|
.with(cache, singleton_a)
|
|
|
|
.and_yield(subject_b)
|
2013-09-08 16:12:23 -04:00
|
|
|
ObjectSpace.stub(each_object: [singleton_a, singleton_b])
|
2013-01-21 16:56:52 -05:00
|
|
|
end
|
|
|
|
|
2013-04-22 06:45:15 -04:00
|
|
|
context 'with no block' do
|
|
|
|
subject { object.each }
|
|
|
|
|
|
|
|
it { should be_instance_of(to_enum.class) }
|
|
|
|
|
|
|
|
if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
|
|
|
|
pending 'FIX RBX rspec? BUG HERE'
|
|
|
|
else
|
|
|
|
it 'yields the expected values' do
|
2014-01-19 15:42:21 -05:00
|
|
|
expect(subject.to_a).to eql(object.to_a)
|
2013-04-22 06:45:15 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-01-21 16:56:52 -05:00
|
|
|
|
|
|
|
it 'should yield subjects' do
|
|
|
|
expect { subject }.to change { yields }.from([]).to([subject_a, subject_b])
|
|
|
|
end
|
|
|
|
end
|