Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 '() -> ()'
like image 803
Rocket Garden Avatar asked Dec 13 '16 15:12

Rocket Garden


1 Answers

try using expect with curly brackets { }

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

should be working

like image 132
Fishman Avatar answered Nov 04 '22 04:11

Fishman