class ResourceKit::Testing::HaveActionMatchers
Attributes
action[R]
failures[R]
path[R]
verb[R]
Public Class Methods
new(action)
click to toggle source
# File lib/resource_kit/testing/have_action_matchers.rb, line 6 def initialize(action) @action = action @failures = [] end
Public Instance Methods
at_path(path)
click to toggle source
# File lib/resource_kit/testing/have_action_matchers.rb, line 19 def at_path(path) @path = path self end
failure_message()
click to toggle source
# File lib/resource_kit/testing/have_action_matchers.rb, line 43 def failure_message return "expected class to have action #{action}." if failures.empty? failures.map do |validation, expected, got| "expected #{expected} #{validation}, got #{got} instead." end.join('\n') end
handler_codes()
click to toggle source
# File lib/resource_kit/testing/have_action_matchers.rb, line 39 def handler_codes @handler_codes ||= [] end
matches?(subject)
click to toggle source
# File lib/resource_kit/testing/have_action_matchers.rb, line 29 def matches?(subject) action = subject.resources.find_action(self.action) return false unless action %i(check_keys check_path check_verb).inject(true) do |rv, method_name| break false unless send(method_name, action) true end end
that_handles(*codes)
click to toggle source
# File lib/resource_kit/testing/have_action_matchers.rb, line 11 def that_handles(*codes) codes.each do |code| handler_codes << StatusCodeMapper.code_for(code) end self end
with_verb(verb)
click to toggle source
# File lib/resource_kit/testing/have_action_matchers.rb, line 24 def with_verb(verb) @verb = verb self end
Private Instance Methods
check_keys(action)
click to toggle source
# File lib/resource_kit/testing/have_action_matchers.rb, line 54 def check_keys(action) keys = action.handlers.keys unless handler_codes.empty? handler_codes.each do |handler_code| unless keys.include?(handler_code) return failed(:status_code, handler_code, keys) end end end true end
check_path(action)
click to toggle source
# File lib/resource_kit/testing/have_action_matchers.rb, line 68 def check_path(action) return true unless self.path action.path == self.path or failed(:path, self.path, action.path) end
check_verb(action)
click to toggle source
# File lib/resource_kit/testing/have_action_matchers.rb, line 73 def check_verb(action) return true unless self.verb checked_verb = self.verb.kind_of?(String) ? self.verb.downcase.to_sym : self.verb action.verb == checked_verb or failed(:verb, checked_verb, action.verb) end
failed(validation, expected, got)
click to toggle source
# File lib/resource_kit/testing/have_action_matchers.rb, line 79 def failed(validation, expected, got) failures << [validation, expected, got] false end