Comments (4)
A few things here:
- You're creating the semaphore with an initial count of 1. This means that the first
dispatch_semaphore_wait
will always complete immediately, which is probably not what you want. - The semaphore isn't recreated each time the
beforeAll
block is run (relevant if it's in adescribe
block). I'd probably move the variable and initialization into there. - If
-loginWithUserName:…
needs to do any work on the main thread — like delivering its results there — it won't be able to, since you'll be blocking on the semaphore.
Instead, if you're also using expecta, you can use the will
matcher to solve all of the above problems:
beforeAll(^{
// This is run once and only once before all of the examples
// in this group and before any beforeEach blocks.
// Set a timeout of 100 sec
setAsyncSpecTimeout(100);
Login *login = [[Login alloc] init];
__block BOOL completed = NO;
[login loginWithUserName:@"user"
passWord:@"pass"
onSuccess:^(id responseObject) {
// Handle successful login
completed = YES;
}
onError:^(NSError *err) {
// Handle error
completed = YES;
}];
expect(completed).will.beTruthy();
});
As a sidenote, 100 seconds is way too long to be waiting for results in a unit test. It's probably safe to say that any more than 10 seconds should be considered a failure.
from specta.
The timeout was left that way because of a very big lag in the first place. I changed that but it doesn't make any difference to the issue.
Yes, I am also using specta but it fails. You could try for yourself the example you gave and see if it fails, for me it does. I added some brakepoints in both success and failure callbacks, they are never called.
Ok, so the semaphore would block, I'll drop it.
Now, following your suggestion I'm having something like this:
// The authToken that will be used in all the tests
__block NSString *authToken = nil;
beforeAll(^{
// This is run once and only once before all of the examples
// in this group and before any beforeEach blocks.
// Set a timeout of 20 sec
setAsyncSpecTimeout(20);
UserSession *sessionManager = [UserSession sharedInstance];
[sessionManager userSessionWithUsername:@"user"
password:@"pass"
success:^(UserSessionData *session) {
// Set the authToken string
authToken = session.authToken;
}
failure:^(NSError *error) {
// Handle the error
}];
expect(authToken).will.beInstanceOf([NSString class]);
});
The will matcher fails. It tries to do the other tests, which also fail, because they make use of the authToken.
from specta.
I added some brakepoints in both success and failure callbacks, they are never called.
This sounds like a problem with the method you're using, then. Does it work in a small sample application?
from specta.
Closing due to lack of a response.
from specta.
Related Issues (20)
- Test results intermittently disappear in the Xcode 7 UI HOT 18
- Test results "arrow button" in Xcode 7 doesn't work correctly for Specta test results HOT 1
- Carthage Binaries HOT 4
- waitUntil hangs when using Specta in XCTest UI Test target HOT 9
- Specta getting stuck when trying to dispatch_sync in the main queue HOT 4
- XCTool support? HOT 14
- Specta fails to build when targeting tvOS HOT 2
- Add watchos support HOT 4
- Hierarchical test results HOT 1
- Cannot build with `rake` on 7.2 <= Xcode < 7.3 on Yosemite and El Cap
- WaitUntil and WaitUntilTimeOut leads to EXC_BAD_ACCESSS HOT 1
- It would be nice if specta had an option to reset the app after each test file completes HOT 1
- Repeating Unit-Tests
- Should fit/fdescribe have other tests show up as pending/failing?
- Tests are skipped nondeterministically
- signal SIGABRT at waiUntilTimeOut function
- No visible @interface for 'XCTestSuite' declares the selector 'run' HOT 5
- Bad access in SPTSharedExampleGroups
- iiccoinsss
- Expecta/EXPDefines.h
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from specta.