Top Level Namespace
Defined Under Namespace
Modules: HashRecursiveMerge
Classes: ExecutableTest, Hash, String, SuccessDefinition, TestCase, Turbo
Instance Method Summary
collapse
Instance Method Details
#generate_command(workflow_path, config) ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/commander.rb', line 65
def generate_command(workflow_path, config)
template = File.read(File.join(File.dirname(File.expand_path(__FILE__)), 'templates/command.erb'))
renderer = ERB.new(template)
puts "Scenario: #{config.name}, test cases: #{config.cases.size}\n".cyan
config.cases.each do |caze|
test_case = TestCase.new({
:name => caze.name,
:url => "#{config.baseurl}/#{caze.path}",
:headers => caze.,
:type => caze.type,
:data_path => "#{workflow_path}/#{caze.data ? caze.data.strip : ''}",
:success => SuccessDefinition.new(caze.success),
:debug => caze.debug
})
command = renderer.result(test_case.get_binding).gsub("\n", " ").strip
test = ExecutableTest.new({
:name => caze.name,
:type => caze.type,
:url => "#{config.baseurl}/#{caze.path}",
:command => command,
:success => SuccessDefinition.new(caze.success)
})
verify(test)
end
end
|
#verfiy_xpath(caze, result) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/commander.rb', line 18
def verfiy_xpath(caze, result)
xmldoc = Document.new(result)
nodes = XPath.match(xmldoc, "#{caze.success.content}")
if nodes != nil
puts "Case: ['#{caze.name}'] passed".green
else
puts "Case: ['#{caze.name}'] failed\nExpected: #{caze.success.content}\nGot: #{result}".red
end
puts "#{caze.type} #{caze.url}\n".cyan
end
|
#verify(caze) ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/commander.rb', line 52
def verify(caze)
result = `#{caze.command}`
case caze.success.type
when 'xpath'
verfiy_xpath(caze, result)
when 'regexp'
verify_regexp(caze, result)
when 'jsonpath'
verify_jsonpath(caze, result)
end
end
|
#verify_jsonpath(caze, result) ⇒ Object
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/commander.rb', line 41
def verify_jsonpath(caze, result)
nodes = JsonPath.on(result, "#{caze.success.content}")
if nodes.size != 0
puts "Case: ['#{caze.name}'] passed".green
else
puts "Case: ['#{caze.name}'] failed\nExpected: #{nodes}\nGot: #{result}".red
end
puts "#{caze.type} #{caze.url}\n".cyan
end
|
#verify_regexp(caze, result) ⇒ Object
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/commander.rb', line 30
def verify_regexp(caze, result)
x = result.match(/#{caze.success.content}/)
if x != nil
puts "Case: ['#{caze.name}'] passed".green
else
puts "Case: ['#{caze.name}'] failed\nExpected: #{caze.success.content}\nGot: #{result}".red
end
puts "#{caze.type} #{caze.url}\n".cyan
end
|