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.



289
290
291
# File 'lib/sunspot_matchers/matchers.rb', line 289

def initialize(expected_class)
  @expected_class = expected_class
end

Instance Method Details

#failure_message_for_shouldObject



308
309
310
# File 'lib/sunspot_matchers/matchers.rb', line 308

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

#failure_message_for_should_notObject



312
313
314
# File 'lib/sunspot_matchers/matchers.rb', line 312

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

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


293
294
295
296
# File 'lib/sunspot_matchers/matchers.rb', line 293

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

#search_tupleObject



298
299
300
301
302
# File 'lib/sunspot_matchers/matchers.rb', line 298

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



304
305
306
# File 'lib/sunspot_matchers/matchers.rb', line 304

def search_types
  search_tuple.first
end