Created
August 26, 2010 04:48
-
-
Save don-smith/550830 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rspec' | |
class MaterialSelector | |
def select(model, material) | |
model.selection.clear | |
model.entities.each do |entity| | |
select_with entity, material do |matching_entity| | |
model.selection.add matching_entity | |
end | |
end | |
end | |
private | |
def select_with(entity, material, &block) | |
case entity.typename | |
when 'Face' | |
yield entity if entity.material.display_name == material.display_name | |
when 'Group' | |
entity.entities.each { |sub_entity| select_with sub_entity, material, &block } | |
when 'ComponentInstance' | |
entity.definition.entities.each { |sub_entity| select_with sub_entity, material, &block } | |
end | |
end | |
end | |
describe MaterialSelector do | |
include RSpec::Mocks | |
before :each do | |
@brown_material = double('material').stub('display_name').and_return('brown') | |
@brown_face = double('face').stub('material').and_return(@brown_material) | |
black_material = double('material').stub('display_name').and_return('black') | |
@black_face = double('face').stub('material').and_return(black_material) | |
selection = double('selection').should_receive(:clear).and_return(nil) | |
selection.should_receive(:add).with(@brown_face) | |
@model = double('model').stub('selection').and_return(selection) | |
@model.stub('active_entities').and_return([@brown_face, @black_face]) | |
end | |
it "should select faces directly in the active model" do | |
selector = MaterialSelector.new | |
selector.select(@model, @brown_material) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment