Class: SpecViews::BaseMatcher

Inherits:
Object
  • Object
show all
Defined in:
app/models/spec_views/base_matcher.rb

Direct Known Subclasses

HtmlMatcher, PdfMatcher

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response, description, run_time:, expected_status: :ok, sanitizer: nil, type: :request) ⇒ BaseMatcher

Returns a new instance of BaseMatcher.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/models/spec_views/base_matcher.rb', line 9

def initialize(response, description, run_time:, expected_status: :ok, sanitizer: nil, type: :request)
  @response = response
  @type = type
  @sanitizer = sanitizer
  @extractor = extractor_class.new(response, expected_status: expected_status)
  @directory = SpecViews::Directory.for_description(description, content_type: content_type)
  @extractor_failure = @extractor.extractor_failure?
  @match = !extractor_failure? && match_challenger
  directory.write_last_run(run_time) if champion_html
  return if match?

  if extractor_failure?
    @failure_message = @extractor.failure_message
    return
  end

  @failure_message = "#{subject_name} has changed."
  @failure_message = "#{subject_name} has been added." if champion_html.nil?

  directory.write_last_run(run_time)
  directory.write_meta(description, type, content_type)
  @directory.write_challenger(challenger_body)
end

Instance Attribute Details

#directoryObject (readonly)

Returns the value of attribute directory.



5
6
7
# File 'app/models/spec_views/base_matcher.rb', line 5

def directory
  @directory
end

#failure_messageObject (readonly)

Returns the value of attribute failure_message.



5
6
7
# File 'app/models/spec_views/base_matcher.rb', line 5

def failure_message
  @failure_message
end

#responseObject (readonly)

Returns the value of attribute response.



5
6
7
# File 'app/models/spec_views/base_matcher.rb', line 5

def response
  @response
end

#sanitizerObject (readonly)

Returns the value of attribute sanitizer.



5
6
7
# File 'app/models/spec_views/base_matcher.rb', line 5

def sanitizer
  @sanitizer
end

#typeObject (readonly)

Returns the value of attribute type.



5
6
7
# File 'app/models/spec_views/base_matcher.rb', line 5

def type
  @type
end

Instance Method Details

#extractor_failure?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'app/models/spec_views/base_matcher.rb', line 37

def extractor_failure?
  @extractor_failure
end

#match?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'app/models/spec_views/base_matcher.rb', line 33

def match?
  @match
end