fuubar-2.0.0/0000755000076400007640000000000012404034046012026 5ustar pravipravifuubar-2.0.0/spec/0000755000076400007640000000000012404034046012760 5ustar pravipravifuubar-2.0.0/spec/fuubar_spec.rb0000644000076400007640000001673112404034046015613 0ustar pravipravirequire 'fuubar' require 'stringio' require 'ostruct' describe Fuubar do let(:output) do io = StringIO.new allow(io).to receive(:tty?). and_return(true) io end let(:formatter) { Fuubar.new(output) } let(:example) { RSpec::Core::ExampleGroup.describe.example } let(:example_count) { 2 } let(:start_notification) { RSpec::Core::Notifications::StartNotification.new(example_count, Time.now) } let(:message_notification) { RSpec::Core::Notifications::MessageNotification.new('My Message') } let(:example_notification) { RSpec::Core::Notifications::ExampleNotification.for(example) } let(:pending_notification) { RSpec::Core::Notifications::ExampleNotification.for(pending_example) } let(:failed_notification) { RSpec::Core::Notifications::ExampleNotification.for(failed_example) } let(:failed_example) do exception = RuntimeError.new('Test Fuubar Error') exception.set_backtrace [ "/my/filename.rb:4:in `some_method'", ] example = RSpec::Core::ExampleGroup.describe.example example.metadata[:file_path] = '/my/example/spec.rb' example.metadata[:execution_result].status = :failed example.metadata[:execution_result].exception = exception example end let(:pending_example) do example = RSpec::Core::ExampleGroup.describe.example example.metadata[:execution_result].pending_fixed = true example end let(:fuubar_results) do output.rewind output.read end before(:each) do RSpec.configuration.fuubar_progress_bar_options = { :length => 40, :throttle_rate => 0.0, } ENV.delete('CONTINUOUS_INTEGRATION') end context 'when it is created' do it 'does not start the bar until the formatter is started' do expect(formatter.progress).not_to be_started formatter.start(start_notification) expect(formatter.progress).to be_started end it 'creates a new ProgressBar' do expect(formatter.progress).to be_instance_of ProgressBar::Base end it 'sets the format of the bar to the default' do expect(formatter.progress.instance_variable_get(:@format_string)).to eql ' %c/%C |%w>%i| %e ' end it 'sets the total to the number of examples' do expect(formatter.progress.total).to be_zero end it 'sets the bar\'s output' do expect(formatter.progress.send(:output)).to eql formatter.output expect(formatter.progress.send(:output)).to eql output end context 'and continuous integration is enabled' do before do RSpec.configuration.fuubar_progress_bar_options = {:length => 40} ENV['CONTINUOUS_INTEGRATION'] = 'true' end it 'throttles the progress bar at one second' do throttle = formatter.progress.instance_variable_get(:@throttle) throttle_rate = throttle.instance_variable_get(:@period) expect(throttle_rate).to eql 1.0 end context 'when processing an example' do before do formatter.start(start_notification) throttle = formatter.progress.instance_variable_get(:@throttle) throttle_rate = throttle.instance_variable_set(:@period, 0.0) output.rewind formatter.example_passed(example) end it 'does not output color codes' do expect(fuubar_results).to start_with " 1/2 |== 50 ==> | ETA: 00:00:00 \r" end end end context 'and continuous integration is not enabled' do before do RSpec.configuration.fuubar_progress_bar_options = {:length => 40} ENV['CONTINUOUS_INTEGRATION'] = 'false' end it 'throttles the progress bar at the default rate' do throttle = formatter.progress.instance_variable_get(:@throttle) throttle_rate = throttle.instance_variable_get(:@period) expect(throttle_rate).to eql 0.01 end context 'when processing an example' do before do formatter.start(start_notification) throttle = formatter.progress.instance_variable_get(:@throttle) throttle_rate = throttle.instance_variable_set(:@period, 0.0) output.rewind formatter.example_passed(example) end it 'does not output color codes' do expect(fuubar_results).to start_with "\e[32m 1/2 |== 50 ==> | ETA: 00:00:00 \r\e[0m" end end end end context 'when custom options are set after the formatter is created' do before(:each) do formatter RSpec.configuration.fuubar_progress_bar_options = { :length => 40, :throttle_rate => 0.0, :format => '%c', } end context 'when the bar is started' do before(:each) { formatter.start(start_notification) } it 'properly creates the bar' do expect(formatter.progress.instance_variable_get(:@format_string)).to eql '%c' end end end context 'when it is started' do before { formatter.start(start_notification) } it 'sets the total to the number of examples' do expect(formatter.progress.total).to eql 2 end context 'and no custom options are passed in' do it 'sets the format of the bar to the default' do expect(formatter.progress.instance_variable_get(:@format_string)).to eql ' %c/%C |%w>%i| %e ' end end context 'and an example passes' do before do output.rewind formatter.example_passed(example) end it 'outputs the proper bar information' do expect(fuubar_results).to start_with "\e[32m 1/2 |== 50 ==> | ETA: 00:00:00 \r\e[0m" end end context 'and an example pends' do before do output.rewind formatter.example_pending(pending_example) end it 'outputs the proper bar information' do formatter.progress.increment expect(fuubar_results).to start_with "\e[33m 1/2 |== 50 ==> | ETA: 00:00:00 \r\e[0m" end context 'and then an example succeeds' do before do output.rewind formatter.example_pending(pending_notification) end it 'outputs the pending bar' do expect(fuubar_results).to start_with "\e[33m 2/2 |===== 100 ======>| Time: 00:00:00 \n\e[0m" end end end context 'and an example fails' do it 'outputs the proper bar information' do output.rewind formatter.example_failed(failed_notification) expect(fuubar_results).to end_with "\e[31m 1/2 |== 50 ==> | ETA: 00:00:00 \r\e[0m" end context 'and then an example succeeds' do before do formatter.example_failed(failed_notification) output.rewind formatter.example_passed(example) end it 'outputs the failed bar' do expect(fuubar_results).to start_with "\e[31m 2/2 |===== 100 ======>| Time: 00:00:00 \n\e[0m" end end context 'and then an example pends' do before do formatter.example_failed(failed_notification) output.rewind formatter.example_pending(example_notification) end it 'outputs the failed bar' do expect(fuubar_results).to start_with "\e[31m 2/2 |===== 100 ======>| Time: 00:00:00 \n\e[0m" end end end it 'can properly log messages' do formatter.message message_notification expect(fuubar_results).to end_with "My Message\n 0/2 |> | ETA: ??:??:?? \r" end end end fuubar-2.0.0/LICENSE0000644000076400007640000000215112404034046013032 0ustar pravipravi(The MIT License) Copyright (c) 2010 Jeff Kreeftmeijer. Copyright (c) 2013 The Kompanee - Jeff Felchner Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. fuubar-2.0.0/README.md0000644000076400007640000000571512404034046013315 0ustar pravipravi#Fuubar [![Gem Version](https://badge.fury.io/rb/fuubar.png)](https://badge.fury.io/rb/fuubar) [![Build Status](https://secure.travis-ci.org/thekompanee/fuubar.png?branch=master)](http://travis-ci.org/thekompanee/fuubar) [![Code Climate](https://codeclimate.com/github/thekompanee/fuubar.png)](https://codeclimate.com/github/thekompanee/fuubar) [![Code Climate](https://codeclimate.com/github/thekompanee/fuubar/coverage.png)](https://codeclimate.com/github/thekompanee/fuubar) Fuubar is an instafailing [RSpec](http://github.com/rspec) formatter that uses a progress bar instead of a string of letters and dots as feedback. Here's [a video of Fuubar in action](http://vimeo.com/16845253). Supported Rubies -------------------------------- * MRI Ruby 1.8.7 * MRI Ruby 1.9.2 * MRI Ruby 1.9.3 * MRI Ruby 2.0.0 * MRI Ruby 2.1.0 * JRuby (in 1.8 compat mode) * JRuby (in 1.9 compat mode) Installation -------------------------------------------------------------------------------- First: ```ruby gem install fuubar ``` or in your Gemfile ```ruby gem 'fuubar' ``` Then, when running rspec: ``` rspec --format Fuubar --color spec ``` Or, if you want to use Fuubar as your default formatter, simply put the options in your `.rspec` file: --format Fuubar --color Advanced Usage -------------------------------- ### Customizing the Bar ### Fuubar exposes an RSpec configuration variable called `fuubar_progress_bar_options` which, when set will be passed directly to [ruby-progressbar](https://github.com/jfelchner/ruby-progressbar) which does all the heavy lifting. Take a look at the documentation for details on all of the options you can pass in. Let's say for example that you would like to change the format of the bar. You would do that like so: ```ruby # spec_helper.rb RSpec.configure do |config| config.fuubar_progress_bar_options = { :format => 'My Fuubar! <%B> %p%% %a' } end ``` would make it so that, when Fuubar is output, it would look something like: My Fuubar! <================================ > 53.44% 00:12:31 Issues -------------------------------- If you have problems, please create a [Github issue](https://github.com/jeffkreeftmeijer/fuubar/issues). Credits -------------------------------- fuubar was created by [Jeff Kreeftmeijer](https://github.com/jeffkreeftmeijer) fuubar is maintained by [Jeff Kreeftmeijer](https://github.com/jeffkreeftmeijer) and [The Kompanee, Ltd.](http://www.thekompanee.com) Contributing -------------------------------------------------------------------------------- Found an issue? Have a great idea? Want to help? Great! Create an issue [issue](http://github.com/jeffkreeftmeijer/fuubar/issues) for it, or even better; fork the project and fix the problem yourself. Pull requests are always welcome. :) License -------------------------------- fuubar is Copyright © 2010-2013 Jeff Kreeftmeijer and Jeff Felchner. It is free software, and may be redistributed under the terms specified in the LICENSE file. fuubar-2.0.0/metadata.yml0000644000076400007640000000345412404034046014337 0ustar pravipravi--- !ruby/object:Gem::Specification name: fuubar version: !ruby/object:Gem::Version version: 2.0.0 platform: ruby authors: - Nicholas Evans - Jeff Kreeftmeijer - jfelchner autorequire: bindir: bin cert_chain: [] date: 2014-08-07 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: rspec requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '3.0' type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '3.0' - !ruby/object:Gem::Dependency name: ruby-progressbar requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '1.4' type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '1.4' description: the instafailing RSpec progress bar formatter email: - jeff@kreeftmeijer.nl executables: [] extensions: [] extra_rdoc_files: - README.md - LICENSE files: - LICENSE - README.md - lib/fuubar.rb - spec/fuubar_spec.rb homepage: https://github.com/jeffkreeftmeijer/fuubar licenses: - MIT metadata: {} post_install_message: rdoc_options: - "--charset" - UTF-8 require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' required_rubygems_version: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' requirements: [] rubyforge_project: rubygems_version: 2.2.2 signing_key: specification_version: 4 summary: the instafailing RSpec progress bar formatter test_files: - spec/fuubar_spec.rb fuubar-2.0.0/lib/0000755000076400007640000000000012404034046012574 5ustar pravipravifuubar-2.0.0/lib/fuubar.rb0000644000076400007640000000652312404034046014413 0ustar pravipravirequire 'rspec' require 'rspec/core/formatters/base_text_formatter' require 'ruby-progressbar' RSpec.configuration.add_setting :fuubar_progress_bar_options, :default => {} class Fuubar < RSpec::Core::Formatters::BaseTextFormatter DEFAULT_PROGRESS_BAR_OPTIONS = { :format => ' %c/%C |%w>%i| %e ' } RSpec::Core::Formatters.register self, :start, :message, :example_passed, :example_pending, :example_failed, :dump_failures attr_accessor :progress, :passed_count, :pending_count, :failed_count def initialize(*args) super self.progress = ProgressBar.create(DEFAULT_PROGRESS_BAR_OPTIONS. merge(:throttle_rate => continuous_integration? ? 1.0 : nil). merge(:total => 0, :output => output, :autostart => false)) end def start(notification) progress_bar_options = DEFAULT_PROGRESS_BAR_OPTIONS. merge(:throttle_rate => continuous_integration? ? 1.0 : nil). merge(configuration.fuubar_progress_bar_options). merge(:total => notification.count, :output => output, :autostart => false) self.progress = ProgressBar.create(progress_bar_options) self.passed_count = 0 self.pending_count = 0 self.failed_count = 0 super with_current_color { progress.start } end def example_passed(notification) self.passed_count += 1 increment end def example_pending(notification) self.pending_count += 1 increment end def example_failed(notification) self.failed_count += 1 progress.clear output.puts notification.fully_formatted(failed_count) output.puts increment end def message(notification) if progress.respond_to? :log progress.log(notification.message) else super end end def dump_failures(notification) # # We output each failure as it happens so we don't need to output them en # masse at the end of the run. # end private def increment with_current_color { progress.increment } end def with_current_color output.print "\e[#{color_code_for(current_color)}m" if color_enabled? yield output.print "\e[0m" if color_enabled? end def color_enabled? configuration.color_enabled? && !continuous_integration? end def current_color if failed_count > 0 configuration.failure_color elsif pending_count > 0 configuration.pending_color else configuration.success_color end end def color_code_for(*args) RSpec::Core::Formatters::ConsoleCodes.console_code_for(*args) end def configuration RSpec.configuration end def continuous_integration? @continuous_integration ||= !(ENV['CONTINUOUS_INTEGRATION'].nil? || ENV['CONTINUOUS_INTEGRATION'] == '' || ENV['CONTINUOUS_INTEGRATION'] == 'false') end end