Class: RSpec::Matchers::BuiltIn::Include

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec-solr/include_documents_matcher.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object (private)



106
107
108
109
110
111
112
113
114
115
# File 'lib/rspec-solr/include_documents_matcher.rb', line 106

def method_missing(method, *args, &block)
  if method =~ /documents?/ || method =~ /results?/
    @collection_name = method
    @args = args
    @block = block
    self
  else
    super.method_missing
  end
end

Instance Method Details

#before(expected) ⇒ Object

chain method for .should include().before()

sets @before_expected for use in perform_match method

Returns:

  • self - “each method must return self in order to chain methods together”



28
29
30
31
32
# File 'lib/rspec-solr/include_documents_matcher.rb', line 28

def before(expected)
  # get first doc position by calling has_document ???
  @before_expected = expected
  self
end

#failure_messageObject

override failure message for improved readability



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/rspec-solr/include_documents_matcher.rb', line 35

def failure_message
  assert_ivars :@actual, :@expecteds
  name_to_sentence = 'include'
  # FIXME: DRY up these messages across cases and across should and should_not
  if @before_expected
    "expected response to #{name_to_sentence} #{doc_label_str(@expecteds)}#{to_sentence(@expecteds)} before #{doc_label_str(@before_expected)} matching #{@before_expected.inspect}: #{@actual.inspect} "
  elsif @min_for_last_matching_doc_pos
    "expected each of the first #{@min_for_last_matching_doc_pos} documents to #{name_to_sentence}#{to_sentence(@expecteds)} in response: #{@actual.inspect}"
  elsif @max_doc_position
    "expected response to #{name_to_sentence} #{doc_label_str(@expecteds)}#{to_sentence(@expecteds)} in first #{@max_doc_position} results: #{@actual.inspect}"
  else
    super
  end
end

#failure_message_when_negatedObject

override failure message for improved readability



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/rspec-solr/include_documents_matcher.rb', line 51

def failure_message_when_negated
  assert_ivars :@actual, :@expecteds
  name_to_sentence = 'include'
  if @before_expected
    "expected response not to #{name_to_sentence} #{doc_label_str(@expecteds)}#{to_sentence(@expecteds)} before #{doc_label_str(@before_expected)} matching #{@before_expected.inspect}: #{@actual.inspect} "
  elsif @min_for_last_matching_doc_pos
    "expected some of the first #{@min_for_last_matching_doc_pos} documents not to #{name_to_sentence}#{to_sentence(@expecteds)} in response: #{@actual.inspect}"
  elsif @max_doc_position
    "expected response not to #{name_to_sentence} #{doc_label_str(@expecteds)}#{to_sentence(@expecteds)} in first #{@max_doc_position} results: #{@actual.inspect}"
  else
    super
  end
end

#in_each_of_first(num = 1) ⇒ Object

chain method for .should include().in_each_of_first(n)

sets @min_for_last_matching_doc_ix for use in perform_match method

Returns:

  • self - “each method must return self in order to chain methods together”



20
21
22
23
# File 'lib/rspec-solr/include_documents_matcher.rb', line 20

def in_each_of_first(num = 1)
  @min_for_last_matching_doc_pos = num
  self
end

#in_first(num = 1) ⇒ Object Also known as: as_first

chain method for .should include().in_first(n)

sets @max_doc_position for use in perform_match method

Returns:

  • self - “each method must return self in order to chain methods together”



10
11
12
13
# File 'lib/rspec-solr/include_documents_matcher.rb', line 10

def in_first(num = 1)
  @max_doc_position = num
  self
end