Skip to content

Ability to add custom reloaders to run before running all specs. #43

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
*.gem
.guard-jruby-spec
Gemfile.lock
Gemfile.lock
14 changes: 8 additions & 6 deletions lib/guard/jruby-rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ def initialize(watchers = [], options = {})
:spec_file_suffix => "_spec.rb",
:run_all => {},
:monitor_file => ".guard-jruby-rspec",
:custom_reloaders => []
:custom_reloaders => [],
:custom_reloaders_for_run_all => []
}.merge(options)
@last_failed = false
@failed_paths = []
Expand All @@ -43,7 +44,8 @@ def initialize(watchers = [], options = {})

@inspector = Inspector.new(@options)
@runner = Runner.new(@options)
@reloaders = set_up_reloaders(@options)
@reloaders = set_up_reloaders(@options[:custom_reloaders], [:reload_rails, :reload_paths, :reload_factory_girl])
@runall_reloaders = set_up_reloaders(@options[:custom_reloaders_for_run_all])
end

# Call once when guard starts
Expand All @@ -54,6 +56,7 @@ def start

def run_all
unload_previous_examples
@runall_reloaders.reload
super
end

Expand Down Expand Up @@ -114,11 +117,10 @@ def reload_paths(paths)

private

def set_up_reloaders(options)
def set_up_reloaders(custom_reloaders, reloader_methods=[])
reloaders = Reloaders.new
reloader_methods = [:reload_rails, :reload_paths, :reload_factory_girl]
reloader_procs = reloader_methods.map { |name| method(name) }
reloader_procs += options[:custom_reloaders]
reloader_procs = custom_reloaders
reloader_procs += reloader_methods.map { |name| method(name) }
reloader_procs.each { |reloader| reloaders.register &reloader }

reloaders
Expand Down
3 changes: 2 additions & 1 deletion spec/guard/jruby-rspec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
:spec_file_suffix => "_spec.rb",
:run_all => {},
:monitor_file => ".guard-jruby-rspec",
:custom_reloaders => []
:custom_reloaders => [],
:custom_reloaders_for_run_all=>[]
}
end

Expand Down