Changeset cd1f3381c1ed


Ignore:
Timestamp:
12/24/10 20:01:10 (17 months ago)
Author:
Mahlon E. Smith <mahlon@…>
Branch:
vim-stuff
Message:

Emit file and line for failure source (use gF to jump straight to it!).
Show context lines for exception source. Put spec summary run at the
top of the screen. Small documentation fixes.

Location:
specky
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • specky/doc/specky.txt

    r19 r21  
    9292ways. 
    9393 
    94     1) Set the *g:speckyRunSpecCmd* variable explicitly: 
    95  
    96         let g:speckyRunRdocCmd = "rspec -r ~/.vim/ruby/specky_formatter.rb -f SpeckyFormatter" ~ 
    97  
    98     2) or, leave *g:speckyRunSpecCmd* at its default value, and instead use 
     94    1) Set the 'g:speckyRunSpecCmd' variable explicitly: 
     95 
     96        let g:speckyRunSpecCmd = "rspec -r ~/.vim/ruby/specky_formatter.rb -f SpeckyFormatter" ~ 
     97 
     98    2) or, leave 'g:speckyRunSpecCmd' at its default value, and instead use 
    9999       an '.rspec' settings file in the root directory of the the project 
    100100       you're working in.  I find this method much more flexible -- the 
  • specky/ruby/specky_formatter.rb

    r19 r21  
    1515        @failure_index = 0 
    1616        @failures      = [] 
     17        @txt           = '' 
     18        @summary       = '' 
    1719    end 
     20 
    1821 
    1922    ######################################################################## 
     
    2427    ### 
    2528    def example_group_started( example_group ) 
    26         output.puts 
    2729        self.out '+', '-' * (example_group.description.length + 2), '+' 
    2830        self.out '| ', example_group.description, ' |' 
     
    7476    ### 
    7577    def dump_failures 
    76         self.out "\n\n\n" unless @failures.empty? 
     78        self.out "\n" unless @failures.empty? 
    7779 
    7880        @failures.each_with_index do |example, index| 
    7981            desc      = example.metadata[ :full_description ] 
    8082            exception = example.execution_result[ :exception ] 
     83            file = line = nil 
    8184 
     85            if exception.backtrace.first =~ /(.*):(\d+)/ 
     86                file, line = $1, $2.to_i 
     87            end 
    8288            self.out "FAILURE - #%d)" % [ index + 1 ] 
     89            self.out "%s:%d" % [ file, line ] 
    8390 
    8491            if RSpec::Core::PendingExampleFixedError === exception 
     
    101108                end 
    102109            end 
    103             self.out "\n" 
     110 
     111            self.out exception_source( file, line ) if file && line 
    104112        end 
     113    end 
     114 
     115 
     116    ### Emit the source of the exception, with context lines. 
     117    ### 
     118    def exception_source( file, line ) 
     119        context = '' 
     120        low, high = line - 3, line + 3 
     121 
     122        File.open( file ).each_with_index do |cline, i| 
     123            cline.chomp!.rstrip! 
     124            next unless i >= low && i <= high 
     125            context << "  %s%4d: %s\n" % [ ( i == line ? '>>' : ' |' ), i, cline ] 
     126        end 
     127 
     128        return context 
     129 
     130    rescue 
     131        'Unable to parse exception context lines.' 
    105132    end 
    106133 
     
    110137    def dump_summary( duration, example_count, failure_count, pending_count ) 
    111138        succeeded = example_count - failure_count - pending_count 
    112         self.out '+', '-' * 49, '+' 
    113         self.out '|', ' ' * 18, '-- Summary --', ' ' * 18, '|' 
    114         self.out '+----------+-----------+--------+---------+-------+' 
    115         self.out '| Duration | Succeeded | Failed | Pending | Total |' 
    116         self.out '+----------+-----------+--------+---------+-------+' 
     139        @summary << "+%s+\n" % [ '-' * 49 ] 
     140        @summary << "|%s-- Summary --%s|\n" % [ ' ' * 18, ' ' * 18 ] 
     141        @summary << "+----------+-----------+--------+---------+-------+\n" 
     142        @summary << "| Duration | Succeeded | Failed | Pending | Total |\n" 
     143        @summary << "+----------+-----------+--------+---------+-------+\n" 
    117144 
    118         self.out "| %7ss | %9s | %6s | %7s | %5s |" % [ 
     145        @summary << "| %7ss | %9s | %6s | %7s | %5s |\n" % [ 
    119146            "%0.3f" % duration, succeeded, failure_count, 
    120147            pending_count, example_count 
    121148        ] 
    122149 
    123         self.out '+----------+-----------+--------+---------+-------+' 
     150        @summary << "+----------+-----------+--------+---------+-------+\n\n" 
     151    end 
     152 
     153 
     154    ### End of run.  Dump it all out! 
     155    ### 
     156    def close 
     157        output.puts @summary 
     158        output.puts @txt 
    124159    end 
    125160 
     
    133168    def out( *msg ) 
    134169        msg = msg.join 
    135         output.puts "%s%s" % [ '  ' * @indent_level, msg ] 
     170        @txt << "%s%s\n" % [ '  ' * @indent_level, msg ] 
    136171    end 
    137172 
  • specky/syntax/specrun.vim

    r19 r21  
    2828 
    2929" Failure details 
    30 syntax region specFailedDetails start="^FAILURE - #\d\+)" end="^$" fold contains=specCallout 
     30syntax region specFailedDetails start="^FAILURE - #\d\+)" end="^$" fold contains=specCallout,specErrorLine 
     31syntax match specErrorLine /^  >>/ 
     32 
    3133 
    3234" Boxes 
     
    5254highlight def link specBoxContent Constant 
    5355highlight def link specBoxLine LineNr 
     56highlight def link specErrorLine ErrorMsg 
    5457 
    5558let b:current_syntax = "specrun" 
Note: See TracChangeset for help on using the changeset viewer.