Skip to content
Browse files

Don't want per_file_info in saikuro.rb to blow up on nonexistent files

  • Loading branch information...
1 parent 1cf104e commit 1191acade8055bd8e3197ecd2b766b151959e268 @jscruggs jscruggs committed
Showing with 17 additions and 1 deletion.
  1. +1 −1 lib/generators/saikuro.rb
  2. +16 −0 spec/generators/saikuro_spec.rb
View
2 lib/generators/saikuro.rb
@@ -49,7 +49,7 @@ def to_h
def per_file_info(out)
@saikuro_data[:files].each do |file_data|
- next if File.extname(file_data[:filename]) == '.erb'
+ next if File.extname(file_data[:filename]) == '.erb' || !File.exists?(file_data[:filename])
begin
line_numbers = MetricFu::LineNumbers.new(File.open(file_data[:filename], 'r').read)
rescue StandardError => e
View
16 spec/generators/saikuro_spec.rb
@@ -33,6 +33,22 @@
@output[:saikuro][:methods].first[:lines].should == 15
end
end
+
+ describe "per_file_info method" do
+ before :all do
+ MetricFu::Configuration.run {}
+ File.stub!(:directory?).and_return(true)
+ @saikuro = MetricFu::Saikuro.new
+ @saikuro.stub!(:metric_directory).and_return(File.join(File.dirname(__FILE__), "..", "resources", "saikuro"))
+ @saikuro.analyze
+ @output = @saikuro.to_h
+ end
+
+ it "doesn't try to get information if the file does not exist" do
+ File.should_receive(:exists?).at_least(:once).and_return(false)
+ @saikuro.per_file_info('ignore_me')
+ end
+ end
describe "format_directories method" do
it "should format the directories" do

0 comments on commit 1191aca

Please sign in to comment.
Something went wrong with that request. Please try again.