minitest-utils 0.1.0

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: 2ad58bb62375ad893e3d7533596c906657793b20
4
+ data.tar.gz: 918f0682ade6441d27b2f4f6b3e30cd69d0cbcf4
5
+ SHA512:
6
+ metadata.gz: ad62a955a0ebdbc058edaaaec27011063344cc8b6da23bec279415f7163565fe3771cae04f4d8e808dd19a7d96fbeae66a4e4de99387d92484883cb8e3c52a76
7
+ data.tar.gz: 466bdb54ea009e5e77aefff8fb7aa70f29fd717d33992c2173280a06ee1afdfde3057d2710f281f1db34f8efbef06e2435e0c993a098828ee3f3bdf7e795416d
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in minitest-utils.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # Minitest::Utils
2
+
3
+ Some utilities for your Minitest day-to-day usage.
4
+
5
+ Includes:
6
+
7
+ - A better reporter (see screenshot below)
8
+ - A [TestNotifier](http://github.com/fnando/test_notifier) reporter
9
+ - Some Rails niceties (set up FactoryGirl, WebMock and Capybara)
10
+ - Add a `t` and `l` methods (i18n)
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem 'minitest-utils'
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ $ bundle
23
+
24
+ Or install it yourself as:
25
+
26
+ $ gem install minitest-utils
27
+
28
+ ## Screenshots
29
+
30
+ ![](https://raw.githubusercontent.com/fnando/minitest-utils/master/screenshots/light-failing.png)
31
+ ![](https://raw.githubusercontent.com/fnando/minitest-utils/master/screenshots/light-success.png)
32
+ ![](https://raw.githubusercontent.com/fnando/minitest-utils/master/screenshots/dark-failing.png)
33
+ ![](https://raw.githubusercontent.com/fnando/minitest-utils/master/screenshots/dark-success.png)
34
+
35
+
36
+ ## Development
37
+
38
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
39
+
40
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
41
+
42
+ ## Contributing
43
+
44
+ 1. Fork it ( https://github.com/[my-github-username]/minitest-utils/fork )
45
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
46
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
47
+ 4. Push to the branch (`git push origin my-new-feature`)
48
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:spec) do |t|
5
+ t.libs << 'spec'
6
+ t.test_files = FileList['spec/**/*_spec.rb']
7
+ t.verbose = true
8
+ end
9
+
10
+ task :default => :spec
@@ -0,0 +1,8 @@
1
+ module Minitest
2
+ module Utils
3
+ require 'minitest'
4
+ require 'minitest/utils/version'
5
+ require 'minitest/utils/reporter'
6
+ require 'minitest/utils/test_notifier_reporter'
7
+ end
8
+ end
@@ -0,0 +1,23 @@
1
+ class ActiveSupport::TestCase
2
+ extend Minitest::Spec::DSL if defined?(Minitest::Spec::DSL)
3
+
4
+ require 'minitest/utils/rails/webmock' if defined?(WebMock)
5
+ require 'minitest/utils/rails/capybara' if defined?(Capybara)
6
+ require 'minitest/utils/rails/factory_girl' if defined?(FactoryGirl)
7
+
8
+ def t(*args)
9
+ I18n.t(*args)
10
+ end
11
+
12
+ def l(*args)
13
+ I18n.l(*args)
14
+ end
15
+ end
16
+
17
+ class ActionMailer::TestCase
18
+ include Rails.application.routes.url_helpers
19
+
20
+ def default_url_options
21
+ Rails.configuration.action_mailer.default_url_options
22
+ end
23
+ end
@@ -0,0 +1,16 @@
1
+ require 'capybara/rails'
2
+
3
+ class ActionDispatch::IntegrationTest
4
+ include Capybara::DSL
5
+
6
+ setup do
7
+ Capybara.reset_sessions!
8
+ Capybara.use_default_driver
9
+ end
10
+
11
+ def self.use_javascript!
12
+ setup do
13
+ Capybara.current_driver = Capybara.javascript_driver
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ class ActiveSupport::TestCase
2
+ include FactoryGirl::Syntax::Methods
3
+ end
@@ -0,0 +1,17 @@
1
+ require 'webmock/minitest'
2
+
3
+ WebMock.disable_net_connect!(allow: %w[codeclimate.com])
4
+
5
+ def WebMock.requests
6
+ @requests ||= []
7
+ end
8
+
9
+ WebMock.after_request do |request, response|
10
+ WebMock.requests << request
11
+ end
12
+
13
+ class ActiveSupport::TestCase
14
+ setup do
15
+ WebMock.requests.clear
16
+ end
17
+ end
@@ -0,0 +1,157 @@
1
+ module Minitest
2
+ module Utils
3
+ class Reporter < Minitest::StatisticsReporter
4
+ def statistics
5
+ stats = super
6
+ end
7
+
8
+ def record(result)
9
+ super
10
+ print_result_code(result.result_code)
11
+ end
12
+
13
+ def report
14
+ super
15
+ io.sync = true
16
+
17
+ failing_results = results.reject(&:skipped?)
18
+ skipped_results = results.select(&:skipped?)
19
+
20
+ color = :green
21
+ color = :yellow if skipped_results.any?
22
+ color = :red if failing_results.any?
23
+
24
+ if failing_results.any? || skipped_results.any?
25
+ failing_results.each.with_index(1) {|result, index| display_failing(result, index) }
26
+ skipped_results.each.with_index(failing_results.size + 1) {|result, index| display_skipped(result, index) }
27
+ end
28
+
29
+ io.print "\n\n"
30
+ io.puts statistics
31
+ io.puts color(summary, color)
32
+
33
+ if failing_results.any?
34
+ io.puts "\nFailed Tests:\n"
35
+ failing_results.each {|result| display_replay_command(result) }
36
+ io.puts "\n\n"
37
+ end
38
+ end
39
+
40
+ private
41
+
42
+ def statistics
43
+ "Finished in %.6fs, %.4f runs/s, %.4f assertions/s." %
44
+ [total_time, count / total_time, assertions / total_time]
45
+ end
46
+
47
+ def summary # :nodoc:
48
+ [
49
+ pluralize('run', count),
50
+ pluralize('assertion', assertions),
51
+ pluralize('failure', failures),
52
+ pluralize('error', errors),
53
+ pluralize('skip', skips),
54
+ ].join(', ')
55
+ end
56
+
57
+ def indent(text)
58
+ text.gsub(/^/, ' ')
59
+ end
60
+
61
+ def display_failing(result, index)
62
+ backtrace = backtrace(result.failure.backtrace)
63
+ message = result.failure.message
64
+ message = message.lines.tap(&:pop).join.chomp if result.error?
65
+
66
+ str = "\n\n"
67
+ str << color("#{index}) #{result_name(result.name)}")
68
+ str << "\n" << color(indent(message), :red)
69
+ str << "\n" << color(backtrace, :blue)
70
+ io.print str
71
+ end
72
+
73
+ def display_skipped(result, index)
74
+ location = location(result.failure.location)
75
+ str = "\n\n"
76
+ str << color("#{index}) #{result_name(result.name)} [SKIPPED]", :yellow)
77
+ str << "\n" << indent(color(location, :yellow))
78
+ io.print str
79
+ end
80
+
81
+ def display_replay_command(result)
82
+ location = filter_backtrace(result.failure.backtrace).first.gsub(/:\d+.*?$/, '')
83
+ command = %[rake TEST=#{location} TESTOPTS="--name=#{result.name}"]
84
+ str = "\n"
85
+ str << color(command, :red)
86
+
87
+ io.print str
88
+ end
89
+
90
+ def backtrace(backtrace)
91
+ backtrace = filter_backtrace(backtrace).map {|line| location(line) }
92
+ return if backtrace.empty?
93
+ indent(backtrace.join("\n")).gsub(/^(\s+)/, "\\1# ")
94
+ end
95
+
96
+ def location(location)
97
+ return location unless location.start_with?(Dir.pwd)
98
+
99
+ location = location.gsub(%r[^#{Regexp.escape(Dir.pwd)}/], '')
100
+ "./#{location}"
101
+ end
102
+
103
+ def filter_backtrace(backtrace)
104
+ Minitest.backtrace_filter.filter(backtrace)
105
+ end
106
+
107
+ def result_name(name)
108
+ name
109
+ .gsub(/^test_\d+_/, '')
110
+ .gsub(/_/, ' ')
111
+ end
112
+
113
+ def print_result_code(result_code)
114
+ result_code = case result_code
115
+ when '.'
116
+ color('.', :green)
117
+ when 'S'
118
+ color('S', :yellow)
119
+ when 'F'
120
+ color('F', :red)
121
+ when 'E'
122
+ color('E', :red)
123
+ else
124
+ color(result_code)
125
+ end
126
+
127
+ io.print result_code
128
+ end
129
+
130
+ def color(string, color = :default)
131
+ case color
132
+ when :red
133
+ "\e[31m#{string}\e[0m"
134
+ when :green
135
+ "\e[32m#{string}\e[0m"
136
+ when :yellow
137
+ "\e[33m#{string}\e[0m"
138
+ when :blue
139
+ "\e[34m#{string}\e[0m"
140
+ else
141
+ "\e[0m#{string}"
142
+ end
143
+ end
144
+
145
+ def pluralize(word, count)
146
+ case count
147
+ when 0
148
+ "no #{word}s"
149
+ when 1
150
+ "1 #{word}"
151
+ else
152
+ "#{count} #{word}s"
153
+ end
154
+ end
155
+ end
156
+ end
157
+ end
@@ -0,0 +1,18 @@
1
+ module Minitest
2
+ module Utils
3
+ class TestNotifierReporter < Minitest::StatisticsReporter
4
+ def report
5
+ super
6
+
7
+ stats = TestNotifier::Stats.new(:minitest, {
8
+ count: count,
9
+ assertions: assertions,
10
+ failures: failures,
11
+ errors: errors
12
+ })
13
+
14
+ TestNotifier.notify(status: stats.status, message: stats.message)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,5 @@
1
+ module Minitest
2
+ module Utils
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ require 'minitest/utils'
2
+
3
+ module Minitest
4
+ def self.plugin_utils_init(options)
5
+ reporters = Minitest.reporter.reporters
6
+ reporters.clear
7
+ reporters << Minitest::Utils::Reporter.new(options[:io], options)
8
+ reporters << Minitest::Utils::TestNotifierReporter.new(options[:io], options) if defined?(TestNotifier)
9
+ end
10
+ end
@@ -0,0 +1,21 @@
1
+ require './lib/minitest/utils/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'minitest-utils'
5
+ spec.version = Minitest::Utils::VERSION
6
+ spec.authors = ['Nando Vieira']
7
+ spec.email = ['fnando.vieira@gmail.com']
8
+ spec.summary = 'Some utilities for your Minitest day-to-day usage.'
9
+ spec.description = spec.summary
10
+ spec.homepage = 'http://github.com/fnando/minitest-utils'
11
+
12
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
13
+ spec.bindir = 'exe'
14
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
15
+ spec.require_paths = ['lib']
16
+
17
+ spec.add_dependency 'minitest'
18
+ spec.add_development_dependency 'bundler', '~> 1.9'
19
+ spec.add_development_dependency 'rake', '~> 10.0'
20
+ spec.add_development_dependency 'pry-meta'
21
+ end
Binary file
Binary file
Binary file
Binary file
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: minitest-utils
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nando Vieira
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-04-30 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: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.9'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-meta
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Some utilities for your Minitest day-to-day usage.
70
+ email:
71
+ - fnando.vieira@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - README.md
79
+ - Rakefile
80
+ - lib/minitest/utils.rb
81
+ - lib/minitest/utils/rails.rb
82
+ - lib/minitest/utils/rails/capybara.rb
83
+ - lib/minitest/utils/rails/factory_girl.rb
84
+ - lib/minitest/utils/rails/webmock.rb
85
+ - lib/minitest/utils/reporter.rb
86
+ - lib/minitest/utils/test_notifier_reporter.rb
87
+ - lib/minitest/utils/version.rb
88
+ - lib/minitest/utils_plugin.rb
89
+ - minitest-utils.gemspec
90
+ - screenshots/dark-failing.png
91
+ - screenshots/dark-success.png
92
+ - screenshots/light-failing.png
93
+ - screenshots/light-success.png
94
+ homepage: http://github.com/fnando/minitest-utils
95
+ licenses: []
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.4.6
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Some utilities for your Minitest day-to-day usage.
117
+ test_files: []