swiftquick-nimble

Error testing a method that throws an Error in Quick with Nimble


I'm having a problem getting a Nimble matcher correct in testing a method that throws an exception. According to the docs it should be simple. I just need an expectation like this

expect( try somethingThatThrows() ).toNot( throwError() ) 

However with Swift 3 and Xcode 8.2 I'm getting a compiler editor. Here's the context.

describe("Using RealmDatasource") {

   let datastore = RealmDatasource() as Datasource

       it("can retrieve an object") {

           expect( try datastore.getCurrentObject() ).to( throwError() )

       }

}

I get the following error on the 'it' declaration line

Invalid conversion from throwing function of type '() -> () throws to non-throwing function of type '() -> ()'

Solution

  • try using expect with curly brackets { }

    expect { try datastore.getCurrentObject() }.to( throwError() )

    should be working