class RSpec::LiveControllers::Matchers::Base
Attributes
actual_matcher[R]
list_of_matchers[R]
response_body[R]
target_response[R]
Public Class Methods
new(actual_matcher)
click to toggle source
# File lib/rspec/live_controllers/matchers/base.rb, line 7 def initialize(actual_matcher) @actual_matcher = actual_matcher end
Public Instance Methods
failure_message()
click to toggle source
# File lib/rspec/live_controllers/matchers/base.rb, line 20 def failure_message raise 'Not implemented' end
failure_message_when_negated()
click to toggle source
# File lib/rspec/live_controllers/matchers/base.rb, line 24 def failure_message_when_negated raise 'Not implemented' end
matches?(target_response)
click to toggle source
# File lib/rspec/live_controllers/matchers/base.rb, line 11 def matches?(target_response) @target_response = target_response @response_body = extract_response_body(target_response) row = target_response_row(actual_matcher) json = target_response_json(actual_matcher) string = target_response_string(actual_matcher) check_matches?(response_body, row, json, string) end
Protected Instance Methods
check_matches?(response_body, *matchers)
click to toggle source
# File lib/rspec/live_controllers/matchers/base.rb, line 53 def check_matches?(response_body, *matchers) @list_of_matchers = matchers.compact list_of_matchers.reduce(false) do |acc, value| reg = Regexp.quote(value) acc ||= response_body.match?(regexp(reg)) end end
extract_response_body(target_response)
click to toggle source
# File lib/rspec/live_controllers/matchers/base.rb, line 43 def extract_response_body(target_response) if target_response.is_a?(ActionDispatch::Response::Buffer) target_response.instance_variable_get(:@buf).join('') end end
regexp(reg)
click to toggle source
# File lib/rspec/live_controllers/matchers/base.rb, line 49 def regexp(reg) raise 'Not implemented' end
target_response_json(actual_matcher)
click to toggle source
# File lib/rspec/live_controllers/matchers/base.rb, line 30 def target_response_json(actual_matcher) return unless actual_matcher.respond_to?(:to_json) actual_matcher.to_json end
target_response_row(actual_matcher)
click to toggle source
# File lib/rspec/live_controllers/matchers/base.rb, line 39 def target_response_row(actual_matcher) return actual_matcher if actual_matcher.is_a?(String) || actual_matcher.is_a?(Regexp) end
target_response_string(actual_matcher)
click to toggle source
# File lib/rspec/live_controllers/matchers/base.rb, line 35 def target_response_string(actual_matcher) actual_matcher.to_s end