Skip to content

Commit

Permalink
Reload FactoryGirl if it's loaded
Browse files Browse the repository at this point in the history
Also test that Rails actually receives the reload messages.
  • Loading branch information
nilbus committed Jan 14, 2014
1 parent 77a88d4 commit 0bdaf96
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -54,7 +54,7 @@ When using this gem on a non Rails 3.2+ project, you may want to unload these cl
Pass in custom reloaders as an option:

unload_my_class = lambda { |changed_paths| Object.send :remove_const, 'MyClass' }
reload_factory_girl = lambda { |changed_paths| FactoryGirl.reload }
reload_factory_girl = lambda { |changed_paths| FactoryGirl.reload } # Already included by default when FactoryGirl is loaded
guard 'jruby-rspec', :custom_reloaders => [unload_my_class, reload_factory_girl] do
...
end
Expand Down
6 changes: 5 additions & 1 deletion lib/guard/jruby-rspec.rb
Expand Up @@ -84,6 +84,10 @@ def reload_rails(*)
end
end

def reload_factory_girl(*)
FactoryGirl.reload if defined? ::FactoryGirl
end

def reload_paths(paths)
paths.reject {|p| p.end_with?(@options[:spec_file_suffix])}.each do |p|
if File.exists?(p)
Expand Down Expand Up @@ -112,7 +116,7 @@ def reload_paths(paths)

def set_up_reloaders(options)
reloaders = Reloaders.new
reloader_methods = [:reload_rails, :reload_paths]
reloader_methods = [:reload_rails, :reload_paths, :reload_factory_girl]
reloader_procs = reloader_methods.map { |name| method(name) }
reloader_procs += options[:custom_reloaders]
reloader_procs.each { |reloader| reloaders.register &reloader }
Expand Down
22 changes: 22 additions & 0 deletions spec/guard/jruby-rspec_spec.rb
Expand Up @@ -116,6 +116,28 @@
subject.reload_rails
}.not_to raise_exception
end

it "reloads Rails if it's loaded" do
stub_const '::ActionDispatch::Reloader', double
ActionDispatch::Reloader.should_receive 'cleanup!'
ActionDispatch::Reloader.should_receive 'prepare!'
subject.reload_rails
end
end

describe '#reload_factory_girl' do
it 'continues silently if FactoryGirl is not loaded' do
defined?(::FactoryGirl).should be_false
expect {
subject.reload_factory_girl
}.not_to raise_exception
end

it "reloads FactoryGirl if it's loaded" do
stub_const 'FactoryGirl', double
FactoryGirl.should_receive 'reload'
subject.reload_factory_girl
end
end

describe '#reload_paths' do
Expand Down

0 comments on commit 0bdaf96

Please sign in to comment.