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)



100
101
102
103
104
105
106
107
108
109
# File 'lib/rspec-solr/include_documents_matcher.rb', line 100

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”



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

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

#failure_message_for_shouldObject

override failure message for improved readability



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

def failure_message_for_should
  assert_ivars :@actual, :@expected
# 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(@expected)}#{expected_to_sentence} 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.to_s} documents to #{name_to_sentence}#{expected_to_sentence} in response: #{@actual.inspect}"
  elsif @max_doc_position
    "expected response to #{name_to_sentence} #{doc_label_str(@expected)}#{expected_to_sentence} in first #{@max_doc_position.to_s} results: #{@actual.inspect}"
  else
    super
  end
end

#failure_message_for_should_notObject

override failure message for improved readability



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

def failure_message_for_should_not
  assert_ivars :@actual, :@expected
  if @before_expected
    "expected response not to #{name_to_sentence} #{doc_label_str(@expected)}#{expected_to_sentence} 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.to_s} documents not to #{name_to_sentence}#{expected_to_sentence} in response: #{@actual.inspect}"
  elsif @max_doc_position
    "expected response not to #{name_to_sentence} #{doc_label_str(@expected)}#{expected_to_sentence} in first #{@max_doc_position.to_s} 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”



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

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”



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

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