Sha256: f1136349abaefc9be2b09b1b52e0786f7dc6f3d0d22f83f2e9bf7d48a7915919

Contents?: true

Size: 1.4 KB

Versions: 5

Compression:

Stored size: 1.4 KB

Contents

require "spec_helper"

module BetterErrors
  describe CodeFormatter do
    let(:filename) { File.expand_path("../support/my_source.rb", __FILE__) }
    
    let(:formatter) { CodeFormatter.new(filename, 8) }
    
    it "should pick an appropriate scanner" do
      formatter.coderay_scanner.should == :ruby
    end
    
    it "should show 5 lines of context" do
      formatter.line_range.should == (3..13)
      
      formatter.context_lines.should == [
          "three\n",
          "four\n",
          "five\n",
          "six\n",
          "seven\n",
          "eight\n",
          "nine\n",
          "ten\n",
          "eleven\n",
          "twelve\n",
          "thirteen\n"
        ]
    end
    
    it "should highlight the erroring line" do
      formatter.html.should =~ /highlight.*eight/
    end
    
    it "should work when the line is right on the edge" do
      formatter = CodeFormatter.new(filename, 20)
      formatter.line_range.should == (15..20)
      formatter.html.should_not == formatter.source_unavailable
    end
    
    it "should not barf when the lines don't make any sense" do
      formatter = CodeFormatter.new(filename, 999)
      formatter.html.should == formatter.source_unavailable
    end
    
    it "should not barf when the file doesn't exist" do
      formatter = CodeFormatter.new("fkdguhskd7e l", 1)
      formatter.html.should == formatter.source_unavailable
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
better_errors-0.3.2 spec/better_errors/code_formatter_spec.rb
better_errors-0.3.0 spec/better_errors/code_formatter_spec.rb
better_errors-0.2.0 spec/better_errors/code_formatter_spec.rb
better_errors-0.1.1 spec/better_errors/code_formatter_spec.rb
better_errors-0.1.0 spec/better_errors/code_formatter_spec.rb