minitest-bender 0.0.1

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: 0267a0cc8091fd2a0c8e5fb7e893d49d3865777f
4
+ data.tar.gz: 0ce2a2de7f417fda024941b26b3adc8b9c1d4dd0
5
+ SHA512:
6
+ metadata.gz: 92096d7372eec15ab075316462ea76dde735c9afaebecf64471e360a94f7b1f7801e141b34b141d8045dbca6573cf260f91351d575eb6cd901c613bee427b865
7
+ data.tar.gz: 4965b2b40228dc5ce37451b7987ba182b7aa28d55d635a46e1df481d40907422e629be39b3344fd2ee7b53234f0535fbece42494c93fc9850b7147071bb89c41
data/.gitignore ADDED
@@ -0,0 +1,50 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ Gemfile.lock
46
+ .ruby-version
47
+ .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
data/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ # Minitest Bender Changelog
2
+
3
+ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning][Semver].
4
+
5
+ ## [Unreleased]
6
+
7
+ * Your contribution here!
8
+
9
+ ## 0.0.1 (2017-06-20)
10
+
11
+ * Initial release
12
+
13
+ [Semver]: http://semver.org
14
+ [Unreleased]: https://github.com/eugeniobruno/minitest-bender/compare/v0.0.1...HEAD
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at eugeniobruno@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in openhouse.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Eugenio Bruno
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # Minitest Bender
2
+
3
+ My own Minitest reporter, without blackjack but with a hook.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'minitest-bender'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install minitest-bender
20
+
21
+ ## Usage
22
+
23
+ Require this plugin just after Minitest:
24
+
25
+ ```ruby
26
+ require 'minitest/autorun'
27
+ require 'minitest/bender'
28
+ ```
29
+
30
+ That's it! The next time you run your tests, a new report format will be used instead of the default one.
31
+
32
+ ## Features
33
+
34
+ Based on [minitest-colorin](https://github.com/gabynaiman/minitest-colorin/), the minitest-bender reporter gives you colored output including:
35
+
36
+ * Status, running time, name and message for each test/expectation, grouped by class/context
37
+ * Details of skips, failures and errors in three different sections, with diffs, backtraces and commands to rerun each single test
38
+ * Details of the top 3 slowest tests, if they may be relevant
39
+ * The same basic statistics of the default reporter
40
+
41
+
42
+ ## Development
43
+
44
+ After checking out the repo, run `bin/setup` to install dependencies. You can run `bin/console` for an interactive prompt that will allow you to experiment.
45
+
46
+ To install this gem onto your local machine, run `bundle exec rake install`.
47
+
48
+ ## Contributing
49
+
50
+ Bug reports and pull requests are welcome on GitHub at https://github.com/eugeniobruno/minitest-bender. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
51
+
52
+
53
+ ## License
54
+
55
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
56
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'minitest-bender'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require 'pry'
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
@@ -0,0 +1,159 @@
1
+ require 'minitest'
2
+ require 'colorin'
3
+ require 'minitest_bender'
4
+
5
+ module Minitest
6
+ class Bender < AbstractReporter
7
+ attr_reader :io, :options, :previous_context, :results, :started_at
8
+
9
+ def initialize(io, options = {})
10
+ @io = io
11
+ @options = options
12
+ @previous_context = nil
13
+ @results = []
14
+ @slowness_podium_is_relevant = false
15
+ end
16
+
17
+ def start
18
+ @started_at = Time.now
19
+ io.puts
20
+ io.puts Colorin.white("Minitest started at #{started_at}")
21
+ io.puts Colorin.white("Options: #{options_args}")
22
+ io.puts
23
+ end
24
+
25
+ def record(minitest_result)
26
+ result = MinitestBender.result_factory.create(minitest_result)
27
+ results << result
28
+
29
+ current_context = result.context
30
+
31
+ if current_context != previous_context
32
+ io.puts
33
+ io.puts(result.header)
34
+ @previous_context = current_context
35
+ end
36
+
37
+ @slowness_podium_is_relevant = true if result.time > 0.01
38
+
39
+ io.puts result.line_to_report
40
+ end
41
+
42
+ def passed?
43
+ passed_count + skipped_count == test_count
44
+ end
45
+
46
+ def report
47
+ io.puts
48
+ print_divider(:white)
49
+
50
+ print_details
51
+
52
+ if @slowness_podium_is_relevant && passed?
53
+ print_slowness_podium
54
+ io.puts
55
+ end
56
+
57
+ print_statistics
58
+ io.puts
59
+
60
+ print_suite_status
61
+ end
62
+
63
+ private
64
+
65
+ def options_args
66
+ options.fetch(:args, '(none)')
67
+ end
68
+
69
+ def passed_without_skips?
70
+ passed_count == test_count
71
+ end
72
+
73
+ def run_all_tests?
74
+ !options_args.include?('--name')
75
+ end
76
+
77
+ def test_count
78
+ results.size
79
+ end
80
+
81
+ def passed_count
82
+ @passed_count ||= results.count(&:passed?)
83
+ end
84
+
85
+ def skipped_count
86
+ @skipped_count ||= results.count(&:skipped?)
87
+ end
88
+
89
+ def assertion_count
90
+ @assertion_count ||= results.reduce(0) { |acum, result| acum + result.assertions }
91
+ end
92
+
93
+ def print_divider(color)
94
+ io.puts(Colorin.public_send(color, ' _______________________').bold)
95
+ io.puts
96
+ end
97
+
98
+ def print_details
99
+ states = MinitestBender.states.values
100
+ symbols = states.map { |state| state.print_details(io, results) }
101
+ io.puts unless symbols.all? { |symbol| symbol == :no_details }
102
+ end
103
+
104
+ def print_statistics
105
+ total_tests = "#{test_count} tests"
106
+ total_tests = total_tests.chop if test_count == 1
107
+ formatted_total_tests = Colorin.blue_a700(total_tests)
108
+
109
+ total_assertions = "#{assertion_count} assertions"
110
+ total_assertions = total_assertions.chop if assertion_count == 1
111
+ formatted_total_assertions = Colorin.purple_400(total_assertions)
112
+
113
+ auxiliary_verb = test_count == 1 ? 'was' : 'were'
114
+
115
+ total_time = (Time.now - started_at).round(3)
116
+ formatted_total_time = Colorin.grey_700("#{total_time} seconds")
117
+
118
+ tests_rate = Colorin.grey_700("#{(test_count / total_time).round(4)} tests/s")
119
+ assertions_rate = Colorin.grey_700("#{(assertion_count / total_time).round(4)} assertions/s")
120
+
121
+ io.puts " #{formatted_total_tests} with #{formatted_total_assertions} #{auxiliary_verb} run in #{formatted_total_time} (#{tests_rate}, #{assertions_rate})"
122
+ end
123
+
124
+ def print_suite_status
125
+ all_passed_color = MinitestBender.passing_color
126
+ final_divider_color = all_passed_color
127
+
128
+ if passed_without_skips? && run_all_tests?
129
+ message = Colorin.public_send(all_passed_color, ' ALL TESTS PASS! (^_^)/')
130
+ else
131
+ messages = MinitestBender.states.values.map do |state|
132
+ summary_message = state.summary_message(results)
133
+ final_divider_color = state.color unless summary_message.empty?
134
+ summary_message
135
+ end
136
+
137
+ message = " #{messages.reject(&:empty?).join(', ').gsub(/(.*), /, '\1 and ')}"
138
+ end
139
+ io.puts(message)
140
+
141
+ print_divider(final_divider_color)
142
+ end
143
+
144
+ def print_slowness_podium
145
+ results.sort_by! { |r| -r.time }
146
+
147
+ io.puts(formatted_slowness_podium_label)
148
+ io.puts
149
+ results.take(3).each_with_index do |result, i|
150
+ number = "#{i + 1})".ljust(4)
151
+ io.puts " #{number}#{result.line_for_slowness_podium}"
152
+ end
153
+ end
154
+
155
+ def formatted_slowness_podium_label
156
+ " #{Colorin.grey_700('SLOWNESS PODIUM').bold.underline}"
157
+ end
158
+ end
159
+ end
@@ -0,0 +1,8 @@
1
+ module Minitest
2
+ def self.plugin_bender_init(options)
3
+ Minitest.reporter.reporters.clear
4
+ Minitest.reporter << Bender.new(options.fetch(:io, $stdout), options)
5
+ end
6
+
7
+ def self.plugin_bender_options(_opts, _options); end
8
+ end
@@ -0,0 +1,32 @@
1
+ module MinitestBender
2
+ class ResultFactory
3
+ RESULT_NAME_REGEXP = /test_(?<number>\d*)_?(?<name>.+)?/
4
+ ANONYMOUS = 'anonymous'.freeze
5
+
6
+ def create(minitest_result)
7
+ result_number = number(minitest_result)
8
+ result_name = name(minitest_result)
9
+ if result_number.empty?
10
+ Results::Test.new(minitest_result, result_name)
11
+ else
12
+ Results::Expectation.new(minitest_result, result_number, result_name)
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ attr_reader :minitest_result
19
+
20
+ def number(minitest_result)
21
+ parsed_name(minitest_result)[:number]
22
+ end
23
+
24
+ def name(minitest_result)
25
+ (parsed_name(minitest_result)[:name] || ANONYMOUS).strip
26
+ end
27
+
28
+ def parsed_name(minitest_result)
29
+ minitest_result.name.match(RESULT_NAME_REGEXP)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,59 @@
1
+ module MinitestBender
2
+ module Results
3
+ class Base
4
+ extend Forwardable
5
+ def_delegators :@minitest_result, :passed?, :skipped?, :assertions, :failures, :time
6
+
7
+ def initialize(minitest_result)
8
+ @minitest_result = minitest_result
9
+ @state = MinitestBender.states.fetch(minitest_result.result_code)
10
+ end
11
+
12
+ def context
13
+ @context ||= minitest_result.class.name.gsub('::', ' > ')
14
+ end
15
+
16
+ def header
17
+ Colorin.white("• #{context}").bold
18
+ end
19
+
20
+ def details_header(number)
21
+ " #{number}#{Colorin.white(context)} > #{name}"
22
+ end
23
+
24
+ def rerun_line(padding)
25
+ unformatted = "Rerun: #{rerun_command}"
26
+ "#{padding}#{Colorin.blue_a700(unformatted)}"
27
+ end
28
+
29
+ def state?(some_state)
30
+ state.class == some_state.class
31
+ end
32
+
33
+ def line_for_slowness_podium
34
+ "#{formatted_time} #{Colorin.white(context)} > #{name}"
35
+ end
36
+
37
+ private
38
+
39
+ attr_reader :minitest_result, :state
40
+
41
+ def formatted_label
42
+ " #{state.formatted_label}"
43
+ end
44
+
45
+ def formatted_message
46
+ " #{state.formatted_message(self)}"
47
+ end
48
+
49
+ def formatted_time
50
+ Colorin.grey_700("#{(time * 1000).round}ms ".rjust(6))
51
+ end
52
+
53
+ def rerun_command
54
+ relative_location = state.test_location(self).split(':').first
55
+ "rake TEST=#{relative_location} TESTOPTS=\"--name=#{name_for_rerun_command}\""
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,27 @@
1
+ module MinitestBender
2
+ module Results
3
+ class Expectation < Base
4
+ def initialize(minitest_result, number, name)
5
+ super(minitest_result)
6
+ @number = number
7
+ @name = name
8
+ end
9
+
10
+ def line_to_report
11
+ "#{formatted_label}#{formatted_time} #{formatted_number} #{name} #{formatted_message}"
12
+ end
13
+
14
+ private
15
+
16
+ attr_reader :number, :name
17
+
18
+ def formatted_number
19
+ "#{Colorin.brown_400(number)} "
20
+ end
21
+
22
+ def name_for_rerun_command
23
+ "/#{name.gsub(' ', '\\ ')}/"
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,36 @@
1
+ module MinitestBender
2
+ module Results
3
+ class Test < Base
4
+ def initialize(minitest_result, raw_name)
5
+ super(minitest_result)
6
+ @raw_name = raw_name
7
+ end
8
+
9
+ def context
10
+ super.gsub(/^Test|Test$/, '')
11
+ end
12
+
13
+ def line_to_report
14
+ "#{formatted_label}#{formatted_time} #{name} #{formatted_message}"
15
+ end
16
+
17
+ private
18
+
19
+ attr_reader :raw_name
20
+
21
+ def name
22
+ @name ||= begin
23
+ words = raw_name.split('_')
24
+ words = words.drop(1) if words.first == 'that'
25
+ words.first.capitalize!
26
+ words.last.gsub!(/([a-zA-Z])(\d+)$/, '\1 \2')
27
+ words.join(' ')
28
+ end
29
+ end
30
+
31
+ def name_for_rerun_command
32
+ minitest_result.name
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,69 @@
1
+ module MinitestBender
2
+ module States
3
+ class Base
4
+ def formatted_label
5
+ @formatted_label ||= colored(label.ljust(7))
6
+ end
7
+
8
+ def formatted_group_label
9
+ @formatted_group_label ||= " #{colored(group_label).bold.underline}"
10
+ end
11
+
12
+ def print_details(io, results)
13
+ filtered_results = only_with_this_state(results)
14
+ return :no_details if filtered_results.empty?
15
+
16
+ io.puts formatted_group_label
17
+ io.puts
18
+ filtered_results.each_with_index do |result, i|
19
+ number = "#{i + 1})".ljust(4)
20
+ padding = ' ' * (number.size + 4)
21
+ io.puts(result.details_header(number))
22
+ do_print_details(io, result, padding)
23
+ io.puts
24
+ io.puts(result.rerun_line(padding))
25
+ io.puts if i < filtered_results.size - 1
26
+ end
27
+ io.puts
28
+ :printed_details
29
+ end
30
+
31
+ def color
32
+ self.class::COLOR
33
+ end
34
+
35
+ def test_location(result)
36
+ location(result)
37
+ end
38
+
39
+ private
40
+
41
+ def label
42
+ self.class::LABEL
43
+ end
44
+
45
+ def group_label
46
+ self.class::GROUP_LABEL
47
+ end
48
+
49
+ def colored(string)
50
+ Colorin.public_send(color, string)
51
+ end
52
+
53
+ def only_with_this_state(results)
54
+ results.select { |result| result.state?(self) }
55
+ end
56
+
57
+ def do_print_details(io, result, padding)
58
+ result.failures[0].message.split("\n").each do |line|
59
+ io.puts "#{padding}#{colored(line)}"
60
+ end
61
+ io.puts "#{padding}#{Colorin.brown_400(location(result))}"
62
+ end
63
+
64
+ def location(result)
65
+ Utils.relative_path(result.failures[0].location)
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,19 @@
1
+ module MinitestBender
2
+ module States
3
+ class Failing < Base
4
+ COLOR = :red_500
5
+ LABEL = 'FAILED'.freeze
6
+ GROUP_LABEL = 'FAILURES'.freeze
7
+
8
+ def formatted_message(result)
9
+ @formatted_message ||= colored(location(result))
10
+ end
11
+
12
+ def summary_message(results)
13
+ filtered_results = only_with_this_state(results)
14
+ return '' if filtered_results.empty?
15
+ colored("#{filtered_results.size} failed")
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,23 @@
1
+ module MinitestBender
2
+ module States
3
+ class Passing < Base
4
+ COLOR = :green_500
5
+ LABEL = 'PASSED'.freeze
6
+ GROUP_LABEL = 'PASSING'.freeze
7
+
8
+ def formatted_message(_result)
9
+ ''
10
+ end
11
+
12
+ def print_details(_io, _results)
13
+ :no_details
14
+ end
15
+
16
+ def summary_message(results)
17
+ filtered_results = only_with_this_state(results)
18
+ return '' if filtered_results.empty?
19
+ colored("#{filtered_results.size} passed")
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,47 @@
1
+ module MinitestBender
2
+ module States
3
+ class Raising < Base
4
+ COLOR = :amber_300
5
+ LABEL = 'RAISED'.freeze
6
+ GROUP_LABEL = 'ERRORS'.freeze
7
+
8
+ def formatted_message(result)
9
+ @formatted_message ||= colored(detailed_error_message(result))
10
+ end
11
+
12
+ def summary_message(results)
13
+ filtered_results = only_with_this_state(results)
14
+ return '' if filtered_results.empty?
15
+ colored("#{filtered_results.size} raised errors")
16
+ end
17
+
18
+ def test_location(result)
19
+ backtrace_line = backtrace(result).select { |line| line =~ /\/test\/|\/spec\// }.last
20
+ Utils.relative_path(backtrace_line).split(':').first
21
+ end
22
+
23
+ private
24
+
25
+ def do_print_details(io, result, padding)
26
+ io.puts "#{padding}#{colored(error_message(result))}"
27
+ backtrace(result).each do |line|
28
+ io.puts "#{padding}#{Colorin.brown_400(line)}"
29
+ end
30
+ end
31
+
32
+ def error_message(result)
33
+ exception = result.failures[0].exception
34
+ "#{exception.class}: #{exception.message}"
35
+ end
36
+
37
+ def detailed_error_message(result)
38
+ details = Utils.relative_path(backtrace(result)[0])
39
+ "#{error_message(result)}\n (#{details})"
40
+ end
41
+
42
+ def backtrace(result)
43
+ result.failures[0].backtrace
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,21 @@
1
+ module MinitestBender
2
+ module States
3
+ class Skipped < Base
4
+ COLOR = :cyan_300
5
+ LABEL = 'SKIPPED'.freeze
6
+ GROUP_LABEL = 'SKIPS'.freeze
7
+
8
+ def formatted_message(result)
9
+ @formatted_message ||= colored(result.failures[0].message)
10
+ end
11
+
12
+ def summary_message(results)
13
+ filtered_results = only_with_this_state(results)
14
+ return '' if filtered_results.empty?
15
+ skipped_count = filtered_results.size
16
+ auxiliary_verb = skipped_count == 1 ? 'was' : 'were'
17
+ colored("#{filtered_results.size} #{auxiliary_verb} skipped")
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,7 @@
1
+ module MinitestBender
2
+ module Utils
3
+ def self.relative_path(full_path)
4
+ full_path.gsub("#{Dir.pwd}/", '')
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module MinitestBender
2
+ VERSION = '0.0.1'.freeze
3
+ end
@@ -0,0 +1,35 @@
1
+ require 'minitest-bender/version'
2
+
3
+ require 'minitest-bender/states/base'
4
+ require 'minitest-bender/states/passing'
5
+ require 'minitest-bender/states/skipped'
6
+ require 'minitest-bender/states/failing'
7
+ require 'minitest-bender/states/raising'
8
+
9
+ require 'minitest-bender/results/base'
10
+ require 'minitest-bender/results/test'
11
+ require 'minitest-bender/results/expectation'
12
+
13
+ require 'minitest-bender/result_factory'
14
+ require 'minitest-bender/utils'
15
+
16
+ module MinitestBender
17
+ STATES = {
18
+ '.' => States::Passing.new,
19
+ 'S' => States::Skipped.new,
20
+ 'F' => States::Failing.new,
21
+ 'E' => States::Raising.new
22
+ }.freeze
23
+
24
+ def self.states
25
+ STATES
26
+ end
27
+
28
+ def self.result_factory
29
+ @result_factory ||= ResultFactory.new
30
+ end
31
+
32
+ def self.passing_color
33
+ states.fetch('.').color
34
+ end
35
+ end
@@ -0,0 +1,41 @@
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'minitest-bender/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'minitest-bender'
9
+ spec.version = MinitestBender::VERSION
10
+ spec.date = '2017-06-20'
11
+ spec.authors = ['Eugenio Bruno']
12
+ spec.email = ['eugeniobruno@gmail.com']
13
+
14
+ spec.summary = 'My own Minitest reporter, without blackjack but with a hook.'
15
+ spec.homepage = 'https://github.com/eugeniobruno/minitest-bender'
16
+ spec.license = 'MIT'
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
19
+ f.match(%r{^(test|spec|features)/})
20
+ end
21
+ spec.bindir = 'bin'
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
24
+ spec.require_paths = ['lib']
25
+ spec.extra_rdoc_files = %w[LICENSE.txt README.md CODE_OF_CONDUCT.md CHANGELOG.md]
26
+
27
+ spec.required_ruby_version = '>= 1.9.3'
28
+
29
+ spec.add_runtime_dependency 'minitest', '~> 5.0'
30
+ spec.add_runtime_dependency 'colorin', '~> 2.0'
31
+
32
+ spec.add_development_dependency 'bundler', '~> 1.15'
33
+ spec.add_development_dependency 'rake', '~> 10.0'
34
+ spec.add_development_dependency 'pry-byebug', '~> 3.4'
35
+
36
+ if RUBY_VERSION < '2'
37
+ spec.add_development_dependency 'term-ansicolor', '~> 1.3.0'
38
+ spec.add_development_dependency 'tins', '~> 1.6.0'
39
+ spec.add_development_dependency 'json', '~> 1.8'
40
+ end
41
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: minitest-bender
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Eugenio Bruno
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-06-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: minitest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: colorin
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.15'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.15'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.4'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.4'
83
+ description:
84
+ email:
85
+ - eugeniobruno@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files:
89
+ - LICENSE.txt
90
+ - README.md
91
+ - CODE_OF_CONDUCT.md
92
+ - CHANGELOG.md
93
+ files:
94
+ - ".gitignore"
95
+ - CHANGELOG.md
96
+ - CODE_OF_CONDUCT.md
97
+ - Gemfile
98
+ - LICENSE.txt
99
+ - README.md
100
+ - Rakefile
101
+ - bin/console
102
+ - bin/setup
103
+ - lib/minitest-bender/result_factory.rb
104
+ - lib/minitest-bender/results/base.rb
105
+ - lib/minitest-bender/results/expectation.rb
106
+ - lib/minitest-bender/results/test.rb
107
+ - lib/minitest-bender/states/base.rb
108
+ - lib/minitest-bender/states/failing.rb
109
+ - lib/minitest-bender/states/passing.rb
110
+ - lib/minitest-bender/states/raising.rb
111
+ - lib/minitest-bender/states/skipped.rb
112
+ - lib/minitest-bender/utils.rb
113
+ - lib/minitest-bender/version.rb
114
+ - lib/minitest/bender.rb
115
+ - lib/minitest/bender_plugin.rb
116
+ - lib/minitest_bender.rb
117
+ - minitest-bender.gemspec
118
+ homepage: https://github.com/eugeniobruno/minitest-bender
119
+ licenses:
120
+ - MIT
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: 1.9.3
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.5.1
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: My own Minitest reporter, without blackjack but with a hook.
142
+ test_files: []