Quick: BeforeEach not executing - what am I missing?

Created on 18 Dec 2015  路  7Comments  路  Source: Quick/Quick

Hi all,

I'm pretty new to Quick, but I'm having an issue with the most basic of scenarios, hoping someone can point to something very simple I'm doing wrong.

I have the follow spec setup

class TripSpec : QuickSpec
{
    override func spec() {
        describe("a trip") {
            var trip: Trip!
            beforeEach {
                trip = Trip(tripName: "Test Trip", purpose: 0)
                print("Trip Created")
            }
            describe("its distance"){
                context("after adding a segment"){
                    let segment = TripSegment(coordinates: [CLLocationCoordinate2D()], distance: 37.5);
                    trip.addSegment(segment)
                    it("has added distance") {
                        expect(trip.distance).to(beCloseTo(37.5, within:0.1));
                    }
                }
            }
        }
    }
}

The problem I'm having is that the before each doesn't seem to be getting called. When I try to access my variable "trip" in the context and in the it statement, it is nil.

Any help would be much appreciated.

Cheers

JT

question

All 7 comments

Hi @Jtango18 , check out the thread for #426, because I think it's the same thing and the responses to my question outline how things execute. In essence, the code does not run as it reads.

Yup, thanks for the tip, @mark-anders! Awesome to see you help diagnose these issues. :100:

@Jtango18 you'll need to wrap these two lines in a beforeEach:

beforeEach {
    let segment = TripSegment(coordinates: [CLLocationCoordinate2D()], distance: 37.5);
    trip.addSegment(segment)
}

If after reading the above and #426 you still have questions, post them here! :+1:

Hi, sorry to bump this topic again.. I'm trying to understand this same beforeEach in a global way.

My code looks like this:

class CurrencyConfiguration: QuickConfiguration {

    override class func configure(_ configuration: Configuration) {

        print("Begin configure...")

        configuration.beforeEach {
            print("Hey i'm inside configuration.beforeEach")
        }
    }
}

class CurrencyTest: QuickSpec {

    override func spec() {

        describe("Valid Currency") {

            beforeEach {
                print("This is beforeEach in QuickSpec")
            }
            print("Valid Currency is called here.")

        }
    }
}

The result log is:

Begin configure...
Valid Currency is called here.
Test Suite 'All tests' started at 2016-11-15 15:46:47.809
Test Suite 'Quick.framework' started at 2016-11-15 15:46:47.810
Test Suite 'Quick.framework' passed at 2016-11-15 15:46:47.812.
     Executed 0 tests, with 0 failures (0 unexpected) in 0.000 (0.001) seconds
Test Suite 'appTests.xctest' started at 2016-11-15 15:46:47.813
Test Suite 'appTests.xctest' passed at 2016-11-15 15:46:47.813.
     Executed 0 tests, with 0 failures (0 unexpected) in 0.000 (0.001) seconds
Test Suite 'All tests' passed at 2016-11-15 15:46:47.814.
     Executed 0 tests, with 0 failures (0 unexpected) in 0.000 (0.005) seconds


Having wrapped the line with beforeEach, why is the global configuration.beforeEach not called?
I mean, these 2 lines are not printed:
print("Hey i'm inside configuration.beforeEach") and print("This is beforeEach in QuickSpec")

Thanks for your help!

Hey @vinamelody,

beforeEach only executes if there's an it block associated with it to run with.

class CurrencyTest: QuickSpec {

    override func spec() {

        describe("Valid Currency") {

            beforeEach {
                print("This is beforeEach in QuickSpec")
            }
            print("Valid Currency is called here.")

            //
            // This line below will cause beforeEaches to fire
            //
            it("does something") { }
        }
    }
}

@jeffh awesome! that works :) thank you!

No problem! 馃槃

Hey @vinamelody,

beforeEach only executes if there's an it block associated with it to run with.

class CurrencyTest: QuickSpec {

    override func spec() {

        describe("Valid Currency") {

            beforeEach {
                print("This is beforeEach in QuickSpec")
            }
            print("Valid Currency is called here.")

            //
            // This line below will cause beforeEaches to fire
            //
            it("does something") { }
        }
    }
}

Its behavior is a little strange to me.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

abhaythakur picture abhaythakur  路  7Comments

cliren picture cliren  路  3Comments

sunshinejr picture sunshinejr  路  4Comments

TofPlay picture TofPlay  路  3Comments

modocache picture modocache  路  7Comments