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 strategy used easier to detect in callbacks #1694

Open
CodeMeister opened this issue Sep 8, 2024 · 0 comments · May be fixed by #1695
Open

Make strategy used easier to detect in callbacks #1694

CodeMeister opened this issue Sep 8, 2024 · 0 comments · May be fixed by #1695
Labels

Comments

@CodeMeister
Copy link

Problem this feature will solve

Like many, I use the same factory with multiple strategies, based on the individual test.

Critically, I want the same code executed on completion, regardless of the strategy used.

With :create also calling :build I need to determine in the :after_build callback if I should execute the code or not.

The strategy can be found with context.instance_variable_get(:@build_strategy).to_sym, but that required a degree of familiarity with the code that most users won't have.

Desired solution

A helper method for the context would simplify the whole process:

factory :user do
  after(:build)   { |user, context| run_this_code() if context.strategy.build?}
  after(:stub)    { |user, context| run_this_code() }
  after(:create)  { |user, context| run_this_code() }
end

Additional context

I'll do a pull request for this feature.

@CodeMeister CodeMeister linked a pull request Sep 8, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant