Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for mocking HTTP::header statements #13

Merged
merged 6 commits into from
Aug 7, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions examples.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@echo off
for %%f in (examples\example_*.tcl) do (
jtcl examples\%%~nf.tcl
)
8 changes: 8 additions & 0 deletions src/irulehttp.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ namespace eval ::testcl::HTTP {
#
proc ::testcl::HTTP::header {cmd args} {
log::log debug "HTTP::header $cmd $args invoked"

set cmdargs [concat HTTP::header $cmd $args]
#set rc [catch { return [::testcl::expected {*}$cmdargs] } res]
set rc [catch { return [eval ::testcl::expected $cmdargs] } res]
if {$rc != 1100} {
log::log debug "skipping header methods evaluation - expectation found for $cmdargs"
return $res
}

variable headers
if { ![array exists headers] } {
Expand Down
11 changes: 8 additions & 3 deletions src/it.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,15 @@ proc ::testcl::reset_expectations { } {
variable verifications
if { [info exists verifications] } {
log::log debug "Reset expected verifications"
set verifications {}
set verifications {}
}
variable headers
if { [info exists headers] } {
log::log debug "Reset HTTP headers"
array unset headers
variable lws
set lws 0
}
log::log debug "Reset HTTP headers"
HTTP::header remove
}

# testcl::before --
Expand Down
52 changes: 41 additions & 11 deletions src/on.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace eval ::testcl {
namespace export endstate
namespace export verify
namespace export unknown
namespace export expected
}

# testcl::on --
Expand Down Expand Up @@ -136,6 +137,45 @@ rename unknown ::tcl::unknown
proc ::testcl::unknown {args} {

log::log debug "unknown called with args: $args"

#set rc [catch { return [::testcl::expected {*}$args] } res]
set rc [catch { return [eval ::testcl::expected $args] } res]
if {$rc != 1100} {
log::log debug "rc from expected: $rc"
if {$rc == 1000} {
return -code 1000 $res
}
return $res
}

set errorMessage "Unexpected unknown command invocation '$args'"
puts "\n$errorMessage\n"
puts "Maybe you should add an \"on\" statement similar to the one below to your \"it\" block?\n"
puts " it \"your description\" \{"
puts " ..."
puts " on $args return \"your return value\""
puts " ..."
puts " \}\n"
error $errorMessage
# TODO?
#uplevel ::tcl::unknown $args
}

# testcl::expected --
#
# verify if there is mock available for command
#
# Arguments:
# Any
#
# Side Effects:
# None
#
# Results:
# Whatever your expectation says
proc ::testcl::expected {args} {

log::log debug "expected called with args: $args"
variable expectations

if { [llength $expectations] > 0 } {
Expand Down Expand Up @@ -168,15 +208,5 @@ proc ::testcl::unknown {args} {
}

}
set errorMessage "Unexpected unknown command invocation '$args'"
puts "\n$errorMessage\n"
puts "Maybe you should add an \"on\" statement similar to the one below to your \"it\" block?\n"
puts " it \"your description\" \{"
puts " ..."
puts " on $args return \"your return value\""
puts " ..."
puts " \}\n"
error $errorMessage
# TODO?
#uplevel ::tcl::unknown $args
return -code 1100 "expectation not found"
}
4 changes: 4 additions & 0 deletions tests.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@echo off
for %%f in (test\test_*.tcl) do (
jtcl test\%%~nf.tcl
)