iterm2_tab_formatter 0.7.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.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
@@ -0,0 +1,7 @@
1
+ before_install: gem install bundler -v 1.3.2
2
+ language: ruby
3
+ rvm:
4
+ - "1.9.3"
5
+ - "2.0.0"
6
+ notifications:
7
+ email: false
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in iterm2_tab_formatter.gemspec
4
+ gemspec
5
+
6
+ group :development, :test do
7
+ gem 'rake'
8
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Mark Rushakoff
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,47 @@
1
+ # Iterm2TabFormatter
2
+
3
+ [![Build Status](https://travis-ci.org/mark-rushakoff/iterm2_tab_formatter.png)](https://travis-ci.org/mark-rushakoff/iterm2_tab_formatter)
4
+ [![Code Climate](https://codeclimate.com/github/mark-rushakoff/iterm2_tab_formatter.png)](https://codeclimate.com/github/mark-rushakoff/iterm2_tab_formatter)
5
+
6
+ An RSpec2 formatter that uses your iTerm2 tabs' color and titles to inform you of your spec status.
7
+
8
+ iTerm2 Tab Formatter communicates your RSpec status through your iTerm2 tabs.
9
+ By default, here's what it does:
10
+ * Tab chrome color:
11
+ * Gray while spec is running/pending
12
+ * Red once a spec has failed
13
+ * Green if all the specs pass
14
+ * Tab title:
15
+ * Index of current spec and total number of specs
16
+ * Percentage of specs that passed, after specs finish
17
+ * Window title:
18
+ * Full spec name for the current spec
19
+ * Summary, duration, and finish time after specs finish
20
+
21
+ (iterm2_tab_formatter is in no way affiliated with [iTerm2](https://github.com/gnachman/iTerm2) -- it was just made by a fan.)
22
+
23
+ ## Installation
24
+
25
+ Add this line to your application's Gemfile:
26
+
27
+ gem 'iterm2_tab_formatter'
28
+
29
+ And then execute:
30
+
31
+ $ bundle
32
+
33
+ Or install it yourself as:
34
+
35
+ $ gem install iterm2_tab_formatter
36
+
37
+ ## Usage
38
+
39
+ TODO: Write usage instructions here
40
+
41
+ ## Contributing
42
+
43
+ 1. Fork it
44
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
45
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
46
+ 4. Push to the branch (`git push origin my-new-feature`)
47
+ 5. Create new Pull Request
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec) do |t|
5
+ t.pattern = 'spec/**/*_spec.rb'
6
+ t.rspec_opts = %w(--format documentation --color)
7
+ end
8
+
9
+ task :default => :spec
@@ -0,0 +1,33 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'iterm2_tab_formatter/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "iterm2_tab_formatter"
8
+ gem.version = Iterm2TabFormatter::VERSION
9
+ gem.authors = ["Mark Rushakoff"]
10
+ gem.email = ["mark.rushakoff@gmail.com"]
11
+ gem.description = %q{An RSpec2 formatter that uses your iTerm2 tabs' color and titles to inform you of your spec status.}
12
+ gem.summary = <<-SUMMARY
13
+ iTerm2 Tab Formatter communicates your RSpec status through your iTerm2 tabs.
14
+ By default, here's what it does:
15
+ * Tab chrome color:
16
+ * Gray while spec is running/pending
17
+ * Red once a spec has failed
18
+ * Green if all the specs pass
19
+ * Tab title:
20
+ * Index of current spec and total number of specs
21
+ * Window title:
22
+ * Full spec name for the current spec
23
+ SUMMARY
24
+ gem.homepage = "https://github.com/mark-rushakoff/iterm2_tab_formatter"
25
+
26
+ gem.files = `git ls-files`.split($/)
27
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
28
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
29
+ gem.require_paths = ["lib"]
30
+
31
+ gem.add_runtime_dependency 'iterm2_escape', '~> 1.0'
32
+ gem.add_runtime_dependency 'rspec', '~> 2.13'
33
+ end
@@ -0,0 +1,49 @@
1
+ require 'iterm2_tab_formatter/base'
2
+ require "iterm2_tab_formatter/version"
3
+ require "iterm2_tab_formatter/controller"
4
+ require "iterm2_tab_formatter/text_formatter"
5
+
6
+ class Iterm2TabFormatter
7
+ attr_reader :controller
8
+
9
+ def initialize(output)
10
+ super
11
+ colors = {
12
+ suite_start: [128, 128, 128],
13
+ spec_fail: [255, 0, 0],
14
+ suite_pass: [0, 255, 0]
15
+ }
16
+ @controller = Iterm2TabFormatter::Controller.new(colors)
17
+ end
18
+
19
+ def start(example_count)
20
+ super
21
+ controller.apply_start_color
22
+ end
23
+
24
+ def example_failed(example)
25
+ super
26
+ controller.apply_fail_color
27
+ end
28
+
29
+ def example_started(example)
30
+ super
31
+
32
+ controller.window_title = example.description
33
+ controller.tab_title = "#{examples.size - 1}/#{example_count}"
34
+ end
35
+
36
+ def dump_summary(duration, example_count, failure_count, pending_count)
37
+ controller.apply_pass_color if failure_count == 0 && example_count > 0
38
+
39
+ pass_ratio = 1 - (1.0 * failure_count / example_count)
40
+ controller.tab_title = "#{pass_ratio * 100}% passed"
41
+
42
+ window_title = Iterm2TabFormatter::TextFormatter.window_title(8, 1, 2)
43
+ window_title << ' - '
44
+ window_title << Iterm2TabFormatter::TextFormatter.duration(duration)
45
+ window_title << ' - Finished at '
46
+ window_title << Iterm2TabFormatter::TextFormatter.finished_at(Time.now)
47
+ controller.window_title = window_title
48
+ end
49
+ end
@@ -0,0 +1,6 @@
1
+ require 'iterm2_tab_formatter'
2
+ require 'rspec/core/configuration'
3
+
4
+ RSpec.configure do |c|
5
+ c.add_formatter(Iterm2TabFormatter)
6
+ end
@@ -0,0 +1,9 @@
1
+ # This file exists only so that we don't have to declare the base class
2
+ # anywhere else. This is why modules are usually used for the top level, but
3
+ # in this case I think it has to be a class for RSpec to load the formatter
4
+ # properly.
5
+
6
+ require 'rspec/core/formatters/base_formatter'
7
+
8
+ class Iterm2TabFormatter < RSpec::Core::Formatters::BaseFormatter
9
+ end
@@ -0,0 +1,30 @@
1
+ require 'iterm2_tab_formatter/base'
2
+ require 'iterm2_escape'
3
+
4
+ class Iterm2TabFormatter
5
+ class Controller
6
+ def initialize(colors)
7
+ @colors = colors
8
+ end
9
+
10
+ def apply_start_color
11
+ Iterm2Escape::Tab.set_color(*@colors.fetch(:suite_start))
12
+ end
13
+
14
+ def apply_fail_color
15
+ Iterm2Escape::Tab.set_color(*@colors.fetch(:spec_fail))
16
+ end
17
+
18
+ def apply_pass_color
19
+ Iterm2Escape::Tab.set_color(*@colors.fetch(:suite_pass))
20
+ end
21
+
22
+ def tab_title=(title)
23
+ Iterm2Escape::Tab.title = title
24
+ end
25
+
26
+ def window_title=(title)
27
+ Iterm2Escape::Tab.window_title = title
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,35 @@
1
+ require 'iterm2_tab_formatter/base'
2
+ require 'time'
3
+
4
+ class Iterm2TabFormatter
5
+ module TextFormatter
6
+ class << self
7
+ def window_title(example_count, failure_count, pending_count)
8
+ window_title = "#{example_count} example"
9
+ window_title << 's' unless example_count == 1
10
+
11
+ window_title << ", #{failure_count} failure" if failure_count > 0
12
+ window_title << 's' if failure_count > 1
13
+
14
+ window_title << ", #{pending_count} pending" if pending_count > 0
15
+
16
+ window_title
17
+ end
18
+
19
+ def finished_at(time)
20
+ time.iso8601
21
+ end
22
+
23
+ def duration(seconds)
24
+ text_minutes = (seconds / 60).to_i
25
+ text_seconds = (seconds % 60)
26
+
27
+ text = ''
28
+ text << "#{text_minutes}m" if text_minutes > 0
29
+ text << ("%.1fs" % text_seconds)
30
+
31
+ text
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,9 @@
1
+ begin
2
+ require 'iterm2_tab_formatter/base'
3
+ rescue LoadError
4
+ warn "Couldn't load base class for Iterm2TabFormatter. This might be okay if reading from the gemspec before running bundle install."
5
+ end
6
+
7
+ class Iterm2TabFormatter
8
+ VERSION = "0.7.0"
9
+ end
@@ -0,0 +1,17 @@
1
+ require 'rspec'
2
+ require 'iterm2_tab_formatter/auto'
3
+
4
+ RSpec.configure do |c|
5
+ c.add_formatter('documentation')
6
+ end
7
+
8
+ describe 'A slow test suite' do
9
+ it 'starts off gray' do
10
+ sleep 1
11
+ end
12
+
13
+ it 'turns green if ENV["PASS"] is set' do
14
+ sleep 1
15
+ expect(ENV['PASS'].to_s).not_to eq('')
16
+ end
17
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+ require 'iterm2_tab_formatter/controller'
3
+
4
+ describe Iterm2TabFormatter::Controller do
5
+ describe 'colors' do
6
+ let(:colors) do
7
+ {
8
+ suite_start: [128, 128, 128],
9
+ spec_fail: [255, 0, 0],
10
+ suite_pass: [0, 0, 255]
11
+ }
12
+ end
13
+
14
+ let(:controller) { described_class.new(colors) }
15
+
16
+ it 'sets the tab color to suite_start when starting suite' do
17
+ Iterm2Escape::Tab.should_receive(:set_color).with(128, 128, 128)
18
+ controller.apply_start_color
19
+ end
20
+
21
+ it 'sets the tab color to spec_fail on fail' do
22
+ Iterm2Escape::Tab.should_receive(:set_color).with(255, 0, 0)
23
+ controller.apply_fail_color
24
+ end
25
+
26
+ it 'sets the tab color to suite_pass when suite passed' do
27
+ Iterm2Escape::Tab.should_receive(:set_color).with(0, 0, 255)
28
+ controller.apply_pass_color
29
+ end
30
+ end
31
+ describe 'titles' do
32
+ let(:controller) { described_class.new({}) }
33
+
34
+ it 'sets the tab title' do
35
+ Iterm2Escape::Tab.should_receive('title=').with('foo bar')
36
+ controller.tab_title = 'foo bar'
37
+ end
38
+
39
+ it 'sets the window title' do
40
+ Iterm2Escape::Tab.should_receive('window_title=').with('foo bar')
41
+ controller.window_title = 'foo bar'
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+ require 'iterm2_tab_formatter'
3
+
4
+ describe Iterm2TabFormatter do
5
+ let(:formatter) { described_class.new(nil).tap { |f| f.stub(:controller).and_return(controller) } }
6
+ let(:controller) { double }
7
+
8
+ it 'makes a controller when initialized' do
9
+ expect(described_class.new(nil).controller).to be_an(Iterm2TabFormatter::Controller)
10
+ end
11
+
12
+ it 'uses the start color when starting suite' do
13
+ controller.should_receive(:apply_start_color).with(no_args)
14
+
15
+ formatter.start(100)
16
+ end
17
+
18
+ it 'uses the fail color when a spec fails' do
19
+ controller.should_receive(:apply_fail_color).with(no_args)
20
+
21
+ formatter.example_failed(double)
22
+ end
23
+
24
+ describe 'at the end of the suite' do
25
+ before do
26
+ controller.stub(:apply_pass_color)
27
+ controller.stub(:tab_title=)
28
+ controller.stub(:window_title=)
29
+ end
30
+
31
+ describe 'color' do
32
+ it 'uses the pass color when the suite passes' do
33
+ controller.should_receive(:apply_pass_color).with(no_args)
34
+
35
+ formatter.dump_summary(1, 10, 0, 0)
36
+ end
37
+
38
+ it 'does not use the pass color when there are failures in the suite' do
39
+ controller.should_not_receive(:apply_pass_color)
40
+
41
+ formatter.dump_summary(1, 10, 1, 0)
42
+ end
43
+
44
+ it 'does not use the pass color if there were no examples' do
45
+ controller.should_not_receive(:apply_pass_color)
46
+
47
+ formatter.dump_summary(1, 0, 0, 0)
48
+ end
49
+ end
50
+
51
+ describe 'text' do
52
+ it 'sets the tab title to a summary of the specs' do
53
+ controller.should_receive(:tab_title=).with('87.5% passed')
54
+
55
+ formatter.dump_summary(1, 8, 1, 2)
56
+ end
57
+
58
+ it 'sets the window title through TextFormatter' do
59
+ Time.should_receive(:now).and_return('time_now')
60
+ Iterm2TabFormatter::TextFormatter.should_receive(:duration).with(5).and_return('the_duration')
61
+ Iterm2TabFormatter::TextFormatter.should_receive(:window_title).with(8, 1, 2).and_return('window_title')
62
+ Iterm2TabFormatter::TextFormatter.should_receive(:finished_at).with('time_now').and_return('finish_time')
63
+ controller.should_receive(:window_title=).with('window_title - the_duration - Finished at finish_time')
64
+
65
+ formatter.dump_summary(5, 8, 1, 2)
66
+ end
67
+ end
68
+ end
69
+
70
+ it 'sets the window title to the description of a spec' do
71
+ example = double("example", description: 'an example description')
72
+
73
+ controller.should_receive(:window_title=).with('an example description')
74
+ controller.should_receive(:tab_title=).with('0/100')
75
+
76
+ formatter.stub(example_count: 100)
77
+ formatter.example_started(example)
78
+ end
79
+ end
@@ -0,0 +1,7 @@
1
+ require 'rspec'
2
+
3
+ RSpec.configure do |config|
4
+ config.expect_with :rspec do |c|
5
+ c.syntax = :expect
6
+ end
7
+ end
@@ -0,0 +1,37 @@
1
+ require 'iterm2_tab_formatter/text_formatter'
2
+
3
+ describe Iterm2TabFormatter::TextFormatter do
4
+ describe '.window_title' do
5
+ ({
6
+ '1 example' => [1, 0, 0],
7
+ '3 examples' => [3, 0, 0],
8
+ '3 examples, 2 failures' => [3, 2, 0],
9
+ '8 examples, 1 failure, 2 pending' => [8, 1, 2],
10
+ '8 examples, 2 failures, 1 pending' => [8, 2, 1],
11
+ '8 examples, 1 pending' => [8, 0, 1],
12
+ '8 examples, 2 pending' => [8, 0, 2],
13
+ }).each do |expected_message, counts|
14
+ example_count, failure_count, pending_count = counts
15
+
16
+ it "is correct for #{example_count}/#{failure_count}/#{pending_count}" do
17
+ expect(described_class.window_title(example_count, failure_count, pending_count)).to eq(expected_message)
18
+ end
19
+ end
20
+ end
21
+
22
+ describe '.finished_at' do
23
+ it 'formats as ISO-8601 datetime' do
24
+ date = DateTime.new(2013, 3, 17, 19, 25, 0, '-7')
25
+ expect(described_class.finished_at(date)).to eq('2013-03-17T19:25:00-07:00')
26
+ end
27
+ end
28
+
29
+ describe '.duration' do
30
+ it 'correctly prints the time under a minute' do
31
+ expect(described_class.duration(1.1)).to eq('1.1s')
32
+ end
33
+ it 'correctly prints time over a minute' do
34
+ expect(described_class.duration(65)).to eq('1m5.0s')
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+ require 'iterm2_tab_formatter'
3
+
4
+ describe Iterm2TabFormatter do
5
+ it "has a version" do
6
+ expect(Iterm2TabFormatter::VERSION).not_to be_nil
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: iterm2_tab_formatter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.7.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Mark Rushakoff
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: iterm2_escape
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '2.13'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '2.13'
46
+ description: An RSpec2 formatter that uses your iTerm2 tabs' color and titles to inform
47
+ you of your spec status.
48
+ email:
49
+ - mark.rushakoff@gmail.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - .travis.yml
56
+ - Gemfile
57
+ - LICENSE.txt
58
+ - README.md
59
+ - Rakefile
60
+ - iterm2_tab_formatter.gemspec
61
+ - lib/iterm2_tab_formatter.rb
62
+ - lib/iterm2_tab_formatter/auto.rb
63
+ - lib/iterm2_tab_formatter/base.rb
64
+ - lib/iterm2_tab_formatter/controller.rb
65
+ - lib/iterm2_tab_formatter/text_formatter.rb
66
+ - lib/iterm2_tab_formatter/version.rb
67
+ - sandbox/slow_spec.rb
68
+ - spec/controller_spec.rb
69
+ - spec/iterm2_tab_formatter_spec.rb
70
+ - spec/spec_helper.rb
71
+ - spec/text_formatter_spec.rb
72
+ - spec/version_spec.rb
73
+ homepage: https://github.com/mark-rushakoff/iterm2_tab_formatter
74
+ licenses: []
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ segments:
86
+ - 0
87
+ hash: -928581428121591177
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ segments:
95
+ - 0
96
+ hash: -928581428121591177
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 1.8.25
100
+ signing_key:
101
+ specification_version: 3
102
+ summary: ! 'iTerm2 Tab Formatter communicates your RSpec status through your iTerm2
103
+ tabs. By default, here''s what it does: * Tab chrome color: * Gray while spec is
104
+ running/pending * Red once a spec has failed * Green if all the specs pass * Tab
105
+ title: * Index of current spec and total number of specs * Window title: * Full
106
+ spec name for the current spec'
107
+ test_files:
108
+ - spec/controller_spec.rb
109
+ - spec/iterm2_tab_formatter_spec.rb
110
+ - spec/spec_helper.rb
111
+ - spec/text_formatter_spec.rb
112
+ - spec/version_spec.rb