diff --git a/lib/active_mocker/generate.rb b/lib/active_mocker/generate.rb
index <HASH>..<HASH> 100644
--- a/lib/active_mocker/generate.rb
+++ b/lib/active_mocker/generate.rb
@@ -93,7 +93,9 @@ class Generate
   end
 
   def save_mock_file(klass_str, model)
-    File.open(File.join(Config.mock_dir, "#{model.class_name.underscore}_mock.rb"), 'w').write(klass_str)
+    File.open(File.join(Config.mock_dir, "#{model.class_name.underscore}_mock.rb"), 'w') do |f|
+      f.write(klass_str)
+    end
   end
 
   def generate_mock_string(model)
Fix for not closing file stream while writing mocks.
This resulted in empty mock files in some cases (eg. non-rails app).