const chai = require('chai');
const expect = chai.expect;
const stub = require('./support/stub');

const Obstacle = require('../lib/obstacle');
const Ufo = require('../lib/ufo');
const game = require('../lib/game');

describe('Obstacle', function() {
  context('traverse', function() {
    var obstacle = new Obstacle({x: 400, y: 0, width: 50, height: 80});

    it('should increment the obstacle', function() {
      expect(obstacle.x).to.eq(400);
      obstacle.traverse(4);
      expect(obstacle.x).to.eq(396);
    });
  });

  context('draw', function(){
    it('should call fillRect on the canvas', function() {
      game.context = stub().of("fillRect");
      var obstacle = new Obstacle({context: context, x: 400, y: 0, width: 50, height: 80});
      obstacle.draw();
      expect(game.context.fillRect.calls.length).to.eq(1);
    });

    it('should pass the length, width, x, y to fillRect', function(){
      game.context = stub().of("fillRect");
      var obstacle = new Obstacle({context: context, x: 400, y: 0, width: 50, height: 80});
      obstacle.draw();
      expect(game.context.fillRect.calls[0][0]).to.eq(obstacle.x);
      expect(game.context.fillRect.calls[0][1]).to.eq(obstacle.y);
      expect(game.context.fillRect.calls[0][2]).to.eq(obstacle.width);
      expect(game.context.fillRect.calls[0][3]).to.eq(obstacle.height);
    });
  });
});

describe('Ufo', function() {
  context('checkFlight', function() {
    var ufo = new Ufo({x: 60, y: 60, width: 10, height: 10, isFlying: true});

    it('should increment the ufo', function() {
      expect(ufo.y).to.eq(60);
      ufo.checkFlight();
      expect(ufo.y).to.eq(54);
    });
  });

  describe('draw', function(){
    it('should call fillRect on the canvas', function() {
      game.context = stub().of("fillRect");
      var ufo = new Ufo({context: context, x: 60, y: 60, width: 10, height: 10});
      ufo.draw();
      expect(game.context.fillRect.calls.length).to.eq(1);
    });

    it('should pass the length, width, x, y to fillRect', function(){
      game.context = stub().of("fillRect");
      var ufo = new Ufo({context: context, x: 60, y: 60, width: 10, height: 10});
      ufo.draw();
      expect(game.context.fillRect.calls[0][0]).to.eq(ufo.x);
      expect(game.context.fillRect.calls[0][1]).to.eq(ufo.y);
      expect(game.context.fillRect.calls[0][2]).to.eq(ufo.width);
      expect(game.context.fillRect.calls[0][3]).to.eq(ufo.height);
    });
  });
});



game.context.beginPath();
game.context.ellipse(this.x+this.width/2, this.y, this.height/2, this.height/2, 0, 0, 2*Math.PI);
game.context.fill();

@@ -1705,36 +1705,32 @@
 should call fill
-Rect
  on the canvas',
@@ -1771,32 +1771,58 @@
  stub().of(%22
+beginPath%22).of(%22ellipse%22).of(%22
 fill
-Rect
 %22);%0A      va
@@ -1858,33 +1858,33 @@
 text, x: 60, y: 
-6
+3
 0, width: 10, he
@@ -1935,32 +1935,31 @@
 ame.context.
-fillRect
+ellipse
 .calls.lengt
@@ -1959,33 +1959,33 @@
 s.length).to.eq(
-1
+2
 );%0A    %7D);%0A%0A    
@@ -2023,36 +2023,32 @@
 th, x, y to fill
-Rect
 ', function()%7B%0A 
@@ -2074,32 +2074,58 @@
  stub().of(%22
+beginPath%22).of(%22ellipse%22).of(%22
 fill
-Rect
 %22);%0A      va
@@ -2161,33 +2161,33 @@
 text, x: 60, y: 
-6
+3
 0, width: 10, he
@@ -2238,32 +2238,31 @@
 ame.context.
-fillRect
+ellipse
 .calls%5B0%5D%5B0%5D
@@ -2274,16 +2274,28 @@
 eq(ufo.x
++ufo.width/2
 );%0A     
@@ -2311,32 +2311,31 @@
 ame.context.
-fillRect
+ellipse
 .calls%5B0%5D%5B1%5D
@@ -2372,32 +2372,31 @@
 ame.context.
-fillRect
+ellipse
 .calls%5B0%5D%5B2%5D
@@ -2407,21 +2407,24 @@
 .eq(ufo.
-width
+height/2
 );%0A     
@@ -2440,32 +2440,31 @@
 ame.context.
-fillRect
+ellipse
 .calls%5B0%5D%5B3%5D
@@ -2477,24 +2477,26 @@
 q(ufo.height
+/2
 );%0A    %7D);%0A 
@@ -2508,152 +2508,4 @@
 %7D);%0A
-%0A%0A%0Agame.context.beginPath();%0Agame.context.ellipse(this.x+this.width/2, this.y, this.height/2, this.height/2, 0, 0, 2*Math.PI);%0Agame.context.fill();%0A

Fix draw tests for ellipse.