 class AVFoundationPlaybackQualityMetricsTests: QuickSpec {
     override func spec() {
         describe(".AVFoundationPlaybackQualityMetricsTests") {
+            
+            var avFoundationPlayback: AVFoundationPlayback!
+            var accessLog: AccessLogEventMock!
+            
             context("when receives AVPlayerItemNewAccessLogEntry event") {
+                
+                beforeEach {
+                    avFoundationPlayback = AVFoundationPlayback(options: [:])
+                    avFoundationPlayback.render()
+                    accessLog = AccessLogEventMock()
+                }
+                
                 context("with new indicatedBitrate value") {
                     it("changes the bitrate") {
                         let baseObject = BaseObject()
                         var bitrate: Double?
-                        let avfoundationPlayback = AVFoundationPlayback(options: [:])
-                        avfoundationPlayback.render()
-                        let accessLog = AccessLogEventMock()
                         let player = PlayerMock(accessLogEvent: accessLog)
                         accessLog.setIndicatedBitrate(7)
-                        avfoundationPlayback.player = player
-                        baseObject.listenToOnce(avfoundationPlayback, eventName: Event.didUpdateBitrate.rawValue) { userInfo in
+                        avFoundationPlayback.player = player
+                        baseObject.listenToOnce(avFoundationPlayback, eventName: Event.didUpdateBitrate.rawValue) { userInfo in
                             bitrate = userInfo?["bitrate"] as? Double
                         }
 
-                        avfoundationPlayback.onAccessLogEntry(notification: nil)
+                        avFoundationPlayback.onAccessLogEntry(notification: nil)
                         
                         expect(bitrate).toEventually(equal(7))
                     }

                
                context("with new observedBitrate value") {
                    it("changes the bandwidth") {
                        let avfoundationPlayback = AVFoundationPlayback(options: [:])
                        avfoundationPlayback.render()
                        let accessLog = AccessLogEventMock()
                        accessLog.setObservedBitrate(13.0)
                        let player = PlayerMock(accessLogEvent: accessLog)
                        avfoundationPlayback.player = player

                        NotificationCenter.default.post(
                            name: .AVPlayerItemNewAccessLogEntry,
                            object: player.currentItem
                        )

                        expect(avfoundationPlayback.bandwidth).toEventually(equal(13.0))
                    }
                }

                describe("droppedFrames") {
                    context("with new numberOfDroppedVideoFrames value") {
                        it("changes the droppedFrames") {
                            let avfoundationPlayback = AVFoundationPlayback(options: [:])
                            avfoundationPlayback.render()
                            let accessLog = AccessLogEventMock()
                            accessLog.setDroppedFrames(2)
                            let player = PlayerMock(accessLogEvent: accessLog)
                            avfoundationPlayback.player = player
                            
                            NotificationCenter.default.post(
                                name: .AVPlayerItemNewAccessLogEntry,
                                object: player.currentItem
                            )
                            
                            expect(avfoundationPlayback.droppedFrames).toEventually(equal(2))
                        }
                        
                        context("when occurs another AVPlayerItemNewAccessLogEntry event") {
                            it("changes the droppedFrames to an accumulated value") {
                                let avfoundationPlayback = AVFoundationPlayback(options: [:])
                                avfoundationPlayback.render()
                                let accessLog = AccessLogEventMock()
                                accessLog.setDroppedFrames(2)
                                let player = PlayerMock(accessLogEvent: accessLog)
                                avfoundationPlayback.player = player
                                
                                NotificationCenter.default.post(
                                    name: .AVPlayerItemNewAccessLogEntry,

                        kSourceUrl: "http://clappr.io/highline.mp4"
                    ]

                    avFoundationPlayback = AVFoundationPlayback(options: options)
                    avFoundationPlayback.render()

                    expect(avFoundationPlayback.decodedFrames).toEventually(equal(-1))
                }
            }
        }
