Class: Webspicy::Tester::Asserter

Inherits:
Object
  • Object
show all
Defined in:
lib/webspicy/tester/asserter.rb

Defined Under Namespace

Classes: AssertionsClass

Constant Summary collapse

NO_ARG =
Object.new

Instance Method Summary collapse

Constructor Details

#initialize(target) ⇒ Asserter

Returns a new instance of Asserter.



11
12
13
14
# File 'lib/webspicy/tester/asserter.rb', line 11

def initialize(target)
  @target = target
  @assertions = AssertionsClass.new
end

Instance Method Details

#empty(path = '') ⇒ Object



42
43
44
45
46
# File 'lib/webspicy/tester/asserter.rb', line 42

def empty(path = '')
  unless @assertions.empty(@target, path)
    _! "Expected #{_s(@target, path)} to be empty"
  end
end

#eq(path, expected = NO_ARG) ⇒ Object



111
112
113
114
115
# File 'lib/webspicy/tester/asserter.rb', line 111

def eq(path, expected = NO_ARG)
  path, expected = '', path if expected == NO_ARG
  target = @assertions.extract_path(@target, path)
  Predicate.eq(target, expected).assert!
end

#eql(path, expected = NO_ARG) ⇒ Object



117
118
119
120
121
# File 'lib/webspicy/tester/asserter.rb', line 117

def eql(path, expected = NO_ARG)
  path, expected = '', path if expected == NO_ARG
  target = @assertions.extract_path(@target, path)
  Predicate.eq(target, expected).assert!
end

#exists(path = '') ⇒ Object



30
31
32
33
34
# File 'lib/webspicy/tester/asserter.rb', line 30

def exists(path = '')
  unless @assertions.exists(@target, path)
    _! "Expected #{_s(@target, path)} to exists"
  end
end

#idFD(path, id, expected = NO_ARG) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/webspicy/tester/asserter.rb', line 76

def idFD(path, id, expected = NO_ARG)
  if expected == NO_ARG
    expected = id
    id, path = path, ''
  end
  element = @assertions.element_with_id(@target, path, id)
  unless element
    _! "Expected an element with id #{id} to contain the key(s) and value(s) #{expected}, but there is no element with that id"
  end

  unless @assertions.idFD(element, expected)
    _! "Expected #{_s(@target, path)} to contain the key(s) and value(s) #{expected}"
  end
end

#idIn(path, *expected) ⇒ Object



62
63
64
65
66
67
# File 'lib/webspicy/tester/asserter.rb', line 62

def idIn(path, *expected)
  path, expected = '', [path]+expected unless path.is_a?(String)
  unless @assertions.idIn(@target, path, expected)
    _! "Expected #{_s(@target, path)} to have ids #{expected.join(',')}"
  end
end

#idNotIn(path, *expected) ⇒ Object



69
70
71
72
73
74
# File 'lib/webspicy/tester/asserter.rb', line 69

def idNotIn(path, *expected)
  path, expected = '', [path]+expected unless path.is_a?(String)
  unless @assertions.idNotIn(@target, path, expected)
    _! "Expected #{_s(@target, path)} to not have ids #{expected.join(',')}"
  end
end

#includes(path, expected = NO_ARG) ⇒ Object



16
17
18
19
20
21
# File 'lib/webspicy/tester/asserter.rb', line 16

def includes(path, expected = NO_ARG)
  path, expected = '', path if expected == NO_ARG
  unless @assertions.includes(@target, path, expected)
    _! "Expected #{_s(@target, path)} to include #{expected}"
  end
end

#match(path, expected = NO_ARG) ⇒ Object



97
98
99
100
101
102
# File 'lib/webspicy/tester/asserter.rb', line 97

def match(path, expected = NO_ARG)
  path, expected = '', path if expected == NO_ARG
  unless @assertions.match(@target, path, expected)
    _! "Expected #{_s(@target, path)} to match #{expected.inspect}"
  end
end

#notEmpty(path = '') ⇒ Object



48
49
50
51
52
# File 'lib/webspicy/tester/asserter.rb', line 48

def notEmpty(path = '')
  unless @assertions.notEmpty(@target, path)
    _! "Expected #{_s(@target, path)} to be non empty"
  end
end

#notExists(path = '') ⇒ Object



36
37
38
39
40
# File 'lib/webspicy/tester/asserter.rb', line 36

def notExists(path = '')
  unless @assertions.notExists(@target, path)
    _! "Expected #{_s(@target, path)} not to exists"
  end
end

#notIncludes(path, expected = NO_ARG) ⇒ Object



23
24
25
26
27
28
# File 'lib/webspicy/tester/asserter.rb', line 23

def notIncludes(path, expected = NO_ARG)
  path, expected = '', path if expected == NO_ARG
  unless @assertions.notIncludes(@target, path, expected)
    _! "Expected #{_s(@target, path)} not to include #{expected}"
  end
end

#notMatch(path, expected = NO_ARG) ⇒ Object



104
105
106
107
108
109
# File 'lib/webspicy/tester/asserter.rb', line 104

def notMatch(path, expected = NO_ARG)
  path, expected = '', path if expected == NO_ARG
  unless @assertions.notMatch(@target, path, expected)
    _! "Expected #{_s(@target, path)} not to match #{expected.inspect}"
  end
end

#pathFD(path, expected) ⇒ Object



91
92
93
94
95
# File 'lib/webspicy/tester/asserter.rb', line 91

def pathFD(path, expected)
  unless @assertions.pathFD(@target, path, expected)
    _! "Expected #{_s(@target, path)} to contain the key(s) and value(s) #{expected}"
  end
end

#size(path, expected = NO_ARG) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/webspicy/tester/asserter.rb', line 54

def size(path, expected = NO_ARG)
  path, expected = '', path if expected == NO_ARG
  unless @assertions.size(@target, path, expected)
    actual = @assertions.actual_size(@target, path)
    _! "Expected #{_s(@target, path)} to have a size of #{expected}, actual size is: #{actual}"
  end
end