spec/resource_spec.rb in wright-0.3.2 vs spec/resource_spec.rb in wright-0.4.0
- old
+ new
@@ -33,21 +33,23 @@
class Sample < Wright::Resource; end
# resource with a single method to test update notification
class Updater < Wright::Resource
+ def initialize(name = '')
+ super
+ end
+
def do_something
might_update_resource {}
end
end
describe Wright::Resource do
before(:each) do
@config = Wright::Config.config_hash.clone
Wright::Config.config_hash.clear
- @hello = 'Hello world'
- @say_hello = -> { print @hello }
end
after(:each) do
Wright::Config.config_hash = @config
end
@@ -80,23 +82,28 @@
end
it 'should run update actions on updates' do
provider = Wright::Provider::AlwaysUpdated
Wright::Config[:resources] = { updater: { provider: provider.name } }
- resource = Updater.new
+ resource = Updater.new('sample_updater')
+ notification = "INFO: run update action for updater 'sample_updater'"
+ message = 'hello'
lambda do
- resource.on_update = @say_hello
+ reset_logger
+ resource.on_update = -> { print message }
assert resource.do_something
- end.must_output @hello
+ end.must_output "#{notification}\n#{message}"
end
it 'should not run update actions if there were no updates' do
provider = Wright::Provider::NeverUpdated
Wright::Config[:resources] = { updater: { provider: provider.name } }
resource = Updater.new
+ message = 'hello'
lambda do
- resource.on_update = @say_hello
+ reset_logger
+ resource.on_update = -> { print message }
assert !resource.do_something
end.must_be_silent
end
it 'should not run update actions in dry-run mode' do
@@ -104,15 +111,16 @@
provider = Wright::Provider::AlwaysUpdated
Wright::Config[:resources] = { updater: { provider: provider.name } }
name = :farnsworth
resource = Updater.new(name)
resource_info = "#{resource.resource_name} '#{name}'"
- output = "INFO: (would) run update action for #{resource_info}\n"
+ notification = "INFO: (would) run update action for #{resource_info}\n"
+ message = 'hello'
lambda do
reset_logger
- resource.on_update = @say_hello
+ resource.on_update = -> { print message }
assert resource.do_something
- end.must_output output
+ end.must_output notification
end
end
it 'should raise an ArgumentError if on_update is not callable' do
resource = Sample.new