Class: SunspotMatchers::BeASearchFor

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

Instance Method Summary collapse

Constructor Details

#initialize(expected_class) ⇒ BeASearchFor

Returns a new instance of BeASearchFor.



291
292
293
# File 'lib/sunspot_matchers/matchers.rb', line 291

def initialize(expected_class)
  @expected_class = expected_class
end

Instance Method Details

#descriptionObject



318
319
320
# File 'lib/sunspot_matchers/matchers.rb', line 318

def description
  "be a search for #{@expected_class}"
end

#failure_messageObject



310
311
312
# File 'lib/sunspot_matchers/matchers.rb', line 310

def failure_message
  "expected search class: #{search_types.join(' and ')} to match expected class: #{@expected_class}"
end

#failure_message_when_negatedObject



314
315
316
# File 'lib/sunspot_matchers/matchers.rb', line 314

def failure_message_when_negated
  "expected search class: #{search_types.join(' and ')} NOT to match expected class: #{@expected_class}"
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


295
296
297
298
# File 'lib/sunspot_matchers/matchers.rb', line 295

def matches?(actual)
  @actual = actual
  search_types.include?(@expected_class)
end

#search_tupleObject



300
301
302
303
304
# File 'lib/sunspot_matchers/matchers.rb', line 300

def search_tuple
  search_tuple = @actual.is_a?(Array) ? @actual : @actual.searches.last
  raise 'no search found' unless search_tuple
  search_tuple
end

#search_typesObject



306
307
308
# File 'lib/sunspot_matchers/matchers.rb', line 306

def search_types
  search_tuple.first
end