command_line_reporter 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +196 -0
 - data/examples/nested.rb +38 -0
 - data/examples/progress.rb +51 -0
 - data/lib/command_line_reporter.rb +20 -0
 - data/lib/nested_formatter.rb +56 -0
 - data/lib/progress_formatter.rb +23 -0
 - data/lib/version.rb +3 -0
 - data/spec/command_line_reporter_spec.rb +37 -0
 - data/spec/nested_formatter_spec.rb +250 -0
 - data/spec/progress_formatter_spec.rb +61 -0
 - data/spec/spec_helper.rb +1 -0
 - metadata +75 -0
 
    
        data/README.md
    ADDED
    
    | 
         @@ -0,0 +1,196 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            ## Command Line Reporter
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            This gem provides an simple way to add RSpec like formatting of the output of your ruby scripts.  It
         
     | 
| 
      
 4 
     | 
    
         
            +
            eliminates the need to litter your code with *puts* statements instead providing a cleaner, more
         
     | 
| 
      
 5 
     | 
    
         
            +
            ruby like way of reporting progress to the user throught the command line interface.
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            ### Installation
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            It is up on rubygems.org so add it to your bundle or do it the old fashioned way:
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            ```bash
         
     | 
| 
      
 12 
     | 
    
         
            +
            gem install command_line_reporter
         
     | 
| 
      
 13 
     | 
    
         
            +
            ```
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
            ### Usage
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
            The gem provides a mixin that can be included in your scripts.
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 20 
     | 
    
         
            +
            include CommandLineReporter
         
     | 
| 
      
 21 
     | 
    
         
            +
            ```
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
            #### Standard Methods
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
            There are several methods the mixin provides that do not depend on the formatter used:
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
            1. _report(hash) {block}_
         
     | 
| 
      
 28 
     | 
    
         
            +
              * The first argument is a hash that defines the options for the method. See the details in the
         
     | 
| 
      
 29 
     | 
    
         
            +
                formatter section for allowed values.
         
     | 
| 
      
 30 
     | 
    
         
            +
              * The second argument is a block of ruby code that you want executed within the context of the
         
     | 
| 
      
 31 
     | 
    
         
            +
                reporter.  Any ruby code is allowed.  See the examples that follow in the formatter sections for
         
     | 
| 
      
 32 
     | 
    
         
            +
                details.
         
     | 
| 
      
 33 
     | 
    
         
            +
            1. _formatter=(string)_
         
     | 
| 
      
 34 
     | 
    
         
            +
              * Simple string indicating the formatter you want your application to use.  At present the 2
         
     | 
| 
      
 35 
     | 
    
         
            +
                formatters are:
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
                2. Progress - indicated by the string '_progress_'
         
     | 
| 
      
 38 
     | 
    
         
            +
                2. Nested - indicated by the string '_nested_'
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
                The default is _nested_.
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
            ### Progress Formatter
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
            #### Example
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 47 
     | 
    
         
            +
            require 'command_line_reporter'
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
            class Example
         
     | 
| 
      
 50 
     | 
    
         
            +
              include CommandLineReporter
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
      
 52 
     | 
    
         
            +
              def initialize
         
     | 
| 
      
 53 
     | 
    
         
            +
                formatter = 'progress'
         
     | 
| 
      
 54 
     | 
    
         
            +
              end
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
              def run
         
     | 
| 
      
 57 
     | 
    
         
            +
                x = 0
         
     | 
| 
      
 58 
     | 
    
         
            +
                report do
         
     | 
| 
      
 59 
     | 
    
         
            +
                  10.times do
         
     | 
| 
      
 60 
     | 
    
         
            +
                    x += 1
         
     | 
| 
      
 61 
     | 
    
         
            +
                    formatter.progress
         
     | 
| 
      
 62 
     | 
    
         
            +
                  end
         
     | 
| 
      
 63 
     | 
    
         
            +
                end
         
     | 
| 
      
 64 
     | 
    
         
            +
              end
         
     | 
| 
      
 65 
     | 
    
         
            +
            end
         
     | 
| 
      
 66 
     | 
    
         
            +
             
     | 
| 
      
 67 
     | 
    
         
            +
            Example.new.run
         
     | 
| 
      
 68 
     | 
    
         
            +
            ```
         
     | 
| 
      
 69 
     | 
    
         
            +
             
     | 
| 
      
 70 
     | 
    
         
            +
            This simply produces 10 dots (.) in succession:
         
     | 
| 
      
 71 
     | 
    
         
            +
             
     | 
| 
      
 72 
     | 
    
         
            +
            ```bash
         
     | 
| 
      
 73 
     | 
    
         
            +
            [~/scratch]$ ruby example.rb
         
     | 
| 
      
 74 
     | 
    
         
            +
            ..........
         
     | 
| 
      
 75 
     | 
    
         
            +
            ```
         
     | 
| 
      
 76 
     | 
    
         
            +
             
     | 
| 
      
 77 
     | 
    
         
            +
            #### Indicator
         
     | 
| 
      
 78 
     | 
    
         
            +
             
     | 
| 
      
 79 
     | 
    
         
            +
            The indicator is the string that is displayed in the command line interface that indicates progress.
         
     | 
| 
      
 80 
     | 
    
         
            +
            The default is the dot (.) but any string is allowed.  In fact one can use the erase character to
         
     | 
| 
      
 81 
     | 
    
         
            +
            get crafty with displaying percent complete in place.
         
     | 
| 
      
 82 
     | 
    
         
            +
             
     | 
| 
      
 83 
     | 
    
         
            +
            #### Instance Methods
         
     | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
      
 85 
     | 
    
         
            +
            * _indicator(string)_ - This overrides the default value of the dot (.) being used for all calls to
         
     | 
| 
      
 86 
     | 
    
         
            +
               the report method.
         
     | 
| 
      
 87 
     | 
    
         
            +
             
     | 
| 
      
 88 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 89 
     | 
    
         
            +
            formatter.indicator('*')
         
     | 
| 
      
 90 
     | 
    
         
            +
            ```
         
     | 
| 
      
 91 
     | 
    
         
            +
             
     | 
| 
      
 92 
     | 
    
         
            +
            * _progress(string)_ - Call this method to invoke the output to the command line interface.  The
         
     | 
| 
      
 93 
     | 
    
         
            +
               string overrides the indicator for this call only.
         
     | 
| 
      
 94 
     | 
    
         
            +
             
     | 
| 
      
 95 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 96 
     | 
    
         
            +
            formatter.progress
         
     | 
| 
      
 97 
     | 
    
         
            +
            formatter.progress("^H^H^H10%")
         
     | 
| 
      
 98 
     | 
    
         
            +
            ```
         
     | 
| 
      
 99 
     | 
    
         
            +
             
     | 
| 
      
 100 
     | 
    
         
            +
            ### Nested Formatter
         
     | 
| 
      
 101 
     | 
    
         
            +
             
     | 
| 
      
 102 
     | 
    
         
            +
            The nested formatter concept is inspired by the documentation formatter in RSpec.  The idea is to be
         
     | 
| 
      
 103 
     | 
    
         
            +
            able to create nested grouping levels of output that are very readable as the code is being
         
     | 
| 
      
 104 
     | 
    
         
            +
            executed.
         
     | 
| 
      
 105 
     | 
    
         
            +
             
     | 
| 
      
 106 
     | 
    
         
            +
            #### Example
         
     | 
| 
      
 107 
     | 
    
         
            +
             
     | 
| 
      
 108 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 109 
     | 
    
         
            +
            require 'command_line_reporter'
         
     | 
| 
      
 110 
     | 
    
         
            +
             
     | 
| 
      
 111 
     | 
    
         
            +
            class Example
         
     | 
| 
      
 112 
     | 
    
         
            +
              include CommandLineReporter
         
     | 
| 
      
 113 
     | 
    
         
            +
             
     | 
| 
      
 114 
     | 
    
         
            +
              def initialize
         
     | 
| 
      
 115 
     | 
    
         
            +
                self.formatter = 'nested'
         
     | 
| 
      
 116 
     | 
    
         
            +
              end
         
     | 
| 
      
 117 
     | 
    
         
            +
             
     | 
| 
      
 118 
     | 
    
         
            +
              def run
         
     | 
| 
      
 119 
     | 
    
         
            +
                x,y,z = 0,0,0
         
     | 
| 
      
 120 
     | 
    
         
            +
             
     | 
| 
      
 121 
     | 
    
         
            +
                report(:message => 'calculating first expression') do
         
     | 
| 
      
 122 
     | 
    
         
            +
                  x = 2 + 2
         
     | 
| 
      
 123 
     | 
    
         
            +
                  2.times do
         
     | 
| 
      
 124 
     | 
    
         
            +
                    report(:message => 'calculating second expression') do
         
     | 
| 
      
 125 
     | 
    
         
            +
                      y = 10 - x
         
     | 
| 
      
 126 
     | 
    
         
            +
                      10.times do |i|
         
     | 
| 
      
 127 
     | 
    
         
            +
                        report(:message => 'pixelizing', :type => 'inline', :complete => "#{i*10+10}%") do
         
     | 
| 
      
 128 
     | 
    
         
            +
                          z = x + y
         
     | 
| 
      
 129 
     | 
    
         
            +
                        end
         
     | 
| 
      
 130 
     | 
    
         
            +
                      end
         
     | 
| 
      
 131 
     | 
    
         
            +
                    end
         
     | 
| 
      
 132 
     | 
    
         
            +
                  end
         
     | 
| 
      
 133 
     | 
    
         
            +
                end
         
     | 
| 
      
 134 
     | 
    
         
            +
              end
         
     | 
| 
      
 135 
     | 
    
         
            +
            end
         
     | 
| 
      
 136 
     | 
    
         
            +
             
     | 
| 
      
 137 
     | 
    
         
            +
            Example.new.run
         
     | 
| 
      
 138 
     | 
    
         
            +
             
     | 
| 
      
 139 
     | 
    
         
            +
            ```
         
     | 
| 
      
 140 
     | 
    
         
            +
             
     | 
| 
      
 141 
     | 
    
         
            +
            This produces the more complex output:
         
     | 
| 
      
 142 
     | 
    
         
            +
             
     | 
| 
      
 143 
     | 
    
         
            +
            ```
         
     | 
| 
      
 144 
     | 
    
         
            +
            [~/scratch]$ ruby example.rb
         
     | 
| 
      
 145 
     | 
    
         
            +
            calculating first expression
         
     | 
| 
      
 146 
     | 
    
         
            +
              calculating second expression
         
     | 
| 
      
 147 
     | 
    
         
            +
                pixelizing...10%
         
     | 
| 
      
 148 
     | 
    
         
            +
                pixelizing...20%
         
     | 
| 
      
 149 
     | 
    
         
            +
                pixelizing...30%
         
     | 
| 
      
 150 
     | 
    
         
            +
                pixelizing...40%
         
     | 
| 
      
 151 
     | 
    
         
            +
                pixelizing...50%
         
     | 
| 
      
 152 
     | 
    
         
            +
                pixelizing...60%
         
     | 
| 
      
 153 
     | 
    
         
            +
                pixelizing...70%
         
     | 
| 
      
 154 
     | 
    
         
            +
                pixelizing...80%
         
     | 
| 
      
 155 
     | 
    
         
            +
                pixelizing...90%
         
     | 
| 
      
 156 
     | 
    
         
            +
                pixelizing...100%
         
     | 
| 
      
 157 
     | 
    
         
            +
              complete
         
     | 
| 
      
 158 
     | 
    
         
            +
              calculating second expression
         
     | 
| 
      
 159 
     | 
    
         
            +
                pixelizing...10%
         
     | 
| 
      
 160 
     | 
    
         
            +
                pixelizing...20%
         
     | 
| 
      
 161 
     | 
    
         
            +
                pixelizing...30%
         
     | 
| 
      
 162 
     | 
    
         
            +
                pixelizing...40%
         
     | 
| 
      
 163 
     | 
    
         
            +
                pixelizing...50%
         
     | 
| 
      
 164 
     | 
    
         
            +
                pixelizing...60%
         
     | 
| 
      
 165 
     | 
    
         
            +
                pixelizing...70%
         
     | 
| 
      
 166 
     | 
    
         
            +
                pixelizing...80%
         
     | 
| 
      
 167 
     | 
    
         
            +
                pixelizing...90%
         
     | 
| 
      
 168 
     | 
    
         
            +
                pixelizing...100%
         
     | 
| 
      
 169 
     | 
    
         
            +
              complete
         
     | 
| 
      
 170 
     | 
    
         
            +
            complete
         
     | 
| 
      
 171 
     | 
    
         
            +
            ```
         
     | 
| 
      
 172 
     | 
    
         
            +
             
     | 
| 
      
 173 
     | 
    
         
            +
            #### Instance Methods
         
     | 
| 
      
 174 
     | 
    
         
            +
             
     | 
| 
      
 175 
     | 
    
         
            +
            * _message_string(string)_ - This defines the string that is displayed as the first part of the
         
     | 
| 
      
 176 
     | 
    
         
            +
              message to the user. The default value is "_working_". 
         
     | 
| 
      
 177 
     | 
    
         
            +
            * _complete_string(string)_ - This defines the string that completes the message to the user for the
         
     | 
| 
      
 178 
     | 
    
         
            +
              report.  The default value is "_complete_".
         
     | 
| 
      
 179 
     | 
    
         
            +
            * _indent_size(int)_ - The number of spaces to indent for a single indentation level.  The default
         
     | 
| 
      
 180 
     | 
    
         
            +
              value is 2 spaces.
         
     | 
| 
      
 181 
     | 
    
         
            +
             
     | 
| 
      
 182 
     | 
    
         
            +
            #### Report Options
         
     | 
| 
      
 183 
     | 
    
         
            +
             
     | 
| 
      
 184 
     | 
    
         
            +
            The following are the allowed values of the options hash argument to the _report_ method:
         
     | 
| 
      
 185 
     | 
    
         
            +
             
     | 
| 
      
 186 
     | 
    
         
            +
            * _message_ - The string that is displayed as the first part of the message to the user
         
     | 
| 
      
 187 
     | 
    
         
            +
            * _complete_ - The string that completes the message to the user
         
     | 
| 
      
 188 
     | 
    
         
            +
            * _type_ - Define as 'inline' if you want the message and complete strings on the same line
         
     | 
| 
      
 189 
     | 
    
         
            +
            * _indent_size_ - The number of spaces to indent the current level
         
     | 
| 
      
 190 
     | 
    
         
            +
             
     | 
| 
      
 191 
     | 
    
         
            +
            ### To Do
         
     | 
| 
      
 192 
     | 
    
         
            +
             
     | 
| 
      
 193 
     | 
    
         
            +
            1. Add the progress method to the top level mixin so that there is no need to invoke through the
         
     | 
| 
      
 194 
     | 
    
         
            +
               formatter.
         
     | 
| 
      
 195 
     | 
    
         
            +
            2. Add a _preface_ and _epilogue_ methods so that beginning and ending aspects of the report may be
         
     | 
| 
      
 196 
     | 
    
         
            +
               added without using _puts_ and _print_.
         
     | 
    
        data/examples/nested.rb
    ADDED
    
    | 
         @@ -0,0 +1,38 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'command_line_reporter'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            class Example
         
     | 
| 
      
 4 
     | 
    
         
            +
              include CommandLineReporter
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
              def initialize
         
     | 
| 
      
 7 
     | 
    
         
            +
                self.formatter = 'nested'
         
     | 
| 
      
 8 
     | 
    
         
            +
                self.formatter.complete_string = 'done'
         
     | 
| 
      
 9 
     | 
    
         
            +
              end
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
              def run
         
     | 
| 
      
 12 
     | 
    
         
            +
                x,y,z = 0,0,0
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
                report(:message => 'calculating first expression') do
         
     | 
| 
      
 15 
     | 
    
         
            +
                  x = 2 + 2
         
     | 
| 
      
 16 
     | 
    
         
            +
                  sleep 1
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
                  2.times do
         
     | 
| 
      
 19 
     | 
    
         
            +
                    report(:message => 'calculating second expression') do
         
     | 
| 
      
 20 
     | 
    
         
            +
                      y = 10 - x
         
     | 
| 
      
 21 
     | 
    
         
            +
                      sleep 1
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                      10.times do |i|
         
     | 
| 
      
 24 
     | 
    
         
            +
                        report(:message => 'pixelizing', :type => 'inline', :complete => "#{i*10+10}%") do
         
     | 
| 
      
 25 
     | 
    
         
            +
                          z = x + y
         
     | 
| 
      
 26 
     | 
    
         
            +
                          sleep 1
         
     | 
| 
      
 27 
     | 
    
         
            +
                        end
         
     | 
| 
      
 28 
     | 
    
         
            +
                      end
         
     | 
| 
      
 29 
     | 
    
         
            +
                    end
         
     | 
| 
      
 30 
     | 
    
         
            +
                  end
         
     | 
| 
      
 31 
     | 
    
         
            +
                end
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                puts '-' * 20
         
     | 
| 
      
 34 
     | 
    
         
            +
                %w(x y z).each {|v| puts "#{v}: #{eval v}"}
         
     | 
| 
      
 35 
     | 
    
         
            +
              end
         
     | 
| 
      
 36 
     | 
    
         
            +
            end
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
            Example.new.run
         
     | 
| 
         @@ -0,0 +1,51 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'command_line_reporter'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            class Example
         
     | 
| 
      
 4 
     | 
    
         
            +
              include CommandLineReporter
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
              def initialize
         
     | 
| 
      
 7 
     | 
    
         
            +
                self.formatter = 'progress'
         
     | 
| 
      
 8 
     | 
    
         
            +
              end
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
              def run
         
     | 
| 
      
 11 
     | 
    
         
            +
                x = 0
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                report do
         
     | 
| 
      
 14 
     | 
    
         
            +
                  10.times do
         
     | 
| 
      
 15 
     | 
    
         
            +
                    x += 1
         
     | 
| 
      
 16 
     | 
    
         
            +
                    formatter.progress
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
                    10.times do
         
     | 
| 
      
 19 
     | 
    
         
            +
                      x += 1
         
     | 
| 
      
 20 
     | 
    
         
            +
                      formatter.progress
         
     | 
| 
      
 21 
     | 
    
         
            +
                    end
         
     | 
| 
      
 22 
     | 
    
         
            +
                  end
         
     | 
| 
      
 23 
     | 
    
         
            +
                end
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                y = 0
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
                report do
         
     | 
| 
      
 28 
     | 
    
         
            +
                  10.times do
         
     | 
| 
      
 29 
     | 
    
         
            +
                    y += 1
         
     | 
| 
      
 30 
     | 
    
         
            +
                    sleep 1
         
     | 
| 
      
 31 
     | 
    
         
            +
                    formatter.progress("#{y*10+10}%")
         
     | 
| 
      
 32 
     | 
    
         
            +
                  end
         
     | 
| 
      
 33 
     | 
    
         
            +
                end
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                report do
         
     | 
| 
      
 36 
     | 
    
         
            +
                  3.times do
         
     | 
| 
      
 37 
     | 
    
         
            +
                    formatter.progress("\\")
         
     | 
| 
      
 38 
     | 
    
         
            +
                    sleep 1
         
     | 
| 
      
 39 
     | 
    
         
            +
                    formatter.progress("/")
         
     | 
| 
      
 40 
     | 
    
         
            +
                    sleep 1
         
     | 
| 
      
 41 
     | 
    
         
            +
                    formatter.progress("-")
         
     | 
| 
      
 42 
     | 
    
         
            +
                    sleep 1
         
     | 
| 
      
 43 
     | 
    
         
            +
                  end
         
     | 
| 
      
 44 
     | 
    
         
            +
                end
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
                puts "x: #{x}"
         
     | 
| 
      
 47 
     | 
    
         
            +
                puts "y: #{y}"
         
     | 
| 
      
 48 
     | 
    
         
            +
              end
         
     | 
| 
      
 49 
     | 
    
         
            +
            end
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
            Example.new.run
         
     | 
| 
         @@ -0,0 +1,20 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            Dir[File.join(File.dirname(__FILE__), '*_formatter.rb')].each {|r| require r}
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module CommandLineReporter
         
     | 
| 
      
 4 
     | 
    
         
            +
              attr_reader :formatter
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
              def report(options = {}, &block)
         
     | 
| 
      
 7 
     | 
    
         
            +
                self.formatter = 'nested' if self.formatter.nil?
         
     | 
| 
      
 8 
     | 
    
         
            +
                self.formatter.format(options, block)
         
     | 
| 
      
 9 
     | 
    
         
            +
              end
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
              def formatter=(type = 'nested')
         
     | 
| 
      
 12 
     | 
    
         
            +
                name = type.capitalize + 'Formatter'
         
     | 
| 
      
 13 
     | 
    
         
            +
                klass = %W{CommandLineReporter #{name}}.inject(Kernel) {|s,c| s.const_get(c)}
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                # Each formatter is a singleton that responds to #instance
         
     | 
| 
      
 16 
     | 
    
         
            +
                @formatter = klass.instance
         
     | 
| 
      
 17 
     | 
    
         
            +
              rescue
         
     | 
| 
      
 18 
     | 
    
         
            +
                raise ArgumentError, 'Invalid formatter specified'
         
     | 
| 
      
 19 
     | 
    
         
            +
              end
         
     | 
| 
      
 20 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,56 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'singleton'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module CommandLineReporter
         
     | 
| 
      
 4 
     | 
    
         
            +
              class NestedFormatter
         
     | 
| 
      
 5 
     | 
    
         
            +
                include Singleton
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
                attr_accessor :indent_size, :complete_string, :message_string
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
                def format(options, block)
         
     | 
| 
      
 10 
     | 
    
         
            +
                  raise ArgumentError unless (options.keys - [:message, :type, :complete, :indent_size]).empty?
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
                  indent_level :incr
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
                  padding = ' ' * @indent_level * (options[:indent_size] || self.indent_size)
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                  message_str = padding + (options[:message] || self.message_string)
         
     | 
| 
      
 17 
     | 
    
         
            +
                  complete_str = options[:complete] || self.complete_string
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                  if options[:type] == 'inline'
         
     | 
| 
      
 20 
     | 
    
         
            +
                    print "#{message_str}..."
         
     | 
| 
      
 21 
     | 
    
         
            +
                  else
         
     | 
| 
      
 22 
     | 
    
         
            +
                    puts message_str
         
     | 
| 
      
 23 
     | 
    
         
            +
                    complete_str = padding + complete_str
         
     | 
| 
      
 24 
     | 
    
         
            +
                  end
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                  block.call
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                  puts complete_str
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
                  indent_level :decr
         
     | 
| 
      
 31 
     | 
    
         
            +
                end
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                def message_string
         
     | 
| 
      
 34 
     | 
    
         
            +
                  @message_string ||= 'working'
         
     | 
| 
      
 35 
     | 
    
         
            +
                end
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
                def complete_string
         
     | 
| 
      
 38 
     | 
    
         
            +
                  @complete_string ||= 'complete'
         
     | 
| 
      
 39 
     | 
    
         
            +
                end
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
                def indent_size
         
     | 
| 
      
 42 
     | 
    
         
            +
                  @indent_size ||= 2
         
     | 
| 
      
 43 
     | 
    
         
            +
                end
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
                private
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
                def indent_level(value)
         
     | 
| 
      
 48 
     | 
    
         
            +
                  case value
         
     | 
| 
      
 49 
     | 
    
         
            +
                  when :incr
         
     | 
| 
      
 50 
     | 
    
         
            +
                    @indent_level = (@indent_level) ? @indent_level + 1 : 0
         
     | 
| 
      
 51 
     | 
    
         
            +
                  when :decr
         
     | 
| 
      
 52 
     | 
    
         
            +
                    @indent_level -= 1
         
     | 
| 
      
 53 
     | 
    
         
            +
                  end
         
     | 
| 
      
 54 
     | 
    
         
            +
                end
         
     | 
| 
      
 55 
     | 
    
         
            +
              end
         
     | 
| 
      
 56 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,23 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'singleton'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module CommandLineReporter
         
     | 
| 
      
 4 
     | 
    
         
            +
              class ProgressFormatter
         
     | 
| 
      
 5 
     | 
    
         
            +
                include Singleton
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
                attr_accessor :indicator
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
                def format(options, block)
         
     | 
| 
      
 10 
     | 
    
         
            +
                  self.indicator = options[:indicator] if options[:indicator]
         
     | 
| 
      
 11 
     | 
    
         
            +
                  block.call
         
     | 
| 
      
 12 
     | 
    
         
            +
                  puts
         
     | 
| 
      
 13 
     | 
    
         
            +
                end
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                def progress(override = nil)
         
     | 
| 
      
 16 
     | 
    
         
            +
                  print override || self.indicator
         
     | 
| 
      
 17 
     | 
    
         
            +
                end
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                def indicator
         
     | 
| 
      
 20 
     | 
    
         
            +
                  @indicator ||= '.'
         
     | 
| 
      
 21 
     | 
    
         
            +
                end
         
     | 
| 
      
 22 
     | 
    
         
            +
              end
         
     | 
| 
      
 23 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/version.rb
    ADDED
    
    
| 
         @@ -0,0 +1,37 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'spec_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'command_line_reporter'
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            describe CommandLineReporter do
         
     | 
| 
      
 5 
     | 
    
         
            +
              let :use_class do
         
     | 
| 
      
 6 
     | 
    
         
            +
                Class.new do
         
     | 
| 
      
 7 
     | 
    
         
            +
                  include CommandLineReporter
         
     | 
| 
      
 8 
     | 
    
         
            +
                end
         
     | 
| 
      
 9 
     | 
    
         
            +
              end
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
              subject { use_class.new }
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
              describe '#formatter=' do
         
     | 
| 
      
 14 
     | 
    
         
            +
                it 'only allows allowed formatters' do
         
     | 
| 
      
 15 
     | 
    
         
            +
                  lambda {
         
     | 
| 
      
 16 
     | 
    
         
            +
                    subject.formatter = 'asfd'
         
     | 
| 
      
 17 
     | 
    
         
            +
                  }.should raise_exception ArgumentError
         
     | 
| 
      
 18 
     | 
    
         
            +
                end
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                it 'specifies the progress formatter' do
         
     | 
| 
      
 21 
     | 
    
         
            +
                  subject.formatter = 'progress'
         
     | 
| 
      
 22 
     | 
    
         
            +
                  subject.formatter.class.should == CommandLineReporter::ProgressFormatter
         
     | 
| 
      
 23 
     | 
    
         
            +
                end
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                it 'specifies the nested formatter' do
         
     | 
| 
      
 26 
     | 
    
         
            +
                  subject.formatter = 'nested'
         
     | 
| 
      
 27 
     | 
    
         
            +
                  subject.formatter.class.should == CommandLineReporter::NestedFormatter
         
     | 
| 
      
 28 
     | 
    
         
            +
                end
         
     | 
| 
      
 29 
     | 
    
         
            +
              end
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
              describe '#report' do
         
     | 
| 
      
 32 
     | 
    
         
            +
                it 'uses the nested formatter as default' do
         
     | 
| 
      
 33 
     | 
    
         
            +
                  subject.report { }
         
     | 
| 
      
 34 
     | 
    
         
            +
                  subject.formatter.class.should == CommandLineReporter::NestedFormatter
         
     | 
| 
      
 35 
     | 
    
         
            +
                end
         
     | 
| 
      
 36 
     | 
    
         
            +
              end
         
     | 
| 
      
 37 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,250 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'spec_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'nested_formatter'
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            describe CommandLineReporter::NestedFormatter do
         
     | 
| 
      
 5 
     | 
    
         
            +
              subject { CommandLineReporter::NestedFormatter.instance }
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
              describe '#method default values' do
         
     | 
| 
      
 8 
     | 
    
         
            +
                its(:message_string) { should == 'working' }
         
     | 
| 
      
 9 
     | 
    
         
            +
                its(:complete_string) { should == 'complete' }
         
     | 
| 
      
 10 
     | 
    
         
            +
                its(:indent_size) { should eq 2 }
         
     | 
| 
      
 11 
     | 
    
         
            +
              end
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
              describe '#format' do
         
     | 
| 
      
 14 
     | 
    
         
            +
                context 'argument validation' do
         
     | 
| 
      
 15 
     | 
    
         
            +
                  before :all do
         
     | 
| 
      
 16 
     | 
    
         
            +
                    @indent_size = subject.indent_size
         
     | 
| 
      
 17 
     | 
    
         
            +
                  end
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                  # Restore the singleton to its original state to ensure clean tests
         
     | 
| 
      
 20 
     | 
    
         
            +
                  after :each do
         
     | 
| 
      
 21 
     | 
    
         
            +
                    subject.indent_size = @indent_size
         
     | 
| 
      
 22 
     | 
    
         
            +
                  end
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
                  it 'raises exception when there is an invalid argument' do
         
     | 
| 
      
 25 
     | 
    
         
            +
                    lambda {
         
     | 
| 
      
 26 
     | 
    
         
            +
                      subject.format({:asdf => true}, lambda { })
         
     | 
| 
      
 27 
     | 
    
         
            +
                    }.should raise_exception ArgumentError
         
     | 
| 
      
 28 
     | 
    
         
            +
                  end
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
                  it 'raises an exception when a block is not given' do
         
     | 
| 
      
 31 
     | 
    
         
            +
                    lambda {
         
     | 
| 
      
 32 
     | 
    
         
            +
                      subject.format({:message => 'test'})
         
     | 
| 
      
 33 
     | 
    
         
            +
                    }.should raise_exception
         
     | 
| 
      
 34 
     | 
    
         
            +
                  end
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
                  it 'accepts valid arguments' do
         
     | 
| 
      
 37 
     | 
    
         
            +
                    subject.should_receive(:puts).with('test')
         
     | 
| 
      
 38 
     | 
    
         
            +
                    subject.should_receive(:puts).with('complete')
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
                    lambda {
         
     | 
| 
      
 41 
     | 
    
         
            +
                      subject.format({:message => 'test'}, lambda { }) do
         
     | 
| 
      
 42 
     | 
    
         
            +
                      end
         
     | 
| 
      
 43 
     | 
    
         
            +
                    }.should_not raise_exception
         
     | 
| 
      
 44 
     | 
    
         
            +
                  end
         
     | 
| 
      
 45 
     | 
    
         
            +
                end
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
                context 'not nested' do
         
     | 
| 
      
 48 
     | 
    
         
            +
                  before :all do
         
     | 
| 
      
 49 
     | 
    
         
            +
                    @complete_string = subject.complete_string
         
     | 
| 
      
 50 
     | 
    
         
            +
                    @indent_size = subject.indent_size
         
     | 
| 
      
 51 
     | 
    
         
            +
                  end
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
                  # Restore the singleton to its original state to ensure clean tests
         
     | 
| 
      
 54 
     | 
    
         
            +
                  after :each do
         
     | 
| 
      
 55 
     | 
    
         
            +
                    subject.complete_string = @complete_string
         
     | 
| 
      
 56 
     | 
    
         
            +
                    subject.indent_size = @indent_size
         
     | 
| 
      
 57 
     | 
    
         
            +
                  end
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
      
 59 
     | 
    
         
            +
                  it 'performs a wrapped report' do
         
     | 
| 
      
 60 
     | 
    
         
            +
                    subject.should_receive(:puts).with('working')
         
     | 
| 
      
 61 
     | 
    
         
            +
                    subject.should_receive(:puts).with('complete')
         
     | 
| 
      
 62 
     | 
    
         
            +
             
     | 
| 
      
 63 
     | 
    
         
            +
                    subject.format({ }, lambda { })
         
     | 
| 
      
 64 
     | 
    
         
            +
                  end
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
                  it 'performs a wrapped report overriding the message' do
         
     | 
| 
      
 67 
     | 
    
         
            +
                    subject.should_receive(:puts).with('test')
         
     | 
| 
      
 68 
     | 
    
         
            +
                    subject.should_receive(:puts).with('complete')
         
     | 
| 
      
 69 
     | 
    
         
            +
             
     | 
| 
      
 70 
     | 
    
         
            +
                    subject.format({:message => 'test'}, lambda { })
         
     | 
| 
      
 71 
     | 
    
         
            +
                  end
         
     | 
| 
      
 72 
     | 
    
         
            +
             
     | 
| 
      
 73 
     | 
    
         
            +
                  it 'performs an inline report' do
         
     | 
| 
      
 74 
     | 
    
         
            +
                    subject.should_receive(:print).with('test...')
         
     | 
| 
      
 75 
     | 
    
         
            +
                    subject.should_receive(:puts).with('complete')
         
     | 
| 
      
 76 
     | 
    
         
            +
                    subject.should_receive(:print).with('test2...')
         
     | 
| 
      
 77 
     | 
    
         
            +
                    subject.should_receive(:puts).with('complete')
         
     | 
| 
      
 78 
     | 
    
         
            +
             
     | 
| 
      
 79 
     | 
    
         
            +
                    subject.format({:message => 'test', :type => 'inline'}, lambda { })
         
     | 
| 
      
 80 
     | 
    
         
            +
                    subject.format({:message => 'test2', :type => 'inline'}, lambda { })
         
     | 
| 
      
 81 
     | 
    
         
            +
                  end
         
     | 
| 
      
 82 
     | 
    
         
            +
             
     | 
| 
      
 83 
     | 
    
         
            +
                  it 'overrides the default for all invocations of a wrapped report' do
         
     | 
| 
      
 84 
     | 
    
         
            +
                    subject.complete_string = 'done'
         
     | 
| 
      
 85 
     | 
    
         
            +
                    subject.should_receive(:puts).with('test')
         
     | 
| 
      
 86 
     | 
    
         
            +
                    subject.should_receive(:puts).with('done')
         
     | 
| 
      
 87 
     | 
    
         
            +
                    subject.should_receive(:puts).with('test2')
         
     | 
| 
      
 88 
     | 
    
         
            +
                    subject.should_receive(:puts).with('done')
         
     | 
| 
      
 89 
     | 
    
         
            +
             
     | 
| 
      
 90 
     | 
    
         
            +
                    subject.format({:message => 'test'}, lambda { })
         
     | 
| 
      
 91 
     | 
    
         
            +
                    subject.format({:message => 'test2'}, lambda { })
         
     | 
| 
      
 92 
     | 
    
         
            +
                  end
         
     | 
| 
      
 93 
     | 
    
         
            +
             
     | 
| 
      
 94 
     | 
    
         
            +
                  it 'overrides the default complete string for a wrapped report' do
         
     | 
| 
      
 95 
     | 
    
         
            +
                    subject.should_receive(:puts).with('test')
         
     | 
| 
      
 96 
     | 
    
         
            +
                    subject.should_receive(:puts).with('done')
         
     | 
| 
      
 97 
     | 
    
         
            +
                    subject.should_receive(:puts).with('test2')
         
     | 
| 
      
 98 
     | 
    
         
            +
                    subject.should_receive(:puts).with('finally')
         
     | 
| 
      
 99 
     | 
    
         
            +
             
     | 
| 
      
 100 
     | 
    
         
            +
                    subject.format({:message => 'test', :complete => 'done'}, lambda { })
         
     | 
| 
      
 101 
     | 
    
         
            +
                    subject.format({:message => 'test2', :complete => 'finally'}, lambda { })
         
     | 
| 
      
 102 
     | 
    
         
            +
                  end
         
     | 
| 
      
 103 
     | 
    
         
            +
             
     | 
| 
      
 104 
     | 
    
         
            +
                  it 'overrides the default complete string for an inline report' do
         
     | 
| 
      
 105 
     | 
    
         
            +
                    subject.should_receive(:print).with('test...')
         
     | 
| 
      
 106 
     | 
    
         
            +
                    subject.should_receive(:puts).with('done')
         
     | 
| 
      
 107 
     | 
    
         
            +
                    subject.should_receive(:print).with('test2...')
         
     | 
| 
      
 108 
     | 
    
         
            +
                    subject.should_receive(:puts).with('finally')
         
     | 
| 
      
 109 
     | 
    
         
            +
             
     | 
| 
      
 110 
     | 
    
         
            +
                    subject.format({:message => 'test', :type => 'inline', :complete => 'done'}, lambda { })
         
     | 
| 
      
 111 
     | 
    
         
            +
                    subject.format({:message => 'test2', :type => 'inline', :complete => 'finally'}, lambda { })
         
     | 
| 
      
 112 
     | 
    
         
            +
                  end
         
     | 
| 
      
 113 
     | 
    
         
            +
             
     | 
| 
      
 114 
     | 
    
         
            +
                  it 'performs another wrapped report to ensure defaul behavior' do
         
     | 
| 
      
 115 
     | 
    
         
            +
                    subject.should_receive(:puts).with('test')
         
     | 
| 
      
 116 
     | 
    
         
            +
                    subject.should_receive(:puts).with('complete')
         
     | 
| 
      
 117 
     | 
    
         
            +
                    subject.should_receive(:puts).with('test2')
         
     | 
| 
      
 118 
     | 
    
         
            +
                    subject.should_receive(:puts).with('complete')
         
     | 
| 
      
 119 
     | 
    
         
            +
             
     | 
| 
      
 120 
     | 
    
         
            +
                    subject.format({:message => 'test'}, lambda { })
         
     | 
| 
      
 121 
     | 
    
         
            +
                    subject.format({:message => 'test2'}, lambda { })
         
     | 
| 
      
 122 
     | 
    
         
            +
                  end
         
     | 
| 
      
 123 
     | 
    
         
            +
                end
         
     | 
| 
      
 124 
     | 
    
         
            +
             
     | 
| 
      
 125 
     | 
    
         
            +
                context 'nested commands' do
         
     | 
| 
      
 126 
     | 
    
         
            +
                  before :all do
         
     | 
| 
      
 127 
     | 
    
         
            +
                    @indent_size = subject.indent_size
         
     | 
| 
      
 128 
     | 
    
         
            +
                  end
         
     | 
| 
      
 129 
     | 
    
         
            +
             
     | 
| 
      
 130 
     | 
    
         
            +
                  # Restore the singleton to its original state to ensure clean tests
         
     | 
| 
      
 131 
     | 
    
         
            +
                  after :each do
         
     | 
| 
      
 132 
     | 
    
         
            +
                    subject.indent_size = @indent_size
         
     | 
| 
      
 133 
     | 
    
         
            +
                  end
         
     | 
| 
      
 134 
     | 
    
         
            +
             
     | 
| 
      
 135 
     | 
    
         
            +
                  it 'indents the nested wrapped messages' do
         
     | 
| 
      
 136 
     | 
    
         
            +
                    subject.should_receive(:puts).with('test')
         
     | 
| 
      
 137 
     | 
    
         
            +
                    subject.should_receive(:puts).with('  test2')
         
     | 
| 
      
 138 
     | 
    
         
            +
                    subject.should_receive(:puts).with('  complete')
         
     | 
| 
      
 139 
     | 
    
         
            +
                    subject.should_receive(:puts).with('complete')
         
     | 
| 
      
 140 
     | 
    
         
            +
             
     | 
| 
      
 141 
     | 
    
         
            +
                    nested = lambda {
         
     | 
| 
      
 142 
     | 
    
         
            +
                    }
         
     | 
| 
      
 143 
     | 
    
         
            +
             
     | 
| 
      
 144 
     | 
    
         
            +
                    subject.format({:message => 'test'}, lambda {
         
     | 
| 
      
 145 
     | 
    
         
            +
                      subject.format({:message => 'test2'}, lambda {})
         
     | 
| 
      
 146 
     | 
    
         
            +
                    })
         
     | 
| 
      
 147 
     | 
    
         
            +
                  end
         
     | 
| 
      
 148 
     | 
    
         
            +
             
     | 
| 
      
 149 
     | 
    
         
            +
                  it 'indents the multiple nested wrapped messages' do
         
     | 
| 
      
 150 
     | 
    
         
            +
                    subject.should_receive(:puts).with('test')
         
     | 
| 
      
 151 
     | 
    
         
            +
                    subject.should_receive(:puts).with('  test2')
         
     | 
| 
      
 152 
     | 
    
         
            +
                    subject.should_receive(:puts).with('    test3')
         
     | 
| 
      
 153 
     | 
    
         
            +
                    subject.should_receive(:puts).with('    complete')
         
     | 
| 
      
 154 
     | 
    
         
            +
                    subject.should_receive(:puts).with('  complete')
         
     | 
| 
      
 155 
     | 
    
         
            +
                    subject.should_receive(:puts).with('complete')
         
     | 
| 
      
 156 
     | 
    
         
            +
             
     | 
| 
      
 157 
     | 
    
         
            +
                    subject.format({:message => 'test'}, lambda {
         
     | 
| 
      
 158 
     | 
    
         
            +
                      subject.format({:message => 'test2'}, lambda {
         
     | 
| 
      
 159 
     | 
    
         
            +
                        subject.format({:message => 'test3'}, lambda { })
         
     | 
| 
      
 160 
     | 
    
         
            +
                      })
         
     | 
| 
      
 161 
     | 
    
         
            +
                    })
         
     | 
| 
      
 162 
     | 
    
         
            +
                  end
         
     | 
| 
      
 163 
     | 
    
         
            +
             
     | 
| 
      
 164 
     | 
    
         
            +
                  it 'indents the nested wrapped and inline messages' do
         
     | 
| 
      
 165 
     | 
    
         
            +
                    subject.should_receive(:puts).with('test')
         
     | 
| 
      
 166 
     | 
    
         
            +
                    subject.should_receive(:print).with('  test2...')
         
     | 
| 
      
 167 
     | 
    
         
            +
                    subject.should_receive(:puts).with('complete')
         
     | 
| 
      
 168 
     | 
    
         
            +
                    subject.should_receive(:puts).with('complete')
         
     | 
| 
      
 169 
     | 
    
         
            +
             
     | 
| 
      
 170 
     | 
    
         
            +
                    subject.format({:message => 'test'}, lambda {
         
     | 
| 
      
 171 
     | 
    
         
            +
                      subject.format({:message => 'test2', :type => 'inline'}, lambda { })
         
     | 
| 
      
 172 
     | 
    
         
            +
                    })
         
     | 
| 
      
 173 
     | 
    
         
            +
                  end
         
     | 
| 
      
 174 
     | 
    
         
            +
             
     | 
| 
      
 175 
     | 
    
         
            +
                  it 'indents the multiple nested wrapped messages' do
         
     | 
| 
      
 176 
     | 
    
         
            +
                    subject.should_receive(:puts).with('test')
         
     | 
| 
      
 177 
     | 
    
         
            +
                    subject.should_receive(:puts).with('  test2')
         
     | 
| 
      
 178 
     | 
    
         
            +
                    subject.should_receive(:print).with('    test3...')
         
     | 
| 
      
 179 
     | 
    
         
            +
                    subject.should_receive(:puts).with('complete')
         
     | 
| 
      
 180 
     | 
    
         
            +
                    subject.should_receive(:puts).with('  complete')
         
     | 
| 
      
 181 
     | 
    
         
            +
                    subject.should_receive(:puts).with('complete')
         
     | 
| 
      
 182 
     | 
    
         
            +
             
     | 
| 
      
 183 
     | 
    
         
            +
                    subject.format({:message => 'test'}, lambda {
         
     | 
| 
      
 184 
     | 
    
         
            +
                      subject.format({:message => 'test2'}, lambda {
         
     | 
| 
      
 185 
     | 
    
         
            +
                        subject.format({:message => 'test3', :type => 'inline'}, lambda { })
         
     | 
| 
      
 186 
     | 
    
         
            +
                      })
         
     | 
| 
      
 187 
     | 
    
         
            +
                    })
         
     | 
| 
      
 188 
     | 
    
         
            +
                  end
         
     | 
| 
      
 189 
     | 
    
         
            +
             
     | 
| 
      
 190 
     | 
    
         
            +
                  it 'overrides the indent spacing of all messages' do
         
     | 
| 
      
 191 
     | 
    
         
            +
                    subject.should_receive(:puts).with('test')
         
     | 
| 
      
 192 
     | 
    
         
            +
                    subject.should_receive(:puts).with('    test2')
         
     | 
| 
      
 193 
     | 
    
         
            +
                    subject.should_receive(:print).with('        test3...')
         
     | 
| 
      
 194 
     | 
    
         
            +
                    subject.should_receive(:puts).with('complete')
         
     | 
| 
      
 195 
     | 
    
         
            +
                    subject.should_receive(:puts).with('    complete')
         
     | 
| 
      
 196 
     | 
    
         
            +
                    subject.should_receive(:puts).with('complete')
         
     | 
| 
      
 197 
     | 
    
         
            +
             
     | 
| 
      
 198 
     | 
    
         
            +
                    subject.indent_size = 4
         
     | 
| 
      
 199 
     | 
    
         
            +
             
     | 
| 
      
 200 
     | 
    
         
            +
                    subject.format({:message => 'test'}, lambda {
         
     | 
| 
      
 201 
     | 
    
         
            +
                      subject.format({:message => 'test2'}, lambda {
         
     | 
| 
      
 202 
     | 
    
         
            +
                        subject.format({:message => 'test3', :type => 'inline'}, lambda { })
         
     | 
| 
      
 203 
     | 
    
         
            +
                      })
         
     | 
| 
      
 204 
     | 
    
         
            +
                    })
         
     | 
| 
      
 205 
     | 
    
         
            +
                  end
         
     | 
| 
      
 206 
     | 
    
         
            +
             
     | 
| 
      
 207 
     | 
    
         
            +
                  it 'overrides the indent spacing of specific message' do
         
     | 
| 
      
 208 
     | 
    
         
            +
                    subject.should_receive(:puts).with('test')
         
     | 
| 
      
 209 
     | 
    
         
            +
                    subject.should_receive(:puts).with('      test2')
         
     | 
| 
      
 210 
     | 
    
         
            +
                    subject.should_receive(:print).with('      test3...')
         
     | 
| 
      
 211 
     | 
    
         
            +
                    subject.should_receive(:puts).with('complete')
         
     | 
| 
      
 212 
     | 
    
         
            +
                    subject.should_receive(:puts).with('      complete')
         
     | 
| 
      
 213 
     | 
    
         
            +
                    subject.should_receive(:puts).with('complete')
         
     | 
| 
      
 214 
     | 
    
         
            +
             
     | 
| 
      
 215 
     | 
    
         
            +
                    subject.indent_size = 4
         
     | 
| 
      
 216 
     | 
    
         
            +
             
     | 
| 
      
 217 
     | 
    
         
            +
                    subject.format({:message => 'test'}, lambda {
         
     | 
| 
      
 218 
     | 
    
         
            +
                      subject.format({:message => 'test2', :indent_size => 6}, lambda {
         
     | 
| 
      
 219 
     | 
    
         
            +
                        subject.format({:message => 'test3', :type => 'inline', :indent_size => 3}, lambda { })
         
     | 
| 
      
 220 
     | 
    
         
            +
                      }) 
         
     | 
| 
      
 221 
     | 
    
         
            +
                    })
         
     | 
| 
      
 222 
     | 
    
         
            +
                  end
         
     | 
| 
      
 223 
     | 
    
         
            +
             
     | 
| 
      
 224 
     | 
    
         
            +
                  it 'performs the sums specified in the block' do
         
     | 
| 
      
 225 
     | 
    
         
            +
                    x,y,z = 0,0,0
         
     | 
| 
      
 226 
     | 
    
         
            +
             
     | 
| 
      
 227 
     | 
    
         
            +
                    subject.should_receive(:puts).with('sum x and 10')
         
     | 
| 
      
 228 
     | 
    
         
            +
                    subject.should_receive(:puts).with('  y is the difference of 20 and x')
         
     | 
| 
      
 229 
     | 
    
         
            +
                    subject.should_receive(:puts).with('    z = x + y')
         
     | 
| 
      
 230 
     | 
    
         
            +
                    subject.should_receive(:puts).with('    complete')
         
     | 
| 
      
 231 
     | 
    
         
            +
                    subject.should_receive(:puts).with('  complete')
         
     | 
| 
      
 232 
     | 
    
         
            +
                    subject.should_receive(:puts).with('complete')
         
     | 
| 
      
 233 
     | 
    
         
            +
             
     | 
| 
      
 234 
     | 
    
         
            +
                    subject.format({:message => 'sum x and 10'}, lambda {
         
     | 
| 
      
 235 
     | 
    
         
            +
                      x = x + 10
         
     | 
| 
      
 236 
     | 
    
         
            +
                      subject.format({:message => 'y is the difference of 20 and x'}, lambda {
         
     | 
| 
      
 237 
     | 
    
         
            +
                        y = 20 - x
         
     | 
| 
      
 238 
     | 
    
         
            +
                        subject.format({:message => 'z = x + y'}, lambda {
         
     | 
| 
      
 239 
     | 
    
         
            +
                          z = x + y
         
     | 
| 
      
 240 
     | 
    
         
            +
                        })
         
     | 
| 
      
 241 
     | 
    
         
            +
                      })
         
     | 
| 
      
 242 
     | 
    
         
            +
                    })
         
     | 
| 
      
 243 
     | 
    
         
            +
             
     | 
| 
      
 244 
     | 
    
         
            +
                    x.should == 10
         
     | 
| 
      
 245 
     | 
    
         
            +
                    y.should == 10
         
     | 
| 
      
 246 
     | 
    
         
            +
                    z.should == 20
         
     | 
| 
      
 247 
     | 
    
         
            +
                  end
         
     | 
| 
      
 248 
     | 
    
         
            +
                end
         
     | 
| 
      
 249 
     | 
    
         
            +
              end
         
     | 
| 
      
 250 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,61 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'spec_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'progress_formatter'
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            describe CommandLineReporter::ProgressFormatter do
         
     | 
| 
      
 5 
     | 
    
         
            +
              subject { CommandLineReporter::ProgressFormatter.instance }
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
              describe '#method default values' do
         
     | 
| 
      
 8 
     | 
    
         
            +
                its(:indicator) { should == '.' }
         
     | 
| 
      
 9 
     | 
    
         
            +
              end
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
              describe '#format' do
         
     | 
| 
      
 12 
     | 
    
         
            +
                it 'displays dots for the indicator' do
         
     | 
| 
      
 13 
     | 
    
         
            +
                  subject.should_receive(:print).exactly(10).times.with('.')
         
     | 
| 
      
 14 
     | 
    
         
            +
                  subject.should_receive(:puts).exactly(1).times
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                  subject.format({}, lambda {
         
     | 
| 
      
 17 
     | 
    
         
            +
                    10.times {subject.progress}
         
     | 
| 
      
 18 
     | 
    
         
            +
                  })
         
     | 
| 
      
 19 
     | 
    
         
            +
                end
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                it 'uses the defined indicator' do
         
     | 
| 
      
 22 
     | 
    
         
            +
                  subject.indicator = '+'
         
     | 
| 
      
 23 
     | 
    
         
            +
                  subject.should_receive(:print).exactly(10).times.with('+')
         
     | 
| 
      
 24 
     | 
    
         
            +
                  subject.should_receive(:puts)
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                  subject.format({}, lambda {
         
     | 
| 
      
 27 
     | 
    
         
            +
                    10.times {subject.progress}
         
     | 
| 
      
 28 
     | 
    
         
            +
                  })
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
                end
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
                it 'allows override of the indicator' do
         
     | 
| 
      
 33 
     | 
    
         
            +
                  subject.should_receive(:print).exactly(10).times.with('=')
         
     | 
| 
      
 34 
     | 
    
         
            +
                  subject.should_receive(:puts)
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
                  subject.format({:indicator => '='}, lambda {
         
     | 
| 
      
 37 
     | 
    
         
            +
                    10.times {subject.progress}
         
     | 
| 
      
 38 
     | 
    
         
            +
                  })
         
     | 
| 
      
 39 
     | 
    
         
            +
                end
         
     | 
| 
      
 40 
     | 
    
         
            +
              end
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
              describe '#progress' do
         
     | 
| 
      
 43 
     | 
    
         
            +
                it 'allows override of the indicator' do
         
     | 
| 
      
 44 
     | 
    
         
            +
                  subject.should_receive(:print).exactly(10).times.with('+')
         
     | 
| 
      
 45 
     | 
    
         
            +
                  subject.should_receive(:puts)
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
                  subject.format({}, lambda {
         
     | 
| 
      
 48 
     | 
    
         
            +
                    10.times {subject.progress('+')}
         
     | 
| 
      
 49 
     | 
    
         
            +
                  })
         
     | 
| 
      
 50 
     | 
    
         
            +
                end
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
      
 52 
     | 
    
         
            +
                it 'allows any indicator' do
         
     | 
| 
      
 53 
     | 
    
         
            +
                  subject.should_receive(:print).exactly(10).times
         
     | 
| 
      
 54 
     | 
    
         
            +
                  subject.should_receive(:puts)
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
                  subject.format({}, lambda {
         
     | 
| 
      
 57 
     | 
    
         
            +
                    10.times {|i| subject.progress("#{i}")}
         
     | 
| 
      
 58 
     | 
    
         
            +
                  })
         
     | 
| 
      
 59 
     | 
    
         
            +
                end
         
     | 
| 
      
 60 
     | 
    
         
            +
              end
         
     | 
| 
      
 61 
     | 
    
         
            +
            end
         
     | 
    
        data/spec/spec_helper.rb
    ADDED
    
    | 
         @@ -0,0 +1 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            $: << File.join(File.dirname(__FILE__), '..', 'lib')
         
     | 
    
        metadata
    ADDED
    
    | 
         @@ -0,0 +1,75 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            --- !ruby/object:Gem::Specification
         
     | 
| 
      
 2 
     | 
    
         
            +
            name: command_line_reporter
         
     | 
| 
      
 3 
     | 
    
         
            +
            version: !ruby/object:Gem::Version
         
     | 
| 
      
 4 
     | 
    
         
            +
              version: 1.0.0
         
     | 
| 
      
 5 
     | 
    
         
            +
              prerelease: 
         
     | 
| 
      
 6 
     | 
    
         
            +
            platform: ruby
         
     | 
| 
      
 7 
     | 
    
         
            +
            authors:
         
     | 
| 
      
 8 
     | 
    
         
            +
            - Wes
         
     | 
| 
      
 9 
     | 
    
         
            +
            - Bailey
         
     | 
| 
      
 10 
     | 
    
         
            +
            autorequire: 
         
     | 
| 
      
 11 
     | 
    
         
            +
            bindir: bin
         
     | 
| 
      
 12 
     | 
    
         
            +
            cert_chain: []
         
     | 
| 
      
 13 
     | 
    
         
            +
            date: 2011-11-28 00:00:00.000000000Z
         
     | 
| 
      
 14 
     | 
    
         
            +
            dependencies:
         
     | 
| 
      
 15 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 16 
     | 
    
         
            +
              name: bundler
         
     | 
| 
      
 17 
     | 
    
         
            +
              requirement: &2151943860 !ruby/object:Gem::Requirement
         
     | 
| 
      
 18 
     | 
    
         
            +
                none: false
         
     | 
| 
      
 19 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 20 
     | 
    
         
            +
                - - ! '>='
         
     | 
| 
      
 21 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 22 
     | 
    
         
            +
                    version: 1.0.0
         
     | 
| 
      
 23 
     | 
    
         
            +
              type: :development
         
     | 
| 
      
 24 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 25 
     | 
    
         
            +
              version_requirements: *2151943860
         
     | 
| 
      
 26 
     | 
    
         
            +
            description: This gem makes it easy to provide a report while your ruby script is
         
     | 
| 
      
 27 
     | 
    
         
            +
              executing
         
     | 
| 
      
 28 
     | 
    
         
            +
            email: baywes@gmail.com
         
     | 
| 
      
 29 
     | 
    
         
            +
            executables: []
         
     | 
| 
      
 30 
     | 
    
         
            +
            extensions: []
         
     | 
| 
      
 31 
     | 
    
         
            +
            extra_rdoc_files: []
         
     | 
| 
      
 32 
     | 
    
         
            +
            files:
         
     | 
| 
      
 33 
     | 
    
         
            +
            - examples/nested.rb
         
     | 
| 
      
 34 
     | 
    
         
            +
            - examples/progress.rb
         
     | 
| 
      
 35 
     | 
    
         
            +
            - lib/command_line_reporter.rb
         
     | 
| 
      
 36 
     | 
    
         
            +
            - lib/nested_formatter.rb
         
     | 
| 
      
 37 
     | 
    
         
            +
            - lib/progress_formatter.rb
         
     | 
| 
      
 38 
     | 
    
         
            +
            - lib/version.rb
         
     | 
| 
      
 39 
     | 
    
         
            +
            - README.md
         
     | 
| 
      
 40 
     | 
    
         
            +
            - spec/command_line_reporter_spec.rb
         
     | 
| 
      
 41 
     | 
    
         
            +
            - spec/nested_formatter_spec.rb
         
     | 
| 
      
 42 
     | 
    
         
            +
            - spec/progress_formatter_spec.rb
         
     | 
| 
      
 43 
     | 
    
         
            +
            - spec/spec_helper.rb
         
     | 
| 
      
 44 
     | 
    
         
            +
            homepage: http://github.com/wbailey/command_line_reporter
         
     | 
| 
      
 45 
     | 
    
         
            +
            licenses: []
         
     | 
| 
      
 46 
     | 
    
         
            +
            post_install_message: 
         
     | 
| 
      
 47 
     | 
    
         
            +
            rdoc_options: []
         
     | 
| 
      
 48 
     | 
    
         
            +
            require_paths:
         
     | 
| 
      
 49 
     | 
    
         
            +
            - lib
         
     | 
| 
      
 50 
     | 
    
         
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 51 
     | 
    
         
            +
              none: false
         
     | 
| 
      
 52 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 53 
     | 
    
         
            +
              - - ! '>='
         
     | 
| 
      
 54 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 55 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 56 
     | 
    
         
            +
                  segments:
         
     | 
| 
      
 57 
     | 
    
         
            +
                  - 0
         
     | 
| 
      
 58 
     | 
    
         
            +
                  hash: 4291773844303302858
         
     | 
| 
      
 59 
     | 
    
         
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 60 
     | 
    
         
            +
              none: false
         
     | 
| 
      
 61 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 62 
     | 
    
         
            +
              - - ! '>='
         
     | 
| 
      
 63 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 64 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 65 
     | 
    
         
            +
            requirements: []
         
     | 
| 
      
 66 
     | 
    
         
            +
            rubyforge_project: 
         
     | 
| 
      
 67 
     | 
    
         
            +
            rubygems_version: 1.8.10
         
     | 
| 
      
 68 
     | 
    
         
            +
            signing_key: 
         
     | 
| 
      
 69 
     | 
    
         
            +
            specification_version: 3
         
     | 
| 
      
 70 
     | 
    
         
            +
            summary: A tool for providing interactive command line applications
         
     | 
| 
      
 71 
     | 
    
         
            +
            test_files:
         
     | 
| 
      
 72 
     | 
    
         
            +
            - spec/command_line_reporter_spec.rb
         
     | 
| 
      
 73 
     | 
    
         
            +
            - spec/nested_formatter_spec.rb
         
     | 
| 
      
 74 
     | 
    
         
            +
            - spec/progress_formatter_spec.rb
         
     | 
| 
      
 75 
     | 
    
         
            +
            - spec/spec_helper.rb
         
     |