parent
41205f9d90
commit
83f6a22a16
3 changed files with 39 additions and 29 deletions
|
@ -36,7 +36,7 @@ module Mutant
|
|||
# @api private
|
||||
#
|
||||
def pattern
|
||||
/\A#{Regexp.escape(namespace)}(?:::)?/
|
||||
/\A#{Regexp.escape(namespace)}(?:\z|::)/
|
||||
end
|
||||
memoize :pattern
|
||||
|
||||
|
|
|
@ -28,6 +28,12 @@ describe Mutant::Expression::Namespace::Recursive do
|
|||
it { should be(0) }
|
||||
end
|
||||
|
||||
context 'when other expression describes adjacent namespace' do
|
||||
let(:other) { described_class.parse('::TestApp::LiteralFoo') }
|
||||
|
||||
it { should be(0) }
|
||||
end
|
||||
|
||||
context 'when other expression describes a longer prefix' do
|
||||
let(:other) { described_class.parse('::TestApp::Literal::Deep') }
|
||||
|
||||
|
|
|
@ -2,44 +2,48 @@
|
|||
|
||||
require 'spec_helper'
|
||||
|
||||
describe Mutant::Matcher::Namespace, '#each' do
|
||||
subject { object.each { |item| yields << item } }
|
||||
|
||||
let(:yields) { [] }
|
||||
describe Mutant::Matcher::Namespace do
|
||||
let(:object) { described_class.new(cache, 'TestApp::Literal') }
|
||||
let(:yields) { [] }
|
||||
|
||||
let(:cache) { Mutant::Cache.new }
|
||||
|
||||
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') }
|
||||
subject { object.each { |item| yields << item } }
|
||||
|
||||
before do
|
||||
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)
|
||||
ObjectSpace.stub(each_object: [singleton_a, singleton_b])
|
||||
end
|
||||
describe '#each' do
|
||||
|
||||
context 'with no block' do
|
||||
subject { object.each }
|
||||
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') }
|
||||
|
||||
it { should be_instance_of(to_enum.class) }
|
||||
before do
|
||||
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)
|
||||
ObjectSpace.stub(each_object: [singleton_a, singleton_b, singleton_c])
|
||||
end
|
||||
|
||||
if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
|
||||
pending 'FIX RBX rspec? BUG HERE'
|
||||
else
|
||||
it 'yields the expected values' do
|
||||
expect(subject.to_a).to eql(object.to_a)
|
||||
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
|
||||
expect(subject.to_a).to eql(object.to_a)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it 'should yield subjects' do
|
||||
expect { subject }.to change { yields }.from([]).to([subject_a, subject_b])
|
||||
it 'should yield subjects' do
|
||||
expect { subject }.to change { yields }.from([]).to([subject_a, subject_b])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue