diff options
| author | Nick Lewis <nick@puppetlabs.com> | 2011-03-22 16:44:01 -0700 |
|---|---|---|
| committer | Nick Lewis <nick@puppetlabs.com> | 2011-03-22 17:18:51 -0700 |
| commit | 847ac203f9c0b5fce299e87a63b0de5d3ef416f6 (patch) | |
| tree | 1177637a9ae75527b14523d3803c610601e5d54b /spec/unit/interface_spec.rb | |
| parent | 01ce91816fe061267e9821c07fefb8aa14af4a14 (diff) | |
| download | puppet-847ac203f9c0b5fce299e87a63b0de5d3ef416f6.tar.gz puppet-847ac203f9c0b5fce299e87a63b0de5d3ef416f6.tar.xz puppet-847ac203f9c0b5fce299e87a63b0de5d3ef416f6.zip | |
maint: Implement an InterfaceCollection class to manage interfaces
Having an instance variable on class Interface is insufficient for
Interface::Indirector. This also changes the semantics of "Interface.interface"
to handle registration and loading actions, and for "Interface.new" to only
instantiate an Interface. Thus, consumers of the API should typically use
"Interface.interface", unless they have reasons to not want an interface
automatically registered.
Paired-With: Pieter van de Bruggen
Diffstat (limited to 'spec/unit/interface_spec.rb')
| -rwxr-xr-x | spec/unit/interface_spec.rb | 56 |
1 files changed, 15 insertions, 41 deletions
diff --git a/spec/unit/interface_spec.rb b/spec/unit/interface_spec.rb index 876c7945c..e35da6b95 100755 --- a/spec/unit/interface_spec.rb +++ b/spec/unit/interface_spec.rb @@ -4,32 +4,32 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb') require 'puppet/interface' describe Puppet::Interface do - describe "at initialization" do - it "should require a name" do - Puppet::Interface.new(:me).name.should == :me - end - - it "should register itself" do - Puppet::Interface.expects(:register_interface).with do |name, inst| - name == :me and inst.is_a?(Puppet::Interface) - end - Puppet::Interface.new(:me) + describe "#interface" do + it "should register the interface" do + interface = Puppet::Interface.interface(:interface_test_register) + interface.should == Puppet::Interface.interface(:interface_test_register) end it "should load actions" do Puppet::Interface.any_instance.expects(:load_actions) - Puppet::Interface.new(:me) + Puppet::Interface.interface(:interface_test_load_actions) end it "should instance-eval any provided block" do - face = Puppet::Interface.new(:me) do - action(:something) { "foo" } + face = Puppet::Interface.new(:interface_test_block) do + action(:something) do + invoke { "foo" } + end end - face.should be_action(:something) + face.something.should == "foo" end end + it "should have a name" do + Puppet::Interface.new(:me).name.should == :me + end + it "should stringify with its own name" do Puppet::Interface.new(:me).to_s.should =~ /\bme\b/ end @@ -54,35 +54,9 @@ describe Puppet::Interface do end it "should try to require interfaces that are not known" do - Puppet::Interface.expects(:require).with "puppet/interface/foo" + Puppet::Interface::InterfaceCollection.expects(:require).with "puppet/interface/foo" Puppet::Interface.interface(:foo) end it "should be able to load all actions in all search paths" - - describe "#underscorize" do - faulty = [1, "#foo", "$bar", "sturm und drang", :"sturm und drang"] - valid = { - "Foo" => :foo, - :Foo => :foo, - "foo_bar" => :foo_bar, - :foo_bar => :foo_bar, - "foo-bar" => :foo_bar, - :"foo-bar" => :foo_bar, - } - - valid.each do |input, expect| - it "should map #{input.inspect} to #{expect.inspect}" do - result = Puppet::Interface.underscorize(input) - result.should == expect - end - end - - faulty.each do |input| - it "should fail when presented with #{input.inspect} (#{input.class})" do - expect { Puppet::Interface.underscorize(input) }. - should raise_error ArgumentError, /not a valid interface name/ - end - end - end end |
