Permalink
Browse files

Adding toHaveColor matcher and new mouseEnter action.

Also, adding a few more specs to the example game project. :)
  • Loading branch information...
1 parent 00b5815 commit 9fea1b415d995b00638eac96362edecf34933d4c Caleb Cohoon committed Apr 16, 2012
View
Binary file not shown.
@@ -147,6 +147,20 @@ class Matcher {
return this;
}
+
+ function toHaveColor(color) {
+ if(_negate) {
+ if(_actual.renderer.material.color == color) {
+ failed('expected ' + _actual.name + ' not to have color ' + color);
+ }
+ } else {
+ if(_actual.renderer.material.color != color) {
+ failed('expected ' + _actual.name + ' to have color ' + color);
+ }
+ }
+
+ return this;
+ }
function not() {
_negate = true;
@@ -7,6 +7,10 @@ class Selector {
function moveTo(x, y, z) {
_gameObject.transform.position = new Vector3(x, y, z);
}
+
+ function mouseEnter(scriptName) {
+ _gameObject.GetComponent(scriptName).OnMouseEnter();
+ }
function gameObject() {
return _gameObject;
@@ -0,0 +1,3 @@
+function OnMouseEnter() {
+ renderer.material.color = Color.blue;
+}
@@ -2,15 +2,31 @@ class Specs extends Gunpowder {
function run() {
describe('Pizza Eater', function() {
describe('main menu', function() {
- beforeEach(function() {
- loadScene('menu');
- });
+ beforeEach(function() { loadScene('menu'); });
it('plays the awesome intro music');
- it('shows a start game link');
+ it('shows a start game link', function() {
+ expect(find('Start Link')).toExist();
+ });
- it('shows a quit game link');
+ it('shows a quit game link', function() {
+ expect(find('Quit Link')).toExist();
+ });
+
+ context('hovering over the links', function() {
+ it('adds a blue highlight to the start link', function() {
+ var startLink = find('Start Link');
+ startLink.mouseEnter('Menu');
+ expect(startLink).toHaveColor(Color.blue);
+ });
+
+ it('adds a blue highlight to the quit link', function() {
+ var quitLink = find('Quit Link');
+ quitLink.mouseEnter('Menu');
+ expect(quitLink).toHaveColor(Color.blue);
+ });
+ });
context('seleting start game', function() {
it('starts the game');
Binary file not shown.
@@ -147,6 +147,20 @@ class Matcher {
return this;
}
+
+ function toHaveColor(color) {
+ if(_negate) {
+ if(_actual.renderer.material.color == color) {
+ failed('expected ' + _actual.name + ' not to have color ' + color);
+ }
+ } else {
+ if(_actual.renderer.material.color != color) {
+ failed('expected ' + _actual.name + ' to have color ' + color);
+ }
+ }
+
+ return this;
+ }
function not() {
_negate = true;
@@ -7,6 +7,10 @@ class Selector {
function moveTo(x, y, z) {
_gameObject.transform.position = new Vector3(x, y, z);
}
+
+ function mouseEnter(scriptName) {
+ _gameObject.GetComponent(scriptName).OnMouseEnter();
+ }
function gameObject() {
return _gameObject;
View
@@ -151,6 +151,20 @@ class Specs extends Gunpowder {
expect(match(find('box')).not().toBeHidden()).toFail();
});
});
+
+ describe('toHaveColor', function() {
+ it('has the correct color', function() {
+ var box = find('box');
+ box.gameObject().renderer.material.color = Color.red;
+ expect(match(box).toHaveColor(Color.red)).toPass();
+ });
+
+ it('does not have the correct color', function() {
+ var box = find('box');
+ box.gameObject().renderer.material.color = Color.red;
+ expect(match(box).toHaveColor(Color.blue)).toFail();
+ });
+ });
});
describe('helpers', function() {
@@ -188,11 +202,11 @@ class Specs extends Gunpowder {
it('can run multiple movements in a single spec', function() {
move('backward', 100, function() {
- expect(find('player')).toHavePosition(1.1, 0.5, -13.0, 0.5);
+ expect(find('player')).toHavePosition(1.1, 0.5, -13.0, 0.8);
});
move('left', 100, function() {
- expect(find('player')).toHavePosition(1.1, 0.5, -14.0, 0.5);
+ expect(find('player')).toHavePosition(1.1, 0.5, -14.0, 0.8);
});
});
});
@@ -233,6 +247,14 @@ class Specs extends Gunpowder {
});
});
});
+
+ describe('mouseEnter', function() {
+ it('triggers the OnMouseEnter on the object', function() {
+ var ball = find('ball');
+ ball.mouseEnter('ball');
+ expect(ball).toHaveColor(Color.green);
+ });
+ });
});
describe('resetting the scene', function() {
@@ -2,4 +2,8 @@ function Update() {
if(Gunpowder.Input.GetButton('Fire1')) {
renderer.enabled = false;
}
+}
+
+function OnMouseEnter() {
+ renderer.material.color = Color.green;
}
Binary file not shown.

0 comments on commit 9fea1b4

Please sign in to comment.