rspec-rerun 0.3.1 → 1.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f84f752f73a6cf918bccb79ac52aa94f784f905f
4
- data.tar.gz: 85c72128204098706dcfc44747ba4723ab727c44
3
+ metadata.gz: 65364fcd0d558bc48418792fc46838cb31773447
4
+ data.tar.gz: 33af133659889ea4cca51bcc33da1de241269046
5
5
  SHA512:
6
- metadata.gz: 554f23058d54bb1cf30f427d5abe96d9ef6b8df1ab79de7b712015302a125a0684812f937444da5142b24e4dc0bba0c6995ac5c05527cd61ccab036e8202d50c
7
- data.tar.gz: 0009bca486f669a32beb4ceb50a241c57b88f6105f1cb1845ab0bdc00ce090ba174e0e6f6c2d2254c26212b230d4e2532478f7a6e453be5d74bb8e9b7d22a22e
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
- The **rspec-rerun** gem is a drop-in solution to retry (rerun) failed RSpec examples. It may be useful, for example, with finicky Capybara tests. The strategy to rerun failed specs is to output a file called `rspec.failures` that contains a list of failed examples and to feed that file back to RSpec via `-e`.
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
- Require `rspec-rerun` and change the default task in `Rakefile`.
23
+ ```ruby
24
+ # Rakefile
25
+ require 'rspec-rerun/tasks'
26
+ task default: 'rspec-rerun:spec'
27
+ ```
24
28
 
25
- ``` ruby
26
- require 'rspec-rerun'
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
@@ -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 rspec_opts(args, spec_files = nil)
6
- opts = [
8
+ def rspec_options(args, spec_files = nil)
9
+ options = [
7
10
  spec_files,
8
- '--require', File.join(File.dirname(__FILE__), '../rspec-rerun'),
9
- '--format', 'RSpec::Rerun::Formatters::FailuresFormatter',
10
- *dot_rspec_params
11
+ '--require', 'rspec-rerun/formatter',
12
+ '--format', 'RSpec::Rerun::Formatter',
13
+ *dot_rspec_options
11
14
  ].compact.flatten
12
15
  if args[:tag]
13
- opts << '--tag'
14
- opts << args[:tag]
16
+ options << '--tag'
17
+ options << args[:tag]
15
18
  end
16
- opts
19
+ options
17
20
  end
18
21
 
19
22
  def parse_args(args)
20
- opts = args.extras
23
+ options = args.extras
21
24
 
22
25
  # Error on multiple arguments
23
- if opts.size > 1
26
+ if options.size > 1
24
27
  fail ArgumentError 'rspec-rerun can take an integer (retry_count) or options hash'
25
28
  else
26
- opts = opts[0]
29
+ options = options[0]
27
30
  end
28
31
 
29
32
  # Handle if opts is just a retry_count integer
30
- opts = if opts.is_a? Hash
31
- opts
32
- else
33
- { retry_count: opts }
34
- end
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
- opts[:pattern] ||= ENV['RSPEC_RERUN_PATTERN'] if ENV['RSPEC_RERUN_PATTERN']
38
- opts[:tag] ||= ENV['RSPEC_RERUN_TAG'] if ENV['RSPEC_RERUN_TAG']
39
- opts[:retry_count] ||= ENV['RSPEC_RERUN_RETRY_COUNT'] if ENV['RSPEC_RERUN_RETRY_COUNT']
40
- opts[:verbose] = (ENV['RSPEC_RERUN_VERBOSE'] != 'false') if opts[:verbose].nil?
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
- opts
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 dot_rspec_params
63
+ def dot_rspec_options
48
64
  dot_rspec_file = ['.rspec', File.expand_path('~/.rspec')].detect { |f| File.exist?(f) }
49
- dot_rspec = if dot_rspec_file
50
- file_contents = File.read(dot_rspec_file)
51
- file_contents.split(/\n+/).map(&:shellsplit).flatten
52
- else
53
- []
54
- end
55
- dot_rspec.concat ['--format', 'progress'] unless dot_rspec.include?('--format')
56
- dot_rspec
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
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module Rerun
3
- VERSION = '0.3.1'
3
+ VERSION = '1.0.0'
4
4
  end
5
5
  end
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.3.1
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-12 00:00:00.000000000 Z
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
@@ -1,8 +0,0 @@
1
- require 'rspec-rerun/version'
2
- require 'rspec-rerun/formatters/failures_formatter'
3
-
4
- if defined?(Rake)
5
- Dir[File.join(File.dirname(__FILE__), '../lib/tasks/**/*.rake')].each do |f|
6
- load f
7
- end
8
- end
@@ -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
@@ -1,8 +0,0 @@
1
- module RSpec
2
- module Rerun
3
- def self.rspec3?
4
- require 'rspec'
5
- ::RSpec.const_defined?(:Support)
6
- end
7
- end
8
- end
@@ -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