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

Global before/after #7

Open
esad opened this issue Dec 28, 2011 · 4 comments
Open

Global before/after #7

esad opened this issue Dec 28, 2011 · 4 comments

Comments

@esad
Copy link

esad commented Dec 28, 2011

I appreciate the minimalism of bacon, but there should be a possibility to supply before/after blocks that get executed for every context.

Useful for ensuring database changes by previous contexts are rolled back before new contexts are run.

@leahneukirchen
Copy link
Owner

Just put the code before and after the context/describe block...

@esad
Copy link
Author

esad commented Dec 28, 2011

What happens when you have multiple contexts?

On 28.12.2011, at 12:14, Christian [email protected] wrote:

Just put the code before and after the context/describe block...


Reply to this email directly or view it on GitHub:
#7 (comment)

@leahneukirchen
Copy link
Owner

They are run in order... I see, you only want to define the blocks once. Let me think about it.

@esad
Copy link
Author

esad commented Dec 28, 2011

This is my current monkey-patch:

Bacon::Context.class_eval do
  alias_method :__initialize__, :initialize

  define_method(:initialize) do |*args, &block|
    __initialize__(*args, &block)
    self.before do
      DataMapper.auto_migrate!
    end
  end
end

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

No branches or pull requests

2 participants