summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo k <mo@mokhan.ca>2012-05-21 11:08:49 -0600
committermo k <mo@mokhan.ca>2012-05-21 11:08:49 -0600
commit7e15845e5089850d2882850d288bf6dd298e59e7 (patch)
treecfbbed20c7b4c0588accfd712658234091aeb143
parent1d0e2de27d8716cdfc409e1d16157aa2e53e4f98 (diff)
create simple stub method.
-rw-r--r--spec/javascripts/FakeSpec.js37
1 files changed, 37 insertions, 0 deletions
diff --git a/spec/javascripts/FakeSpec.js b/spec/javascripts/FakeSpec.js
new file mode 100644
index 0000000..0bf6c1b
--- /dev/null
+++ b/spec/javascripts/FakeSpec.js
@@ -0,0 +1,37 @@
+describe ("Fake", function() {
+ beforeEach (function() {
+ sut = new Fake();
+ });
+ var sut;
+ describe ("when stubbing out return values", function() {
+ describe ("when there is no args", function() {
+ it ("should return the correct value", function() {
+ expect(result).toEqual("hello mo");
+ });
+ beforeEach (function() {
+ sut.stub('greet').andReturn('hello mo');
+ result = sut.greet();
+ });
+ var result;
+ });
+ });
+});
+var Fake = (function(){
+ var fake = function(){
+ methods = [];
+ this.stub = function(method){
+ methods.push(method);
+ return this;
+ };
+ this.andReturn = function(return_value){
+ var method = methods[methods.length - 1];
+ console.log(method);
+ this[method] = function(){
+ return return_value;
+ };
+ };
+ };
+ return function(){
+ return new fake();
+ };
+})();