unassuming 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c8247b16bd3585f5a88d33ffda6cd772a85f910a
4
+ data.tar.gz: 169e70ba8650e169ec635bcd9c11ad533df7333e
5
+ SHA512:
6
+ metadata.gz: 19187a4c3cb8e1f808e0b3b81fc78398ea975d166f3afaf7216e3ad12fb68ee901c887f7c4472ddaff4ee3893088395e1621319f4caeb6b6594eb7b511f226a2
7
+ data.tar.gz: a13779ddcfd9db5c932b954db850ad2dc58f139fb5940d4d7d70c6967e28e3b1cb69123bfa5b375f558ac8b3a27c71f3be3a8358d87b8ce1fe089b29edd18ea0
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --require spec_helper
3
+ --format RSpec::Core::Formatters::Unassuming
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in unassuming.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Martin Feckie
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.
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # Unassuming
2
+
3
+ An RSpec formatter to take up minimal space
4
+
5
+ ## Why?
6
+ I find an RSpec + Guard workflow very useful when I'm developing, but find most of the default formatter too 'noisy' when I'm working in a single file.
7
+ This formatter helps by reducing the amount of information presented when encountering failures, while presenting enough information to see where the issue is.
8
+
9
+ ###Passing Spec
10
+ ![Passing Spec](img/passing.png)
11
+ ###Failing Spec
12
+ ![Passing Spec](img/failing.png)
13
+
14
+ ## Installation
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ ```ruby
19
+ gem 'unassuming'
20
+ ```
21
+
22
+ And then execute:
23
+
24
+ $ bundle
25
+
26
+ ## Usage
27
+
28
+ add to `.rspec`
29
+
30
+ ```ruby
31
+ --format Unassuming
32
+ ```
33
+
34
+ ## Contributing
35
+
36
+ 1. Fork it ( https://github.com/mfeckie/unassuming/fork )
37
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
38
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
39
+ 4. Push to the branch (`git push origin my-new-feature`)
40
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/img/failing.png ADDED
Binary file
data/img/passing.png ADDED
Binary file
data/lib/unassuming.rb ADDED
@@ -0,0 +1,3 @@
1
+ require "unassuming/formatter"
2
+
3
+ Unassuming = RSpec::Core::Formatters::Unassuming
@@ -0,0 +1,120 @@
1
+ require 'rspec/core/formatters/base_text_formatter'
2
+ require 'pry'
3
+
4
+ module RSpec
5
+ module Core
6
+ module Formatters
7
+ class Unassuming < RSpec::Core::Formatters::BaseTextFormatter
8
+ include RSpec::Core::Formatters::ConsoleCodes
9
+
10
+ Formatters.register self, :start, :example_passed, :example_failed, :example_pending
11
+
12
+ attr_reader :output, :failed_examples
13
+
14
+ def initialize(output)
15
+ @output = output
16
+ super(output)
17
+ end
18
+
19
+ def start(example_count)
20
+ super(example_count)
21
+ cyan_line
22
+ output.print(bold('Starting Spec Run @ '), green(now), ' -> ')
23
+ @example_results = []
24
+ @failed_examples = []
25
+ @pending_examples = []
26
+ end
27
+
28
+ def example_passed(example)
29
+ output.print green('好 ')
30
+ end
31
+
32
+ def example_failed(example)
33
+ failed_examples << example
34
+ output.print red('☢')
35
+ end
36
+
37
+ def example_pending(example)
38
+ output.print yellow(example)
39
+ end
40
+
41
+ def dump_failures(notification)
42
+ return if failed_examples.empty?
43
+ failed_examples.each_with_index do |example, index|
44
+ dump_failure(example, index)
45
+ end
46
+ end
47
+
48
+ def dump_failure(example, index)
49
+ output.puts
50
+ dump_failure_info(example, index)
51
+ end
52
+
53
+ def dump_failure_info(example, index)
54
+ exception = example.exception
55
+ message = strip_whitespace(exception.message)
56
+ failed_line = strip_whitespace(read_failed_line(example))
57
+ output.print "#{index+1}) #{cyan failed_line}\t #{red message }"
58
+ end
59
+
60
+ def dump_summary(run)
61
+ output.puts "\n"
62
+ output.puts "Finished in #{run.duration}\n"
63
+ output.puts "#{run.example_count} examples, #{run.failure_count} failures"
64
+ if run.failure_count > 0
65
+ output.puts bold(red "(╯°□°)╯︵ ┻━┻")
66
+ else
67
+ output.puts bold(magenta "(ノ◕ヮ◕)ノ*:・゚✧")
68
+ end
69
+ cyan_line
70
+ end
71
+
72
+ def now
73
+ Time.now.strftime('%H:%M:%S')
74
+ end
75
+
76
+ def strip_whitespace(string)
77
+ string.to_s.gsub("\n", ' ').gsub(/\s{2,}/, ' ')
78
+ end
79
+
80
+ def cyan_line
81
+ output.puts cyan('--------------------------------------')
82
+ end
83
+
84
+ def blue(input)
85
+ wrap(input, :blue)
86
+ end
87
+
88
+ def bold(input)
89
+ wrap(input, :bold)
90
+ end
91
+
92
+ def cyan(input)
93
+ wrap(input, :cyan)
94
+ end
95
+
96
+ def green(input)
97
+ wrap(input, :green)
98
+ end
99
+
100
+ def red(input)
101
+ wrap(input, :red)
102
+ end
103
+
104
+ def yellow(input)
105
+ wrap(input, :yellow)
106
+ end
107
+
108
+ def magenta(input)
109
+ wrap(input, :magenta)
110
+ end
111
+
112
+ def read_failed_line(example)
113
+ example.example.location.split("/").last.to_s
114
+ end
115
+
116
+
117
+ end
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,33 @@
1
+ describe RSpec::Core::Formatters::Unassuming do
2
+ include FormatterSupport
3
+
4
+ before do
5
+ send_notification :start, start_notification(1)
6
+ allow(formatter).to receive(:color_enabled?).and_return(false)
7
+ end
8
+
9
+ let(:unassuming) { RSpec::Core::Formatters::Unassuming.new(StringIO.new)}
10
+
11
+ it 'prints 好 for passed examples' do
12
+ send_notification :example_passed, example_notification
13
+ expect(output.string).to end_with("好 \e[0m")
14
+ end
15
+
16
+ it 'throws glitter if specs pass' do
17
+ send_notification :example_failed, example_notification
18
+ send_notification :dump_summary, summary_notification(0.00001, examples(2), [], [2], 0)
19
+ expect(output.string).to include("(ノ◕ヮ◕)ノ*:・゚✧")
20
+ end
21
+
22
+ it 'prints ☢ for failed examples' do
23
+ send_notification :example_failed, example_notification
24
+ expect(output.string).to end_with("☢\e[0m")
25
+ end
26
+
27
+ it 'throws the table if specs fail' do
28
+ send_notification :example_failed, example_notification
29
+ send_notification :dump_summary, summary_notification(0.00001, examples(2), [1], [], 0)
30
+ expect(output.string).to include("(╯°□°)╯︵ ┻━┻")
31
+ end
32
+
33
+ end
@@ -0,0 +1,3 @@
1
+ require 'unassuming'
2
+
3
+ require 'support/formatter_support'
@@ -0,0 +1,144 @@
1
+ ## Based on https://github.com/rspec/rspec-core
2
+
3
+ module FormatterSupport
4
+ def run_example_specs_with_formatter(formatter_option)
5
+ options = RSpec::Core::ConfigurationOptions.new(%W[spec/rspec/core/resources/formatter_specs.rb --format #{formatter_option} --order defined])
6
+
7
+ err, out = StringIO.new, StringIO.new
8
+ err.set_encoding("utf-8") if err.respond_to?(:set_encoding)
9
+
10
+ runner = RSpec::Core::Runner.new(options)
11
+ configuration = runner.instance_variable_get("@configuration")
12
+ configuration.backtrace_formatter.exclusion_patterns << /rspec_with_simplecov/
13
+ configuration.backtrace_formatter.inclusion_patterns = []
14
+
15
+ runner.run(err, out)
16
+
17
+ output = out.string
18
+ output.gsub!(/\d+(?:\.\d+)?(s| seconds)/, "n.nnnn\\1")
19
+
20
+ caller_line = RSpec::Core::Metadata.relative_path(caller.first)
21
+ output.lines.reject do |line|
22
+ # remove the direct caller as that line is different for the summary output backtraces
23
+ line.include?(caller_line) ||
24
+
25
+ # ignore scirpt/rspec_with_simplecov because we don't usually have it locally but
26
+ # do have it on travis
27
+ line.include?("script/rspec_with_simplecov") ||
28
+
29
+ # this line varies a bit depending on how you run the specs (via `rake` vs `rspec`)
30
+ line.include?('/exe/rspec:')
31
+ end.join
32
+ end
33
+
34
+ def send_notification type, notification
35
+ reporter.notify type, notification
36
+ end
37
+
38
+ def reporter
39
+ @reporter ||= setup_reporter
40
+ end
41
+
42
+ def setup_reporter(*streams)
43
+ config.add_formatter described_class, *streams
44
+ @formatter = config.formatters.first
45
+ @reporter = config.reporter
46
+ end
47
+
48
+ def output
49
+ @output ||= StringIO.new
50
+ end
51
+
52
+ def config
53
+ @configuration ||=
54
+ begin
55
+ output.set_encoding "utf-8"
56
+ config = RSpec::Core::Configuration.new
57
+ config.output_stream = output
58
+ config
59
+ end
60
+ end
61
+
62
+ def configure
63
+ yield config
64
+ end
65
+
66
+ def formatter
67
+ @formatter ||=
68
+ begin
69
+ setup_reporter
70
+ @formatter
71
+ end
72
+ end
73
+
74
+ def example
75
+ @example ||=
76
+ begin
77
+ result = instance_double(RSpec::Core::Example::ExecutionResult,
78
+ :pending_fixed? => false,
79
+ :status => :passed
80
+ )
81
+ allow(result).to receive(:exception) { exception }
82
+ instance_double(RSpec::Core::Example,
83
+ :description => "Example",
84
+ :full_description => "Example",
85
+ :execution_result => result,
86
+ :location => "",
87
+ :metadata => {}
88
+ )
89
+ end
90
+ end
91
+
92
+ def exception
93
+ Exception.new
94
+ end
95
+
96
+ def examples(n)
97
+ (1..n).map { example }
98
+ end
99
+
100
+ def group
101
+ class_double "RSpec::Core::ExampleGroup", :description => "Group"
102
+ end
103
+
104
+ def start_notification(count)
105
+ ::RSpec::Core::Notifications::StartNotification.new count
106
+ end
107
+
108
+ def stop_notification
109
+ ::RSpec::Core::Notifications::ExamplesNotification.new reporter
110
+ end
111
+
112
+ def example_notification(specific_example = example)
113
+ ::RSpec::Core::Notifications::ExampleNotification.for specific_example
114
+ end
115
+
116
+ def group_notification
117
+ ::RSpec::Core::Notifications::GroupNotification.new group
118
+ end
119
+
120
+ def message_notification(message)
121
+ ::RSpec::Core::Notifications::MessageNotification.new message
122
+ end
123
+
124
+ def null_notification
125
+ ::RSpec::Core::Notifications::NullNotification
126
+ end
127
+
128
+ def seed_notification(seed, used = true)
129
+ ::RSpec::Core::Notifications::SeedNotification.new seed, used
130
+ end
131
+
132
+ def failed_examples_notification
133
+ ::RSpec::Core::Notifications::ExamplesNotification.new reporter
134
+ end
135
+
136
+ def summary_notification(duration, examples, failed, pending, time)
137
+ ::RSpec::Core::Notifications::SummaryNotification.new duration, examples, failed, pending, time
138
+ end
139
+
140
+ def profile_notification(duration, examples, number)
141
+ ::RSpec::Core::Notifications::ProfileNotification.new duration, examples, number
142
+ end
143
+
144
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "unassuming"
7
+ spec.version = "0.0.2"
8
+ spec.authors = ["Martin Feckie"]
9
+ spec.email = ["mfeckie@gmail.com"]
10
+ spec.summary = %q{Unassuming is an RSpec formatter that doesn't take much space!}
11
+ spec.description = %q{RSpec formatter designed to live in a small terminal of ~6 lines}
12
+ spec.homepage = ""
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.7"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "pry"
23
+
24
+ spec.add_dependency "rspec", ">= 3.0"
25
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: unassuming
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Martin Feckie
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: RSpec formatter designed to live in a small terminal of ~6 lines
70
+ email:
71
+ - mfeckie@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - img/failing.png
83
+ - img/passing.png
84
+ - lib/unassuming.rb
85
+ - lib/unassuming/formatter.rb
86
+ - spec/lib/unassuming/formatter_spec.rb
87
+ - spec/spec_helper.rb
88
+ - spec/support/formatter_support.rb
89
+ - unassuming.gemspec
90
+ homepage: ''
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.2.2
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: Unassuming is an RSpec formatter that doesn't take much space!
114
+ test_files:
115
+ - spec/lib/unassuming/formatter_spec.rb
116
+ - spec/spec_helper.rb
117
+ - spec/support/formatter_support.rb