rspec-rerun 0.3.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -14
- data/lib/rspec-rerun/formatter.rb +30 -0
- data/lib/rspec-rerun/tasks.rb +87 -30
- data/lib/rspec-rerun/version.rb +1 -1
- metadata +17 -6
- data/lib/rspec-rerun.rb +0 -8
- data/lib/rspec-rerun/formatters/failures_formatter.rb +0 -44
- data/lib/rspec-rerun/rspec.rb +0 -8
- data/lib/tasks/rspec.rake +0 -43
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 65364fcd0d558bc48418792fc46838cb31773447
|
4
|
+
data.tar.gz: 33af133659889ea4cca51bcc33da1de241269046
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98cafbb7c1a635cbd0a67f82088649021ae86aa05bea5eaa152e265597ec9e541a1e83b71784f077328504cfbf3cc202bcf6cc47b96117960033e588b31e3e31
|
7
|
+
data.tar.gz: 5fff934cf2f8e821088f186c4ea8d14141196d4314062da2460b2956889ec0be62c7e021fb75b394beb063ab2fcfaab7ff5d070dfc470c220e15175d338d279f
|
data/README.md
CHANGED
@@ -5,26 +5,29 @@
|
|
5
5
|
[![Dependency Status](https://gemnasium.com/dblock/rspec-rerun.svg)](https://gemnasium.com/dblock/rspec-rerun)
|
6
6
|
[![Code Climate](https://codeclimate.com/github/dblock/rspec-rerun.svg)](https://codeclimate.com/github/dblock/rspec-rerun)
|
7
7
|
|
8
|
-
|
8
|
+
**rspec-rerun** reruns failed RSpec examples (for brittle tests).
|
9
|
+
|
10
|
+
It writes failed examples to the file `rspec.failures` and feeds these back to RSpec via `-e`.
|
9
11
|
|
10
12
|
Usage
|
11
13
|
-----
|
12
|
-
|
13
|
-
Add `rspec-rerun` to `Gemfile` in the `:development` and `:test` groups.
|
14
|
-
If you're using RSpec 3, also add `rspec-legacy_formatters`.
|
14
|
+
(For RSpec 2 use version '~> 0.3.1'. )
|
15
15
|
|
16
16
|
``` ruby
|
17
|
+
# Gemfile
|
17
18
|
group :development, :test do
|
18
19
|
gem 'rspec-rerun'
|
19
|
-
gem 'rspec-legacy_formatters'
|
20
20
|
end
|
21
21
|
```
|
22
22
|
|
23
|
-
|
23
|
+
```ruby
|
24
|
+
# Rakefile
|
25
|
+
require 'rspec-rerun/tasks'
|
26
|
+
task default: 'rspec-rerun:spec'
|
27
|
+
```
|
24
28
|
|
25
|
-
```
|
26
|
-
|
27
|
-
task :default => 'rspec-rerun:spec'
|
29
|
+
```bash
|
30
|
+
echo rspec.failures >> .gitignore
|
28
31
|
```
|
29
32
|
|
30
33
|
Run `rake` or `rake rspec-rerun:spec`. Failed examples will be rerun automatically.
|
@@ -43,11 +46,6 @@ You can set the following global environment variables:
|
|
43
46
|
* `RSPEC_RERUN_TAG`: only execute the tag specified
|
44
47
|
* `RSPEC_RERUN_VERBOSE`: if 'false', don't show the rspec command invoked by Rake
|
45
48
|
|
46
|
-
Git Ignore
|
47
|
-
----------
|
48
|
-
|
49
|
-
A list of failed examples is stored in a file called `rspec.failures`. It might also be a good idea that you add `rspec.failures` to `.gitignore`.
|
50
|
-
|
51
49
|
History
|
52
50
|
-------
|
53
51
|
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'rspec/core'
|
2
|
+
require 'rspec/legacy_formatters'
|
3
|
+
require 'rspec/core/formatters/base_formatter'
|
4
|
+
|
5
|
+
module RSpec
|
6
|
+
module Rerun
|
7
|
+
class Formatter < RSpec::Core::Formatters::BaseFormatter
|
8
|
+
FILENAME = 'rspec.failures'
|
9
|
+
|
10
|
+
def dump_failures
|
11
|
+
if failed_examples.empty?
|
12
|
+
clean!
|
13
|
+
else
|
14
|
+
rerun_commands = failed_examples.map { |e| retry_command(e) }
|
15
|
+
File.write(FILENAME, rerun_commands.join(''))
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def clean!
|
20
|
+
File.delete FILENAME if File.exist? FILENAME
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def retry_command(example)
|
26
|
+
example.location.gsub("\"", "\\\"") + "\n"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/rspec-rerun/tasks.rb
CHANGED
@@ -1,61 +1,118 @@
|
|
1
|
+
require 'rspec/core/rake_task'
|
2
|
+
require 'rspec-rerun/formatter'
|
3
|
+
|
1
4
|
module RSpec
|
2
5
|
module Rerun
|
3
6
|
module Tasks
|
4
7
|
class << self
|
5
|
-
def
|
6
|
-
|
8
|
+
def rspec_options(args, spec_files = nil)
|
9
|
+
options = [
|
7
10
|
spec_files,
|
8
|
-
'--require',
|
9
|
-
'--format', 'RSpec::Rerun::
|
10
|
-
*
|
11
|
+
'--require', 'rspec-rerun/formatter',
|
12
|
+
'--format', 'RSpec::Rerun::Formatter',
|
13
|
+
*dot_rspec_options
|
11
14
|
].compact.flatten
|
12
15
|
if args[:tag]
|
13
|
-
|
14
|
-
|
16
|
+
options << '--tag'
|
17
|
+
options << args[:tag]
|
15
18
|
end
|
16
|
-
|
19
|
+
options
|
17
20
|
end
|
18
21
|
|
19
22
|
def parse_args(args)
|
20
|
-
|
23
|
+
options = args.extras
|
21
24
|
|
22
25
|
# Error on multiple arguments
|
23
|
-
if
|
26
|
+
if options.size > 1
|
24
27
|
fail ArgumentError 'rspec-rerun can take an integer (retry_count) or options hash'
|
25
28
|
else
|
26
|
-
|
29
|
+
options = options[0]
|
27
30
|
end
|
28
31
|
|
29
32
|
# Handle if opts is just a retry_count integer
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
33
|
+
options = if options.is_a? Hash
|
34
|
+
options
|
35
|
+
else
|
36
|
+
{ retry_count: options }
|
37
|
+
end
|
35
38
|
|
36
39
|
# Parse environment variables
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
40
|
+
options[:pattern] ||= ENV['RSPEC_RERUN_PATTERN'] if ENV['RSPEC_RERUN_PATTERN']
|
41
|
+
options[:tag] ||= ENV['RSPEC_RERUN_TAG'] if ENV['RSPEC_RERUN_TAG']
|
42
|
+
options[:retry_count] ||= ENV['RSPEC_RERUN_RETRY_COUNT'] if ENV['RSPEC_RERUN_RETRY_COUNT']
|
43
|
+
options[:verbose] = (ENV['RSPEC_RERUN_VERBOSE'] != 'false') if options[:verbose].nil?
|
44
|
+
|
45
|
+
options
|
46
|
+
end
|
47
|
+
|
48
|
+
def failing_specs
|
49
|
+
File.read(RSpec::Rerun::Formatter::FILENAME).split
|
50
|
+
end
|
41
51
|
|
42
|
-
|
52
|
+
def failure_message
|
53
|
+
failed_count = failing_specs.count
|
54
|
+
"[#{Time.now}] Failed, #{failed_count} failure#{failed_count == 1 ? '' : 's'}"
|
55
|
+
end
|
56
|
+
|
57
|
+
def rerun(args)
|
58
|
+
Rake::Task['rspec-rerun:run'].execute(args)
|
43
59
|
end
|
44
60
|
|
45
61
|
private
|
46
62
|
|
47
|
-
def
|
63
|
+
def dot_rspec_options
|
48
64
|
dot_rspec_file = ['.rspec', File.expand_path('~/.rspec')].detect { |f| File.exist?(f) }
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
65
|
+
options = if dot_rspec_file
|
66
|
+
file_contents = File.read(dot_rspec_file)
|
67
|
+
file_contents.split(/\n+/).map(&:shellsplit).flatten
|
68
|
+
else
|
69
|
+
[]
|
70
|
+
end
|
71
|
+
options.concat ['--format', 'progress'] unless options.include?('--format')
|
72
|
+
options
|
57
73
|
end
|
58
74
|
end
|
59
75
|
end
|
60
76
|
end
|
61
77
|
end
|
78
|
+
|
79
|
+
desc 'Run RSpec examples.'
|
80
|
+
RSpec::Core::RakeTask.new('rspec-rerun:run') do |t, args|
|
81
|
+
t.pattern = args[:pattern] if args[:pattern]
|
82
|
+
t.fail_on_error = false
|
83
|
+
t.verbose = false if args[:verbose] == false
|
84
|
+
t.rspec_opts = RSpec::Rerun::Tasks.rspec_options(args)
|
85
|
+
end
|
86
|
+
|
87
|
+
desc 'Re-run failed RSpec examples.'
|
88
|
+
RSpec::Core::RakeTask.new('rspec-rerun:rerun') do |t, args|
|
89
|
+
failing_specs = RSpec::Rerun::Tasks.failing_specs
|
90
|
+
|
91
|
+
t.pattern = args[:pattern] if args[:pattern]
|
92
|
+
t.fail_on_error = false
|
93
|
+
t.verbose = false if args[:verbose] == false
|
94
|
+
t.rspec_opts = RSpec::Rerun::Tasks.rspec_options(args, failing_specs.join(' '))
|
95
|
+
end
|
96
|
+
|
97
|
+
desc 'Run RSpec code examples.'
|
98
|
+
task 'rspec-rerun:spec' do |_t, args|
|
99
|
+
parsed_args = RSpec::Rerun::Tasks.parse_args(args)
|
100
|
+
retry_count = (parsed_args[:retry_count] || 1).to_i
|
101
|
+
|
102
|
+
fail 'retry count must be >= 1' if retry_count <= 0
|
103
|
+
FileUtils.rm_f RSpec::Rerun::Formatter::FILENAME
|
104
|
+
RSpec::Rerun::Tasks.rerun(parsed_args)
|
105
|
+
|
106
|
+
until $?.success? || retry_count == 0
|
107
|
+
retry_count -= 1
|
108
|
+
msg = RSpec::Rerun::Tasks.failure_message
|
109
|
+
msg += ", re-running, #{retry_count} #{retry_count == 1 ? 'retry' : 'retries'} left" if retry_count > 0
|
110
|
+
$stderr.puts msg
|
111
|
+
RSpec::Rerun::Tasks.rerun(parsed_args)
|
112
|
+
end
|
113
|
+
|
114
|
+
unless $?.success?
|
115
|
+
$stderr.puts RSpec::Rerun::Tasks.failure_message
|
116
|
+
fail "#{failed_count} failure#{failed_count == 1 ? '' : 's'}"
|
117
|
+
end
|
118
|
+
end
|
data/lib/rspec-rerun/version.rb
CHANGED
metadata
CHANGED
@@ -1,17 +1,31 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-rerun
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Doubrovkine
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec-legacy_formatters
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
16
30
|
requirements:
|
17
31
|
- - ">="
|
@@ -87,12 +101,9 @@ extensions: []
|
|
87
101
|
extra_rdoc_files: []
|
88
102
|
files:
|
89
103
|
- README.md
|
90
|
-
- lib/rspec-rerun.rb
|
91
|
-
- lib/rspec-rerun/formatters/failures_formatter.rb
|
92
|
-
- lib/rspec-rerun/rspec.rb
|
104
|
+
- lib/rspec-rerun/formatter.rb
|
93
105
|
- lib/rspec-rerun/tasks.rb
|
94
106
|
- lib/rspec-rerun/version.rb
|
95
|
-
- lib/tasks/rspec.rake
|
96
107
|
homepage: https://github.com/dblock/rspec-rerun
|
97
108
|
licenses:
|
98
109
|
- MIT
|
data/lib/rspec-rerun.rb
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
require 'rspec/core'
|
2
|
-
require 'rspec-rerun/rspec'
|
3
|
-
|
4
|
-
if RSpec::Rerun.rspec3?
|
5
|
-
begin
|
6
|
-
require 'rspec/legacy_formatters'
|
7
|
-
rescue LoadError => e
|
8
|
-
STDERR.puts '*' * 80
|
9
|
-
STDERR.puts e.message
|
10
|
-
STDERR.puts 'Please add rspec-legacy_formatters to your Gemfile.'
|
11
|
-
STDERR.puts 'See https://github.com/dblock/rspec-rerun/pull/22 for details.'
|
12
|
-
STDERR.puts '*' * 80
|
13
|
-
raise
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
require 'rspec/core/formatters/base_formatter'
|
18
|
-
|
19
|
-
module RSpec
|
20
|
-
module Rerun
|
21
|
-
module Formatters
|
22
|
-
class FailuresFormatter < RSpec::Core::Formatters::BaseFormatter
|
23
|
-
FILENAME = 'rspec.failures'
|
24
|
-
|
25
|
-
def dump_failures
|
26
|
-
return if failed_examples.empty?
|
27
|
-
f = File.new(FILENAME, 'w+')
|
28
|
-
failed_examples.each do |example|
|
29
|
-
f.puts retry_command(example)
|
30
|
-
end
|
31
|
-
f.close
|
32
|
-
end
|
33
|
-
|
34
|
-
def retry_command(example)
|
35
|
-
example.location.gsub("\"", "\\\"")
|
36
|
-
end
|
37
|
-
|
38
|
-
def clean!
|
39
|
-
File.delete FILENAME if File.exist? FILENAME
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
data/lib/rspec-rerun/rspec.rb
DELETED
data/lib/tasks/rspec.rake
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
require 'rspec/core/rake_task'
|
2
|
-
require 'rspec-rerun/tasks'
|
3
|
-
|
4
|
-
desc 'Run RSpec examples.'
|
5
|
-
RSpec::Core::RakeTask.new('rspec-rerun:run') do |t, args|
|
6
|
-
t.pattern = args[:pattern] if args[:pattern]
|
7
|
-
t.fail_on_error = false
|
8
|
-
t.verbose = false if args[:verbose] == false
|
9
|
-
t.rspec_opts = RSpec::Rerun::Tasks.rspec_opts(args)
|
10
|
-
end
|
11
|
-
|
12
|
-
desc 'Re-run failed RSpec examples.'
|
13
|
-
RSpec::Core::RakeTask.new('rspec-rerun:rerun') do |t, args|
|
14
|
-
failing_specs = File.read(RSpec::Rerun::Formatters::FailuresFormatter::FILENAME).split
|
15
|
-
|
16
|
-
t.pattern = args[:pattern] if args[:pattern]
|
17
|
-
t.fail_on_error = false
|
18
|
-
t.verbose = false if args[:verbose] == false
|
19
|
-
t.rspec_opts = RSpec::Rerun::Tasks.rspec_opts(args, failing_specs.join(' '))
|
20
|
-
end
|
21
|
-
|
22
|
-
desc 'Run RSpec code examples.'
|
23
|
-
task 'rspec-rerun:spec' do |_t, args|
|
24
|
-
parsed_args = RSpec::Rerun::Tasks.parse_args(args)
|
25
|
-
retry_count = (parsed_args[:retry_count] || 1).to_i
|
26
|
-
|
27
|
-
fail 'retry count must be >= 1' if retry_count <= 0
|
28
|
-
FileUtils.rm_f RSpec::Rerun::Formatters::FailuresFormatter::FILENAME
|
29
|
-
Rake::Task['rspec-rerun:run'].execute(parsed_args)
|
30
|
-
while !$?.success? && retry_count > 0
|
31
|
-
retry_count -= 1
|
32
|
-
failed_count = File.read(RSpec::Rerun::Formatters::FailuresFormatter::FILENAME).split(/\n+/).count
|
33
|
-
msg = "[#{Time.now}] Failed, re-running #{failed_count} failure#{failed_count == 1 ? '' : 's'}"
|
34
|
-
msg += ", #{retry_count} #{retry_count == 1 ? 'retry' : 'retries'} left" if retry_count > 0
|
35
|
-
$stderr.puts "#{msg} ..."
|
36
|
-
Rake::Task['rspec-rerun:rerun'].execute(parsed_args)
|
37
|
-
end
|
38
|
-
unless $?.success?
|
39
|
-
failed_count = File.read(RSpec::Rerun::Formatters::FailuresFormatter::FILENAME).split(/\n+/).count
|
40
|
-
$stderr.puts "[#{Time.now}] #{failed_count} failure#{failed_count == 1 ? '' : 's'}."
|
41
|
-
fail "#{failed_count} failure#{failed_count == 1 ? '' : 's'}"
|
42
|
-
end
|
43
|
-
end
|