From 67467441fb2b13b592192ac2003c6739182e01fb Mon Sep 17 00:00:00 2001 From: Phil Hagelberg Date: Sun, 4 Nov 2007 20:38:24 -0500 Subject: [PATCH] improved spec coverage --- .gitignore | 3 ++- Rakefile | 3 +-- spec/color_backend_spec.rb | 2 +- spec/fixtures/layers.json | 6 +++--- spec/html_frontend_spec.rb | 8 -------- spec/layer_spec.rb | 36 ++++++++++++++++++++++++++++++++++-- spec/test_backend_spec.rb | 23 ++++++++++++++--------- 7 files changed, 55 insertions(+), 26 deletions(-) diff --git a/.gitignore b/.gitignore index 600f7b6..6727d00 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .augment -pkg \ No newline at end of file +pkg +html/*html \ No newline at end of file diff --git a/Rakefile b/Rakefile index 8b9a995..6bd274c 100644 --- a/Rakefile +++ b/Rakefile @@ -26,8 +26,7 @@ task :render_html do FileUtils.cd(File.dirname(__FILE__) + '/html/src/') TEMPLATE = File.read('html.erb') Dir.glob('*html').each do |filename| - @title = filename.match(/(.*)\.html/)[1].gsub(/_/, ' ').capitalize - @title = "Augment" if @title == 'Index' # edge case! + @title = ("Augment - " + filename.match(/(.*)\.html/)[1].gsub(/_/, ' ').capitalize).gsub(/ - Index/, '') @body = File.read(filename) html = ERB.new(TEMPLATE).result( binding ) diff --git a/spec/color_backend_spec.rb b/spec/color_backend_spec.rb index 3fb9526..40f68f6 100644 --- a/spec/color_backend_spec.rb +++ b/spec/color_backend_spec.rb @@ -1,7 +1,7 @@ $LOAD_PATH << File.dirname(__FILE__) require 'spec_helper' -describe Backend, " when augmenting by color" do +describe ColoringBackend, " when augmenting by color" do before do FileUtils.cd(PROJECT_ROOT) FileUtils.rm_r('lib/.augment') rescue nil diff --git a/spec/fixtures/layers.json b/spec/fixtures/layers.json index 84924a1..1f64cf1 100644 --- a/spec/fixtures/layers.json +++ b/spec/fixtures/layers.json @@ -1,3 +1,3 @@ -[{"message":"cons", "color":"red", "range":"1...12"}, - {"message":"car", "color":"green", "range":"13...24"}, - {"message":"cdr", "color":"blue", "range":"25...36"}] \ No newline at end of file +[{"message":"cons", "color":"red", "range":"1...12", "backend":"coloring"}, + {"message":"car", "color":"green", "range":"13...24", "backend":"coloring"}, + {"message":"cdr", "color":"blue", "range":"25...36", "backend":"coloring"}] \ No newline at end of file diff --git a/spec/html_frontend_spec.rb b/spec/html_frontend_spec.rb index 46e9bcc..1959ac4 100644 --- a/spec/html_frontend_spec.rb +++ b/spec/html_frontend_spec.rb @@ -14,11 +14,3 @@ describe Frontend, " when outputting HTML" do output.to_s.should include("white") end end - -describe Layer, " when converting line range to char range" do - it "should convert properly" do - Layer.line_to_char_range('test/test_drink.rb', 10).should == (153 ... 176) - Layer.line_to_char_range('test/test_drink.rb', 3).should == (22 ... 61) - Layer.line_to_char_range('test/test_drink.rb', 17).should == (289 ... 332) - end -end diff --git a/spec/layer_spec.rb b/spec/layer_spec.rb index 9b73f64..da25757 100644 --- a/spec/layer_spec.rb +++ b/spec/layer_spec.rb @@ -19,9 +19,41 @@ describe Layer, " when creating ranges" do Layer.interpret_where("#test_might_error", @filename).should == (63 ... 68) Layer.interpret_where("#test_will_fail", @filename).should == (230 ... 235) end + + it "should get range from an ambiguous method name" + it "should get range from a class method name" end describe Layer, " when working with JSON" do - it "should read from a file" - it "should output valid JSON" + before do + FileUtils.cd(PROJECT_ROOT + '/..') + # have to create this on the fly since "augment clear"ing the spec dir will erase it. =( + Dir.mkdir('.augment') rescue nil + FileUtils.cp('layers.json', '.augment/layers.json') + @layers = Layer.read('layers.json').reverse + end + + it "should read from a file" do + @layers.map{ |l| l.message }.should == ['cons', 'car', 'cdr'] + @layers.map{ |l| l.color }.should == ['red', 'green', 'blue'] + @layers.map{ |l| l.range }.should == [(1...12), (13...24), (25...36)] + @layers.map{ |l| l.backend }.uniq.should == ['coloring'] + end + + it "should output valid JSON" do + @layers.to_json.should == File.read('layers.json').gsub(/[ \n]/, '') + end + + after do + FileUtils.rm_rf('.augment') + end +end + +describe Layer, " when converting line range to char range" do + it "should convert properly" do + FileUtils.cd(PROJECT_ROOT) + Layer.line_to_char_range('test/test_drink.rb', 10).should == (153 ... 176) + Layer.line_to_char_range('test/test_drink.rb', 3).should == (22 ... 61) + Layer.line_to_char_range('test/test_drink.rb', 17).should == (289 ... 332) + end end diff --git a/spec/test_backend_spec.rb b/spec/test_backend_spec.rb index d89c484..d9b94d4 100644 --- a/spec/test_backend_spec.rb +++ b/spec/test_backend_spec.rb @@ -8,21 +8,26 @@ describe TestUnitBackend, " when augmenting test results" do FileUtils.rm_r('test/.augment') rescue nil TestUnitBackend.run('test/test_drink.rb') + @layers = Layer.read('test/test_drink.rb') end it "should color failing/erroring tests" do - File.should exist(Augment.augment_path('test/test_drink.rb')) - layers = Layer.read('test/test_drink.rb') - layers.first.color.should == 'red' - layers.last.color.should == 'yellow' + @layers.first.color.should == 'red' + @layers.last.color.should == 'yellow' + end - layers.first.range.should == (289 ... 332) + it "should set the range to the line of the error/failure" do + @layers.first.range.should == (289 ... 332) + @layers.last.range.should == (85 ... 97) end it "should include failure message" do - layers = Layer.read('test/test_drink.rb') - layers.first.message.should =~ /bad length/ - layers.last.message.should =~ /undefined local variable or method/ - layers.map{ |l| l.backend }.uniq.should == ['testunit'] + @layers = Layer.read('test/test_drink.rb') + @layers.first.message.should =~ /bad length/ + @layers.last.message.should =~ /undefined local variable or method/ + end + + it "should set the backend field" do + @layers.map{ |l| l.backend }.uniq.should == ['testunit'] end end -- 2.11.4.GIT