Skip to content

Commit

Permalink
reset instance variables to prevent rspec leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
e2 committed Oct 27, 2014
1 parent eaabdc9 commit 7758edd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/guard/setuper.rb
Expand Up @@ -38,6 +38,11 @@ module Setuper
#
# @return [Guard] the Guard singleton
#

# TODO: this method has too many instance variables
# and some are mock and leak between tests,
# so ideally there should be a guard "instance"
# object that can be created anew between tests
def setup(opts = {})
reset_options(opts)

Expand Down Expand Up @@ -345,5 +350,17 @@ def _prepare_scope(scope)
def _non_builtin_plugins?
plugins.map(&:name) != ["reevaluator"]
end

def _reset_for_tests
@options = nil
@queue = nil
@runner = nil
@evaluator = nil
@watchdirs = nil
@watchdirs = nil
@listener = nil
@interactor = nil
::Guard.scope = nil
end
end
end
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Expand Up @@ -24,6 +24,7 @@
end

config.before(:each) do |example|
Guard.send(:_reset_for_tests)

Guard.clear_options

Expand Down

0 comments on commit 7758edd

Please sign in to comment.