Class: ChefSpec::Matchers::NotificationsMatcher
- Inherits:
-
Object
- Object
- ChefSpec::Matchers::NotificationsMatcher
- Includes:
- Normalize
- Defined in:
- lib/chefspec/matchers/notifications_matcher.rb
Instance Method Summary collapse
- #delayed ⇒ Object
- #description ⇒ Object
- #failure_message_for_should ⇒ Object
- #immediately ⇒ Object
-
#initialize(signature) ⇒ NotificationsMatcher
constructor
A new instance of NotificationsMatcher.
- #matches?(resource) ⇒ Boolean
- #to(action) ⇒ Object
Methods included from Normalize
Constructor Details
#initialize(signature) ⇒ NotificationsMatcher
Returns a new instance of NotificationsMatcher.
5 6 7 8 9 |
# File 'lib/chefspec/matchers/notifications_matcher.rb', line 5 def initialize(signature) signature.match(/^([^\[]*)\[(.*)\]$/) @expected_resource_type = $1 @expected_resource_name = $2 end |
Instance Method Details
#delayed ⇒ Object
41 42 43 44 |
# File 'lib/chefspec/matchers/notifications_matcher.rb', line 41 def delayed @delayed = true self end |
#description ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/chefspec/matchers/notifications_matcher.rb', line 46 def description = %Q{notify "#{@expected_resource_type}[#{@expected_resource_name}]"} << " with action :#{@action}" if @action << " immediately" if @immediately << " delayed" if @delayed end |
#failure_message_for_should ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/chefspec/matchers/notifications_matcher.rb', line 54 def if @resource = %Q{expected "#{resource_name(@resource)}[#{@resource.name}]" to notify "#{@expected_resource_type}[#{@expected_resource_name}]"} << " with action :#{@action}" if @action << " immediately" if @immediately << " delayed" if @delayed << ", but did not." << "\n\n" << "Other notifications were:\n\n#{format_notifications}" << "\n " else = %Q{expected _something_ to notify "#{@expected_resource_type}[#{@expected_resource_name}]"} << " with action :#{@action}" if @action << " immediately" if @immediately << " delayed" if @delayed << ", but the _something_ you gave me was nil! If you are running a test like:" << "\n\n" << " expect(_something_).to notify('...')" << "\n\n" << "Make sure that `_something_` exists, because I got nil" << "\n " end end |
#immediately ⇒ Object
36 37 38 39 |
# File 'lib/chefspec/matchers/notifications_matcher.rb', line 36 def immediately @immediately = true self end |
#matches?(resource) ⇒ Boolean
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/chefspec/matchers/notifications_matcher.rb', line 11 def matches?(resource) @resource = resource if @resource block = Proc.new do |notified| resource_name(notified.resource).to_s == @expected_resource_type && (@expected_resource_name === notified.resource.identity.to_s || @expected_resource_name === notified.resource.name.to_s) && matches_action?(notified) end if @immediately immediate_notifications.any?(&block) elsif @delayed delayed_notifications.any?(&block) else all_notifications.any?(&block) end end end |
#to(action) ⇒ Object
31 32 33 34 |
# File 'lib/chefspec/matchers/notifications_matcher.rb', line 31 def to(action) @action = action.to_sym self end |