Permalink
Browse files

Refactor the class stubbing/mocking fix and add some specs.

  • Loading branch information...
1 parent e4b2feb commit 4bc5bf2490d493efa90cd4f23adce3d5c1ef3093 @arthurschreiber committed Sep 9, 2012
Showing with 22 additions and 6 deletions.
  1. +8 −3 lib/spec/mocks/nx/method_double.tcl
  2. +14 −3 spec/mocks/nx/method_double_spec.tcl
@@ -33,16 +33,21 @@ namespace eval Spec::Mocks::nx {
return "public"
} else {
set definition [${:object} info method definition ${:message_name}]
-
if { $definition == "" } {
set definition [[${:object} info class] info method definition ${:message_name}]
}
if { $definition != "" } {
- return "[lindex $definition 1][expr {[${:object} info class] == "::nx::Class" ? " class" : ""}]"
+ set visibility [list [lindex $definition 1]]
} else {
- return "public[expr {[${:object} info class] == "::nx::Class" ? " class" : ""}]"
+ set visibility [list "public"]
+ }
+
+ if { [${:object} info class] == "::nx::Class" } {
+ lappend visibility "class"
}
+
+ return $visibility
}
}
@@ -2,7 +2,11 @@ source [file join [file dirname [info script]] ".." ".." "spec_helper.tcl"]
describe "::Spec::Mocks::nx::MethodDouble" {
before each {
- set object [nx::Object new {
+ set class [nx::Class new {
+ :class method example_class_method {} {
+ return "original"
+ }
+
:public method example_method {} {
return "original"
}
@@ -16,14 +20,16 @@ describe "::Spec::Mocks::nx::MethodDouble" {
}
}]
+ set object [$class new]
+
set proxy [::Spec::Mocks::nx::Proxy new -object $object]
set method_double [::Spec::Mocks::nx::MethodDouble new -object $object -message_name "example_method" -proxy $proxy]
}
describe "#visibility" {
it "returns 'public' for a public method" {
- set method_double [::Spec::Mocks::nx::MethodDouble new -object $object -message_name "public_example_method" -proxy $proxy]
+ set method_double [::Spec::Mocks::nx::MethodDouble new -object $object -message_name "example_method" -proxy $proxy]
expect [$method_double visibility] to equal "public"
}
@@ -36,6 +42,11 @@ describe "::Spec::Mocks::nx::MethodDouble" {
set method_double [::Spec::Mocks::nx::MethodDouble new -object $object -message_name "protected_example_method" -proxy $proxy]
expect [$method_double visibility] to equal "protected"
}
+
+ it "returns 'public class' for a class method" {
+ set method_double [::Spec::Mocks::nx::MethodDouble new -object $class -message_name "example_class_method" -proxy $proxy]
+ expect [$method_double visibility] to equal [list "public" "class"]
+ }
}
describe "#configure_method" {
@@ -58,4 +69,4 @@ describe "::Spec::Mocks::nx::MethodDouble" {
}
}
}
-}
+}

0 comments on commit 4bc5bf2

Please sign in to comment.