Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added the Smoke test suite.

  • Loading branch information...
commit 464859bc73354c3f38861e38108e2de32fe1e8d0 1 parent 9f4bc2e
Larry Karnowski authored
View
14 spec/javascripts/fixtures/smoke.mock.html
@@ -0,0 +1,14 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+
+<head>
+ <title>Smoke Mocking | JavaScript Testing Results</title>
+ <link rel="stylesheet" href="../../../generators/blue_ridge/templates/screw.css" type="text/css" charset="utf-8" />
+ <script type="text/javascript" charset="utf-8">var BLUE_RIDGE_LIB_PREFIX = "../../lib/";</script>
+ <script type="text/javascript" src="../../../lib/blue-ridge.js"></script>
+</head>
+
+<body>
+ <!-- Put any HTML fixture elements here. -->
+</body>
+</html>
View
14 spec/javascripts/fixtures/smoke.screw_integration.html
@@ -0,0 +1,14 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+
+<head>
+ <title>Smoke Stubbing | JavaScript Testing Results</title>
+ <link rel="stylesheet" href="../../../generators/blue_ridge/templates/screw.css" type="text/css" charset="utf-8" />
+ <script type="text/javascript" charset="utf-8">var BLUE_RIDGE_LIB_PREFIX = "../../lib/";</script>
+ <script type="text/javascript" src="../../../lib/blue-ridge.js"></script>
+</head>
+
+<body>
+ <!-- Put any HTML fixture elements here. -->
+</body>
+</html>
View
14 spec/javascripts/fixtures/smoke.stub.html
@@ -0,0 +1,14 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+
+<head>
+ <title>Smoke Stubbing | JavaScript Testing Results</title>
+ <link rel="stylesheet" href="../../../generators/blue_ridge/templates/screw.css" type="text/css" charset="utf-8" />
+ <script type="text/javascript" charset="utf-8">var BLUE_RIDGE_LIB_PREFIX = "../../lib/";</script>
+ <script type="text/javascript" src="../../../lib/blue-ridge.js"></script>
+</head>
+
+<body>
+ <!-- Put any HTML fixture elements here. -->
+</body>
+</html>
View
104 spec/javascripts/smoke.mock_spec.js
@@ -0,0 +1,104 @@
+Screw.Unit(function() {
+ describe("mocking", function() {
+ describe("basics", function() {
+ it("allows stubbing directly on mock objects", function() {
+ mockObj = mock().stub('bar').and_return('baz');
+ expect(mockObj.bar()).to(equal, 'baz');
+ });
+
+ it("should check an exact call count", function() {
+ var m = mock()
+ m.should_receive('bar').exactly('twice');
+ m.bar();
+ m.bar();
+ });
+
+ it("should check a minimum call count", function() {
+ var m = mock()
+ m.should_receive('bar').at_least('once');
+ m.bar();
+ });
+
+ it("should check a maximum call count", function() {
+ var m = mock()
+ m.should_receive('bar').at_most(2,'times');
+ m.bar();
+ m.bar();
+ });
+
+ it("should allow return values directly from mocks",function() {
+ var m = mock()
+ m.should_receive('bar').exactly('once').and_return('hello');
+ expect(m.bar()).to(equal, 'hello');
+ });
+ });
+
+ describe("with argument conditions", function() {
+ it("should only mock the exact method signature when with_arguments is used", function() {
+ mockObj = mock()
+ baz = {a:'a dummy obj'}
+ mockObj.should_receive('foo').with_arguments('bar',baz).and_return('foobar');
+ expect(mockObj.foo('bar',baz)).to(equal, 'foobar');
+ });
+ it("should return undefined if the arguments aren't matched", function() {
+ mockObj = mock()
+ mockObj.should_receive('foo').with_arguments('bar').and_return('foobar');
+ expect(mockObj.foo('chicken')).to(equal, undefined);
+ });
+ it("should allow mocking multiple method signatures with different returns", function() {
+ mockObj = mock()
+ mockObj.should_receive('foo').with_arguments('bar').and_return('foobar');
+ mockObj.should_receive('foo').with_arguments('mouse').and_return('cheese');
+ expect(mockObj.foo('mouse')).to(equal, 'cheese');
+ expect(mockObj.foo('bar')).to(equal, 'foobar');
+ });
+ it("should allow mocking a method signature with arguments and setting expectations", function() {
+ mockObj = mock()
+ mockObj.should_receive('foo').with_arguments('bar').exactly('once');
+ mockObj.foo('bar')
+ });
+ });
+
+ describe("added ontop of an existing object", function() {
+ before(function() {
+ obj = { say: "hello", shout: function() { return this.say.toUpperCase(); } }
+ mockObj = mock(obj);
+ });
+
+ it("should leave original properties intact", function() {
+ expect(mockObj.say).to(equal,'hello');
+ });
+
+ it("should leave original functions intact", function() {
+ expect(mockObj.shout()).to(equal,'HELLO');
+ });
+
+ it("should add methods to allow stubbing and mocking on the objects properties", function() {
+ expect(mockObj.should_receive).to_not(equal,undefined);
+ expect(mockObj.stub).to_not(equal,undefined);
+ });
+
+ it("shouldn't break Arrays", function() {
+ mockObj = mock([0,1,2,3]);
+ expect(mockObj[2]).to(equal,2);
+ expect(mockObj.length).to(equal,4);
+ });
+
+ it("should place expectations on existing methods non-destructively", function() {
+ myMock = mock({ say: "hello", shout: function() { return this.say.toUpperCase(); } });
+ myMock.should_receive('shout').exactly('once');
+ expect(myMock.shout()).to(equal,'HELLO');
+ });
+ });
+
+ describe("an objects prototype", function() {
+ it("should allow mocks to be carried through to individual objects", function() {
+ Aobj = function() {};
+ Aobj.prototype = { aFunction: function() {return 'prototype function'} };
+ mock(Aobj.prototype).should_receive('aFunction').exactly('twice');
+ (new Aobj()).aFunction();
+ (new Aobj()).aFunction();
+ });
+ });
+ });
+});
View
17 spec/javascripts/smoke.screw_integration_spec.js
@@ -0,0 +1,17 @@
+Screw.Unit(function() {
+ describe("integrating with Screw.Unit", function() {
+ before(function() {
+ foo = {bar: function(attribute){return 'hello'}, baz:'goodbye'};
+ });
+
+ it("should forward stub() calls to new Stub to allow stub().and_return()", function() {
+ var myStub = stub(foo,'baz')
+ expect(myStub.and_return).to_not(equal, undefined);
+ });
+
+ it("should forward mock() calls to new mock object to allow mock().should_receive()", function() {
+ var myMock = mock(foo);
+ expect(myMock.should_receive).to_not(equal,undefined)
+ });
+ });
+});
View
17 spec/javascripts/smoke.stub_spec.js
@@ -0,0 +1,17 @@
+Screw.Unit(function() {
+ describe("stubbing", function() {
+ before(function() {
+ foo = {bar: function(attribute){return 'hello'}, baz:'goodbye'};
+ });
+
+ it("should return the stubbed value of a property", function() {
+ stub(foo,'baz').and_set_to('baz');
+ expect(foo.baz).to(equal, 'baz');
+ });
+
+ it("should return the stubbed value of a function", function() {
+ stub(foo,'bar').and_return('bar');
+ expect(foo.bar()).to(equal, 'bar');
+ });
+ });
+});
Please sign in to comment.
Something went wrong with that request. Please try again.