Module: Helpers
- Defined in:
- vendor_modules/lvm/spec/lib/helpers.rb
Constant Summary collapse
- TEST_DIR =
Pathname.new(__FILE__).parent + '..'
- TYPES =
{ :pv => :physical_volume, :lv => :logical_volume, :vg => :volume_group, :fs => :filesystem }
Class Method Summary collapse
Instance Method Summary collapse
- #fixture(name, ext = '.txt') ⇒ Object
-
#should_create(type) ⇒ Object
Sets up an expection that a resource for
type
is created. -
#should_not_create(type) ⇒ Object
Sets up an expection that a resource for
type
is not created. -
#specifying(opts = {}, &block) ⇒ Object
Returns a lambda creating a resource (ready for use with
should
). -
#stub_default_provider! ⇒ Object
Stub the default provider to get around confines for testing.
-
#valid_params_without(*keys) ⇒ Object
Return the @valid_params without one or more keys Note: Useful since resource types don't like it when
nil
is passed as a parameter value. -
#with(opts = {}, &block) ⇒ Object
Creates a new resource of
type
.
Class Method Details
.included(obj) ⇒ Object
12 13 14 |
# File 'vendor_modules/lvm/spec/lib/helpers.rb', line 12 def self.included(obj) obj.instance_eval { attr_reader :valid_params } end |
Instance Method Details
#fixture(name, ext = '.txt') ⇒ Object
56 57 58 |
# File 'vendor_modules/lvm/spec/lib/helpers.rb', line 56 def fixture(name, ext = '.txt') (TEST_DIR + 'fixtures' + "#{name}#{ext}").read end |
#should_create(type) ⇒ Object
Sets up an expection that a resource for type
is created
35 36 37 38 |
# File 'vendor_modules/lvm/spec/lib/helpers.rb', line 35 def should_create(type) raise "Invalid type #{type}" unless TYPES[type] Puppet::Type.type(TYPES[type]).expects(:new).with { |args| yield(args) } end |
#should_not_create(type) ⇒ Object
Sets up an expection that a resource for type
is not created
29 30 31 32 |
# File 'vendor_modules/lvm/spec/lib/helpers.rb', line 29 def should_not_create(type) raise "Invalid type #{type}" unless TYPES[type] Puppet::Type.type(TYPES[type]).expects(:new).never end |
#specifying(opts = {}, &block) ⇒ Object
Returns a lambda creating a resource (ready for use with
should
)
23 24 25 26 |
# File 'vendor_modules/lvm/spec/lib/helpers.rb', line 23 def (opts = {}, &block) specification = lambda { with(opts) } block ? (yield specification) : specification end |
#stub_default_provider! ⇒ Object
Stub the default provider to get around confines for testing
48 49 50 51 52 53 54 |
# File 'vendor_modules/lvm/spec/lib/helpers.rb', line 48 def stub_default_provider! unless defined?(@type) raise ArgumentError, "@type must be set" end provider = @type.provider(:lvm) @type.stubs(:defaultprovider => provider) end |
#valid_params_without(*keys) ⇒ Object
Return the @valid_params without one or more keys Note: Useful since
resource types don't like it when nil
is passed as a
parameter value
43 44 45 |
# File 'vendor_modules/lvm/spec/lib/helpers.rb', line 43 def valid_params_without(*keys) valid_params.reject { |k, v| keys.include?(k) } end |
#with(opts = {}, &block) ⇒ Object
Creates a new resource of type
17 18 19 20 |
# File 'vendor_modules/lvm/spec/lib/helpers.rb', line 17 def with(opts = {}, &block) resource = @type.new(opts) block ? (yield resource) : resource end |