Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sibling Suites have separate contexts #1164

Merged

Conversation

park9140
Copy link
Contributor

The main context in mocha is currently shared by all suites.

This change makes it so that each suite can add values to it's own context without polluting the shared global context.

This allows a layer of automatic cleanup to occur between test suites. Making after mostly unnecessary if you are using the shared context to store setup rather than using the closure.

@park9140
Copy link
Contributor Author

@travisjeffery or @visionmedia any thoughts on this?

@park9140
Copy link
Contributor Author

@travisjeffery or @visionmedia still looking for input.

@travisjeffery
Copy link
Contributor

seems like a good idea, I'll take a closer look later today

On Tuesday, April 15, 2014, Jonathan Park notifications@github.com wrote:

@travisjeffery https://github.com/travisjeffery or @visionmediahttps://github.com/visionmediastill looking for input.


Reply to this email directly or view it on GitHubhttps://github.com//pull/1164#issuecomment-40486992
.

@benvinegar
Copy link
Contributor

+1

@park9140
Copy link
Contributor Author

@travisjeffery, Thanks for looking at this, if you have any changes you would like, I can surely get some time today to resolve them.

@park9140
Copy link
Contributor Author

@travisjeffery I just realized that I should just leave all the original tests in place rather than trying to intermix the sibling tests. Should I break the sibling tests into a separate file as well?

@travisjeffery
Copy link
Contributor

@park9140 no keep them in one context file

@park9140
Copy link
Contributor Author

@travisjeffery, cool, I'll leave it as is then.

@travisjeffery
Copy link
Contributor

@park9140 ok and can you squash these commits into a single commit and force push your branch

@park9140
Copy link
Contributor Author

@travisjeffery, done

travisjeffery added a commit that referenced this pull request Apr 17, 2014
…ontext

Make sibling Suites have separate contexts
@travisjeffery travisjeffery merged commit ca35545 into mochajs:master Apr 17, 2014
@travisjeffery
Copy link
Contributor

awesome thanks

@moll
Copy link

moll commented Apr 20, 2014

Why not use Object.create instead of the prototype+new thing you did in the code?

@park9140 park9140 deleted the sibling-suites-have-separate-context branch April 20, 2014 14:37
@onetom
Copy link

onetom commented Jul 14, 2014

Since there is no cross talk between it steps, is it recommended to use the test context instead of closure variables to share state?

describe 'Something', ->
    user = null
    before -> user = Factory.build 'User'
    it '', -> expect( user.name ).to.be.not.empty

vs

describe 'Something', ->
    before -> @user = Factory.build 'User'
    it '', -> expect( @user.name ).to.be.not.empty

@onetom
Copy link

onetom commented Jul 14, 2014

To me this seem to allow to use mocha finally, properly as an integration test framework too, not just as a unit test one, is that correct?

With mocha --ui exports I can write something like:

'Feature: Scratch my head':
    before -> @head = new Head
    'Scenario: From the left':
        'Given my head itches': -> @head.itch = true
        'When I scratch it': -> ...
    'Scenario: From the right':

@travisjeffery
Copy link
Contributor

@onetom #1164 (comment) - either's fine. #1164 (comment) - probably could of used mocha before, but sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants