Module: ChefSpec::API::Stubs
- Extended by:
- RSpec::SharedContext
- Defined in:
- lib/chefspec/api/stubs.rb
Instance Method Summary collapse
-
#stub_command(command, &block) ⇒ ChefSpec::CommandStub
Stub a shell command to return a particular value without shelling out to the system.
-
#stub_data_bag(bag, &block) ⇒ ChefSpec::DataBagStub
Stub a Chef call to load a data_bag.
-
#stub_data_bag_item(bag, id, &block) ⇒ ChefSpec::DataBagItemStub
Stub a Chef data_bag call.
-
#stub_node(*args, &block) ⇒ Chef::Node
Creates a fake Chef::Node for use in testing.
-
#stub_search(type, query = "*:*", &block) ⇒ ChefSpec::SearchStub
Stub a Chef search to return pre-defined data.
Instance Method Details
#stub_command(command, &block) ⇒ ChefSpec::CommandStub
Stub a shell command to return a particular value without shelling out to the system.
26 27 28 |
# File 'lib/chefspec/api/stubs.rb', line 26 def stub_command(command, &block) ChefSpec::Stubs::CommandRegistry.register(ChefSpec::Stubs::CommandStub.new(command, &block)) end |
#stub_data_bag(bag, &block) ⇒ ChefSpec::DataBagStub
Stub a Chef call to load a data_bag.
54 55 56 |
# File 'lib/chefspec/api/stubs.rb', line 54 def stub_data_bag(bag, &block) ChefSpec::Stubs::DataBagRegistry.register(ChefSpec::Stubs::DataBagStub.new(bag, &block)) end |
#stub_data_bag_item(bag, id, &block) ⇒ ChefSpec::DataBagItemStub
Stub a Chef data_bag call.
81 82 83 |
# File 'lib/chefspec/api/stubs.rb', line 81 def stub_data_bag_item(bag, id, &block) ChefSpec::Stubs::DataBagItemRegistry.register(ChefSpec::Stubs::DataBagItemStub.new(bag, id, &block)) end |
#stub_node(*args, &block) ⇒ Chef::Node
Creates a fake Chef::Node for use in testing.
122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/chefspec/api/stubs.rb', line 122 def stub_node(*args, &block) = args.last.is_a?(Hash) ? args.pop : {} name = args.first || "node.example" fauxhai = Fauxhai.mock().data fauxhai = fauxhai.merge([:ohai] || {}) fauxhai = Mash.new(fauxhai) node = Chef::Node.new node.name(name) node.automatic_attrs = fauxhai node.instance_eval(&block) if block_given? node end |
#stub_search(type, query = "*:*", &block) ⇒ ChefSpec::SearchStub
Stub a Chef search to return pre-defined data. When providing a value, the value is automatically mashified (to the best of ChefSpecās abilities) to ease in use.
168 169 170 |
# File 'lib/chefspec/api/stubs.rb', line 168 def stub_search(type, query = "*:*", &block) ChefSpec::Stubs::SearchRegistry.register(ChefSpec::Stubs::SearchStub.new(type, query, &block)) end |