module Webspicy::Tester::Assertions
Constants
- NO_ARG
Public Instance Methods
actual_size(target, path)
click to toggle source
# File lib/webspicy/tester/assertions.rb, line 43 def actual_size(target, path) target = extract_path(target, path) respond_to!(target, :size).size end
element_with_id(target, path, id)
click to toggle source
# File lib/webspicy/tester/assertions.rb, line 66 def element_with_id(target, path, id) target = extract_path(target, path) an_array(target).find { |t| t[:id] == id } end
empty(target, path = NO_ARG)
click to toggle source
# File lib/webspicy/tester/assertions.rb, line 29 def empty(target, path = NO_ARG) target = extract_path(target, path) respond_to!(target, :empty?).empty? end
exists(target, path = NO_ARG)
click to toggle source
# File lib/webspicy/tester/assertions.rb, line 19 def exists(target, path = NO_ARG) target = extract_path(target, path) not target.nil? end
extract_path(target, path = NO_ARG)
click to toggle source
# File lib/webspicy/tester/assertions.rb, line 95 def extract_path(target, path = NO_ARG) return target if path.nil? or path==NO_ARG or path.empty? return nil unless target.respond_to?(:[]) path.split('/').inject(target) do |memo,key| memo && (memo.is_a?(Array) ? memo[key.to_i] : memo[key.to_sym]) end end
idFD(element, expected)
click to toggle source
# File lib/webspicy/tester/assertions.rb, line 71 def idFD(element, expected) expected.keys.all? do |k| value_equal(expected[k], element[k]) end end
idIn(target, path, expected = NO_ARG)
click to toggle source
# File lib/webspicy/tester/assertions.rb, line 48 def idIn(target, path, expected = NO_ARG) path, expected = '', path if expected == NO_ARG target = extract_path(target, path) ids = an_array(target).map do |tuple| respond_to!(tuple, :[])[:id] end ids.to_set == expected.to_set end
idNotIn(target, path, expected = NO_ARG)
click to toggle source
# File lib/webspicy/tester/assertions.rb, line 57 def idNotIn(target, path, expected = NO_ARG) path, expected = '', path if expected == NO_ARG target = extract_path(target, path) ids = an_array(target).map do |tuple| respond_to!(tuple, :[])[:id] end (ids.to_set & expected.to_set).empty? end
includes(target, path, expected = NO_ARG)
click to toggle source
# File lib/webspicy/tester/assertions.rb, line 9 def includes(target, path, expected = NO_ARG) path, expected = '', path if expected == NO_ARG target = extract_path(target, path) an_array(target).include?(expected) end
match(target, path, rx)
click to toggle source
# File lib/webspicy/tester/assertions.rb, line 84 def match(target, path, rx) target = extract_path(target, path) !(target.to_s =~ rx).nil? end
notEmpty(target, path = NO_ARG)
click to toggle source
# File lib/webspicy/tester/assertions.rb, line 34 def notEmpty(target, path = NO_ARG) not empty(target, path) end
notExists(target, path = NO_ARG)
click to toggle source
# File lib/webspicy/tester/assertions.rb, line 24 def notExists(target, path = NO_ARG) target = extract_path(target, path) target.nil? end
notIncludes(target, path, expected = NO_ARG)
click to toggle source
# File lib/webspicy/tester/assertions.rb, line 15 def notIncludes(target, path, expected = NO_ARG) not self.includes(target, path, expected) end
notMatch(target, path, rx)
click to toggle source
# File lib/webspicy/tester/assertions.rb, line 89 def notMatch(target, path, rx) !match(target, path, rx) end
pathFD(target, path, expected)
click to toggle source
# File lib/webspicy/tester/assertions.rb, line 77 def pathFD(target, path, expected) target = extract_path(target, path) expected.keys.all?{|k| value_equal(expected[k], target[k]) } end
size(target, path, expected = NO_ARG)
click to toggle source
# File lib/webspicy/tester/assertions.rb, line 38 def size(target, path, expected = NO_ARG) path, expected = '', path if expected == NO_ARG actual_size(target, path) == expected end
Private Instance Methods
an_array(target)
click to toggle source
# File lib/webspicy/tester/assertions.rb, line 112 def an_array(target) target.is_a?(Array) ? target : [target] end
respond_to!(target, method)
click to toggle source
# File lib/webspicy/tester/assertions.rb, line 105 def respond_to!(target, method) unless target.respond_to?(method) raise InvalidArgError, "Expecting instance responding to #{method}" end target end
value_equal(exp, got)
click to toggle source
# File lib/webspicy/tester/assertions.rb, line 116 def value_equal(exp, got) case exp when Hash exp.all?{|(k,v)| got[k] == v } else exp == got end end