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

Add Eager def (similiar to rspec's let!) #138

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

rinslow
Copy link

@rinslow rinslow commented Jul 12, 2021

Solves

This PR Solves #113

Context

This PR allows you to specify a def with {lazy: false} to make it eagerly evaluate instead of lazily.
This is very similiar to how let and let! are different in the RSpec library.

My use case for this feature is a sequelize ORM creation of an object.
Not all its needs the id of the object or even the object at all, because they are testing other side effects of the call. (for example, validations, errors being thrown, HTTP calls being sent out).
Some however, do test the object.

@@ -7,23 +7,33 @@ module.exports = (context, tracker, options) => {

get.definitionOf = get.variable = (varName) => get.bind(null, varName);

function def(varName, definition) {
function def(varName, definition, defOptions = {}) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function def(varName, definition, defOptions = {}) {
function def(varName, definition, defOptions = {lazy: true}) {

@newhouse
Copy link

Not that my opinion matters much, but as a user who would like to see this feature, I'd imagined it being more of a whole new keyword/method rather than an option passed to the existing ’def’ method. It feels kinda verbose to have to do that for each one and if my tests already have a ’beforeEach’ I'd likely still just leave the options out and call them in there.

I dunno. Just my thoughts. Perhaps this is good but also alias it somehow? ’deff’? ’defE’?

@yard
Copy link

yard commented Mar 14, 2022

How about following given2 suite and add an exclamation mark:

def('myEagerVar!', () => Math.random())

On the PR, I think the evaluation should happen in beforeEach hook – you might be relying on some setup done there, plus it's needed to re-evaluate the variable between runs.

@rinslow
Copy link
Author

rinslow commented May 26, 2022

Hey everyone! thanks for the comments :) loved your ideas
Can I please get a comment from the code owner? It's been more than a year and I don't know if this is the right direction in the owners eyes. @stalniy

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.

None yet

3 participants