Class: Spec::Rails::Matchers::Observe

Inherits:
Object
  • Object
show all
Defined in:
lib/spec/rails/matchers/observers.rb

Instance Method Summary collapse

Constructor Details

#initialize(expected_model_class) ⇒ Observe

Returns a new instance of Observe.



6
7
8
# File 'lib/spec/rails/matchers/observers.rb', line 6

def initialize(expected_model_class)
  @expected_model_class = expected_model_class
end

Instance Method Details

#descriptionObject



23
24
25
# File 'lib/spec/rails/matchers/observers.rb', line 23

def description
  "observer to be observing #{@expected_model_class.name}"
end

#failure_messageObject



19
20
21
# File 'lib/spec/rails/matchers/observers.rb', line 19

def failure_message
  return "expected #{@observer.name} to observe #{@expected_model_class.name}, but it was not included in [#{@observed_classes.map(&:name).join(', ')}]"
end

#matches?(observer) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
14
15
16
17
# File 'lib/spec/rails/matchers/observers.rb', line 10

def matches?(observer)
  @observer = observer
  if @observer.is_a?(ActiveRecord::Observer)
    @observer = @observer.class
  end
  @observed_classes = observer.observed_classes.flatten
  @observed_classes.include?(@expected_model_class)
end