Class: ChefSpec::Matchers::NotificationsMatcher
- Inherits:
-
Object
- Object
- ChefSpec::Matchers::NotificationsMatcher
- Includes:
- Normalize
- Defined in:
- lib/chefspec/matchers/notifications_matcher.rb
Instance Method Summary collapse
- #before ⇒ Object
- #delayed ⇒ Object
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ 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
#before ⇒ Object
48 49 50 51 |
# File 'lib/chefspec/matchers/notifications_matcher.rb', line 48 def before @before = true self end |
#delayed ⇒ Object
43 44 45 46 |
# File 'lib/chefspec/matchers/notifications_matcher.rb', line 43 def delayed @delayed = true self end |
#description ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/chefspec/matchers/notifications_matcher.rb', line 53 def description = %Q{notify "#{@expected_resource_type}[#{@expected_resource_name}]"} << " with action :#{@action}" if @action << " immediately" if @immediately << " delayed" if @delayed << " before" if @before end |
#failure_message ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/chefspec/matchers/notifications_matcher.rb', line 62 def if @resource = %Q{expected "#{@resource}" to notify "#{@expected_resource_type}[#{@expected_resource_name}]"} << " with action :#{@action}" if @action << " immediately" if @immediately << " delayed" if @delayed << " before" if @before << ", 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 << " before" if @before << ", 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 |
#failure_message_when_negated ⇒ Object
90 91 92 93 94 95 96 |
# File 'lib/chefspec/matchers/notifications_matcher.rb', line 90 def if @resource = %Q{expected "#{@resource}" to not notify "#{@expected_resource_type}[#{@expected_resource_name}]"} << ", but it did." end end |
#immediately ⇒ Object
38 39 40 41 |
# File 'lib/chefspec/matchers/notifications_matcher.rb', line 38 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 30 31 |
# 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) elsif @before before_notifications.any?(&block) else all_notifications.any?(&block) end end end |
#to(action) ⇒ Object
33 34 35 36 |
# File 'lib/chefspec/matchers/notifications_matcher.rb', line 33 def to(action) @action = action.to_sym self end |