Class: CustomRspecMatchers::Matchers::CallbackMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/custom_rspec_matchers/matchers/callback_matcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(kind, callback_on, method) ⇒ CallbackMatcher

Returns a new instance of CallbackMatcher.



4
5
6
7
8
# File 'lib/custom_rspec_matchers/matchers/callback_matcher.rb', line 4

def initialize(kind, callback_on, method)
  @kind = kind
  @callback_on = callback_on
  @method = method
end

Instance Method Details

#descriptionObject



15
16
17
# File 'lib/custom_rspec_matchers/matchers/callback_matcher.rb', line 15

def description
  " has #{@kind}_#{@callback_on} callback on #{@method}"
end

#failure_messageObject



19
20
21
# File 'lib/custom_rspec_matchers/matchers/callback_matcher.rb', line 19

def failure_message
  msg = " expected to have #{@kind}_#{@callback_on} callback on #{@method}"
end

#matches?(model) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
# File 'lib/custom_rspec_matchers/matchers/callback_matcher.rb', line 10

def matches?(model)
  @callbacks = model.send("_#{@callback_on}_callbacks").find_all {|cb| cb.kind == @kind && cb.raw_filter == @method}
  @callbacks.size == 1
end