rspec-rerun 0.2.0 → 0.3.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: 134c8ec35696f70df71be92ceb94e794a771ce31
4
- data.tar.gz: a528f3dcb318a4de70865851fe2ffc50956a7791
3
+ metadata.gz: 6d388b330116565e3727f28033b49af020d54bf5
4
+ data.tar.gz: 0459c3704ff72c816994e5b033fcd759c039d43b
5
5
  SHA512:
6
- metadata.gz: afa781d2506ec6b588878d5de5d8b0debbcb1269a9c0779ab53e63ead1a592068a48c0ab08a3ed219cb84950edcf1e2bc0d8a52b0e722f208be4cb1a1181dab3
7
- data.tar.gz: 79b82066a6ed3aeca3f573319237e44d668057fa365888c17765af257bc5fedb83d5052277ba4714af5f53b1ebe8ff87aa8729e9b805ffeed3cbe2d707fda3ce
6
+ metadata.gz: 3b82514b1a26c9c18d10e7012a75b9f21c9b00c10110b19b9b9d18c3c22f38f79e4096bb6c4a683f33c8823b1d722369ceee24785014258448e60e8b3a6bc2e9
7
+ data.tar.gz: 6e22e346348305c388dd4b886c9afaed3c1f7874ee5199a2a2910d40781bb4c2f86f6e57bf34ed1f1fbd1c895e27567c31ae700f5d6c0724cf3ee117399b2ae6
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
1
  Gemfile.lock
2
2
  pkg
3
3
  rspec.failures
4
+ .bundle
@@ -1,6 +1,6 @@
1
1
  AllCops:
2
2
  Exclude:
3
- - vendor/**
3
+ - vendor/**/*
4
4
 
5
5
  LineLength:
6
6
  Enabled: false
@@ -4,7 +4,6 @@ cache: bundler
4
4
 
5
5
  rvm:
6
6
  - 2.1.2
7
- - 2.1.0
8
7
  - 2.0.0
9
8
  - 1.9.3
10
9
  - rbx-2.2.10
@@ -16,3 +15,8 @@ matrix:
16
15
  allow_failures:
17
16
  - rvm: ruby-head
18
17
  - rvm: jruby-head
18
+
19
+ env:
20
+ - RSPEC_VERSION=2
21
+ - RSPEC_VERSION=3
22
+
@@ -1,3 +1,11 @@
1
+ 0.3.0 (3/10/2015)
2
+ -----------------
3
+
4
+ * [#22](https://github.com/dblock/rspec-rerun/pull/22): Added support for RSpec 3 - [@nightscape](https://github.com/nightscape), [@dblock](https://github.com/dblock).
5
+ * [#23](https://github.com/dblock/rspec-rerun/issues/23): Fixed dual formatter error - [@KurtPreston](https://github.com/KurtPreston).
6
+ * [#26](https://github.com/dblock/rspec-rerun/pull/26): Allow disabling RSpec verbose output - [@KurtPreston](https://github.com/KurtPreston).
7
+ * [#26](https://github.com/dblock/rspec-rerun/pull/26): Added support for running on a specific tag - [@KurtPreston](https://github.com/KurtPreston).
8
+
1
9
  0.2.0
2
10
  -----
3
11
 
data/Gemfile CHANGED
@@ -1,3 +1,13 @@
1
1
  source "http://rubygems.org"
2
2
 
3
3
  gemspec
4
+
5
+ case rspec_version = ENV['RSPEC_VERSION'] || '~> 3.0'
6
+ when /2/
7
+ gem 'rspec', '~> 2.11'
8
+ when /3/
9
+ gem 'rspec', '~> 3.0'
10
+ gem 'rspec-legacy_formatters'
11
+ else
12
+ gem 'rspec', rspec_version
13
+ end
data/README.md CHANGED
@@ -1,6 +1,9 @@
1
1
  ![rspec-rerun](https://raw.github.com/dblock/rspec-rerun/master/rspec-rerun.png)
2
2
 
3
- [![Build Status](https://secure.travis-ci.org/dblock/rspec-rerun.png)](http://travis-ci.org/dblock/rspec-rerun)
3
+ [![Gem Version](http://img.shields.io/gem/v/rspec-rerun.svg)](http://badge.fury.io/rb/rspec-rerun)
4
+ [![Build Status](http://img.shields.io/travis/dblock/rspec-rerun.svg)](https://travis-ci.org/dblock/rspec-rerun)
5
+ [![Dependency Status](https://gemnasium.com/dblock/rspec-rerun.svg)](https://gemnasium.com/dblock/rspec-rerun)
6
+ [![Code Climate](https://codeclimate.com/github/dblock/rspec-rerun.svg)](https://codeclimate.com/github/dblock/rspec-rerun)
4
7
 
5
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`.
6
9
 
@@ -8,10 +11,12 @@ Usage
8
11
  -----
9
12
 
10
13
  Add `rspec-rerun` to `Gemfile` in the `:development` and `:test` groups.
14
+ If you're using RSpec 3, also add `rspec-legacy_formatters`.
11
15
 
12
16
  ``` ruby
13
17
  group :development, :test do
14
- gem "rspec-rerun"
18
+ gem 'rspec-rerun'
19
+ gem 'rspec-legacy_formatters'
15
20
  end
16
21
  ```
17
22
 
@@ -19,7 +24,7 @@ Require `rspec-rerun` and change the default task in `Rakefile`.
19
24
 
20
25
  ``` ruby
21
26
  require 'rspec-rerun'
22
- task :default => "rspec-rerun:spec"
27
+ task :default => 'rspec-rerun:spec'
23
28
  ```
24
29
 
25
30
  Run `rake` or `rake rspec-rerun:spec`. Failed examples will be rerun automatically.
@@ -35,6 +40,8 @@ You can set the following global environment variables:
35
40
 
36
41
  * `RSPEC_RERUN_RETRY_COUNT`: number of retries, defaults to the value of `retry_count` or 1
37
42
  * `RSPEC_RERUN_PATTERN`: spec file pattern, defaults to the value defined by `RSpec::Core::RakeTask`
43
+ * `RSPEC_RERUN_TAG`: only execute the tag specified
44
+ * `RSPEC_RERUN_VERBOSE`: if 'false', don't show the rspec command invoked by Rake
38
45
 
39
46
  Git Ignore
40
47
  ----------
@@ -1,6 +1,5 @@
1
1
  require 'rspec-rerun/version'
2
-
3
- require 'rspec-rerun/formatters/failures_formatter.rb'
2
+ require 'rspec-rerun/formatters/failures_formatter'
4
3
 
5
4
  if defined?(Rake)
6
5
  Dir[File.join(File.dirname(__FILE__), '../lib/tasks/**/*.rake')].each do |f|
@@ -1,3 +1,19 @@
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
+
1
17
  require 'rspec/core/formatters/base_formatter'
2
18
 
3
19
  module RSpec
@@ -0,0 +1,8 @@
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,5 +1,5 @@
1
1
  module RSpec
2
2
  module Rerun
3
- VERSION = '0.2.0'
3
+ VERSION = '0.3.0'
4
4
  end
5
5
  end
@@ -1,47 +1,38 @@
1
1
  require 'rspec/core/rake_task'
2
2
 
3
3
  desc "Run RSpec examples."
4
- RSpec::Core::RakeTask.new("rspec-rerun:run") do |t|
5
- dot_rspec = [".rspec", File.expand_path("~/.rspec")].detect { |f| File.exist?(f) }
6
- dot_rspec = (dot_rspec ? File.read(dot_rspec).split(/\n+/).map { |l| l.shellsplit } : [])
7
- dot_rspec.concat ["--format", "progress"] unless dot_rspec.include?("--format")
8
-
9
- t.pattern = ENV['RSPEC_RERUN_PATTERN'] if ENV['RSPEC_RERUN_PATTERN']
4
+ RSpec::Core::RakeTask.new("rspec-rerun:run") do |t, args|
5
+ t.pattern = args[:pattern] if args[:pattern]
10
6
  t.fail_on_error = false
11
- t.rspec_opts = [
12
- "--require", File.join(File.dirname(__FILE__), '../rspec-rerun'),
13
- "--format", "RSpec::Rerun::Formatters::FailuresFormatter",
14
- *dot_rspec
15
- ].flatten
7
+ t.verbose = false if args[:verbose] == false
8
+ t.rspec_opts = rspec_opts(args)
16
9
  end
17
10
 
18
11
  desc "Re-run failed RSpec examples."
19
- RSpec::Core::RakeTask.new("rspec-rerun:rerun") do |t|
12
+ RSpec::Core::RakeTask.new("rspec-rerun:rerun") do |t, args|
20
13
  failing_specs = File.read(RSpec::Rerun::Formatters::FailuresFormatter::FILENAME).split
21
14
 
22
- t.pattern = ENV['RSPEC_RERUN_PATTERN'] if ENV['RSPEC_RERUN_PATTERN']
15
+ t.pattern = args[:pattern] if args[:pattern]
23
16
  t.fail_on_error = false
24
- t.rspec_opts = [
25
- failing_specs.join(' '),
26
- "--require", File.join(File.dirname(__FILE__), '../rspec-rerun'),
27
- "--format", "RSpec::Rerun::Formatters::FailuresFormatter",
28
- File.exist?(".rspec") ? File.read(".rspec").split(/\n+/).map { |l| l.shellsplit } : nil
29
- ].flatten
17
+ t.verbose = false if args[:verbose] == false
18
+ t.rspec_opts = rspec_opts(args, failing_specs.join(' '))
30
19
  end
31
20
 
32
21
  desc "Run RSpec code examples."
33
- task "rspec-rerun:spec", :retry_count do |t, args|
34
- retry_count = (args[:retry_count] || ENV['RSPEC_RERUN_RETRY_COUNT'] || 1).to_i
22
+ task "rspec-rerun:spec" do |t, args|
23
+ parsed_args = parse_args(args)
24
+ retry_count = (parsed_args[:retry_count] || 1).to_i
25
+
35
26
  fail "retry count must be >= 1" if retry_count <= 0
36
27
  FileUtils.rm_f RSpec::Rerun::Formatters::FailuresFormatter::FILENAME
37
- Rake::Task["rspec-rerun:run"].execute
28
+ Rake::Task["rspec-rerun:run"].execute(parsed_args)
38
29
  while !$?.success? && retry_count > 0
39
30
  retry_count -= 1
40
31
  failed_count = File.read(RSpec::Rerun::Formatters::FailuresFormatter::FILENAME).split(/\n+/).count
41
32
  msg = "[#{Time.now}] Failed, re-running #{failed_count} failure#{failed_count == 1 ? '' : 's'}"
42
33
  msg += ", #{retry_count} #{retry_count == 1 ? 'retry' : 'retries'} left" if retry_count > 0
43
34
  $stderr.puts "#{msg} ..."
44
- Rake::Task["rspec-rerun:rerun"].execute
35
+ Rake::Task["rspec-rerun:rerun"].execute(parsed_args)
45
36
  end
46
37
  if !$?.success?
47
38
  failed_count = File.read(RSpec::Rerun::Formatters::FailuresFormatter::FILENAME).split(/\n+/).count
@@ -49,3 +40,55 @@ task "rspec-rerun:spec", :retry_count do |t, args|
49
40
  fail "#{failed_count} failure#{failed_count == 1 ? '' : 's'}"
50
41
  end
51
42
  end
43
+
44
+ def dot_rspec_params
45
+ dot_rspec_file = [".rspec", File.expand_path("~/.rspec")].detect { |f| File.exist?(f) }
46
+ dot_rspec = if dot_rspec_file
47
+ file_contents = File.read(dot_rspec_file)
48
+ file_contents.split(/\n+/).map { |l| l.shellsplit }.flatten
49
+ else
50
+ []
51
+ end
52
+ dot_rspec.concat ["--format", "progress"] unless dot_rspec.include?("--format")
53
+ dot_rspec
54
+ end
55
+
56
+ def rspec_opts(args, spec_files = nil)
57
+ opts = [
58
+ spec_files,
59
+ "--require", File.join(File.dirname(__FILE__), '../rspec-rerun'),
60
+ "--format", "RSpec::Rerun::Formatters::FailuresFormatter",
61
+ *dot_rspec_params
62
+ ].compact.flatten
63
+ if args[:tag]
64
+ opts << "--tag"
65
+ opts << args[:tag]
66
+ end
67
+ opts
68
+ end
69
+
70
+ def parse_args(args)
71
+ opts = args.extras
72
+
73
+ # Error on multiple arguments
74
+ if opts.size > 1
75
+ raise ArgumentError "rspec-rerun can take an integer (retry_count) or options hash"
76
+ else
77
+ opts = opts[0]
78
+ end
79
+
80
+ # Handle if opts is just a retry_count integer
81
+ opts = if opts.is_a? Hash
82
+ opts
83
+ else
84
+ {retry_count: opts}
85
+ end
86
+
87
+ # Parse environment variables
88
+ opts[:pattern] ||= ENV['RSPEC_RERUN_PATTERN'] if ENV['RSPEC_RERUN_PATTERN']
89
+ opts[:tag] ||= ENV['RSPEC_RERUN_TAG'] if ENV['RSPEC_RERUN_PATTERN']
90
+ opts[:retry_count] ||= ENV['RSPEC_RERUN_RETRY_COUNT'] if ENV['RSPEC_RERUN_RETRY_COUNT']
91
+ opts[:verbose] = (ENV['RSPEC_RERUN_VERBOSE'] != 'false') if opts[:verbose].nil?
92
+
93
+ opts
94
+ end
@@ -1,4 +1,5 @@
1
1
  require './lib/rspec-rerun/version'
2
+ require './lib/rspec-rerun/rspec'
2
3
 
3
4
  Gem::Specification.new do |s|
4
5
  s.name = 'rspec-rerun'
@@ -11,7 +12,7 @@ Gem::Specification.new do |s|
11
12
  s.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
12
13
  s.test_files = s.files.grep(/^(spec)\//)
13
14
 
14
- s.add_runtime_dependency 'rspec', '>= 2.11.0', '< 3'
15
+ s.add_runtime_dependency 'rspec'
15
16
 
16
17
  s.add_development_dependency 'rake'
17
18
  s.add_development_dependency 'bundler'
@@ -53,6 +53,30 @@ describe 'RakeTask' do
53
53
  end.to raise_error RuntimeError, /failed with exit code 1/
54
54
  end
55
55
 
56
+ context 'verbose output' do
57
+ it 'displays the rspec command by default' do
58
+ `cd #{root} && RSPEC_RERUN_MARKER=#{@filename} RSPEC_RERUN_PATTERN=spec-runs/succeeds_spec.rb rake rspec-rerun:spec`.should include('rspec')
59
+ end
60
+
61
+ context 'when the RSPEC_RERUN_VERBOSE flag is set to false' do
62
+ it "doesn't display the rspec command" do
63
+ `cd #{root} && RSPEC_RERUN_VERBOSE=false RSPEC_RERUN_MARKER=#{@filename} RSPEC_RERUN_PATTERN=spec-runs/succeeds_spec.rb rake rspec-rerun:spec`.should_not include('rspec')
64
+ end
65
+ end
66
+ end
67
+
68
+ context 'tag execution' do
69
+ it 'does not scope by tag by default' do
70
+ `cd #{root} && RSPEC_RERUN_MARKER=#{@filename} RSPEC_RERUN_PATTERN=spec-runs/succeeds_spec.rb rake rspec-rerun:spec`.should_not include('--tag')
71
+ end
72
+
73
+ context 'when the RSPEC_RERUN_TAG flag is set' do
74
+ it 'scopes rspec to the tag' do
75
+ `cd #{root} && RSPEC_RERUN_TAG=test RSPEC_RERUN_MARKER=#{@filename} RSPEC_RERUN_PATTERN=spec-runs/succeeds_spec.rb rake rspec-rerun:spec`.should include('--tag test')
76
+ end
77
+ end
78
+ end
79
+
56
80
  context 'preserving .rspec' do
57
81
  let(:dot_rspec) { "#{root}/.rspec" }
58
82
  let(:home_rspec) { File.expand_path('~/.rspec') }
@@ -77,6 +101,12 @@ describe 'RakeTask' do
77
101
  run.should include '--format progress'
78
102
  end
79
103
 
104
+ it 'only uses the formatter specified by the .rspec file' do
105
+ File.write(dot_rspec, '--format documentation')
106
+ run.should include '--format documentation'
107
+ run.should_not include '--format progress'
108
+ end
109
+
80
110
  it 'also uses given formatter' do
81
111
  File.write(dot_rspec, "--color\n--format documentation")
82
112
  run.should include '--format documentation'
@@ -11,3 +11,11 @@ require 'tmpdir'
11
11
  require file
12
12
  end
13
13
  end
14
+
15
+ if RSpec::Rerun.rspec3?
16
+ RSpec.configure do |config|
17
+ config.expect_with :rspec do |c|
18
+ c.syntax = [:should, :expect]
19
+ end
20
+ end
21
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-rerun
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.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: 2014-08-18 00:00:00.000000000 Z
11
+ date: 2015-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -16,20 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '>='
18
18
  - !ruby/object:Gem::Version
19
- version: 2.11.0
20
- - - <
21
- - !ruby/object:Gem::Version
22
- version: '3'
19
+ version: '0'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - '>='
28
25
  - !ruby/object:Gem::Version
29
- version: 2.11.0
30
- - - <
31
- - !ruby/object:Gem::Version
32
- version: '3'
26
+ version: '0'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: rake
35
29
  requirement: !ruby/object:Gem::Requirement
@@ -89,6 +83,7 @@ files:
89
83
  - Rakefile
90
84
  - lib/rspec-rerun.rb
91
85
  - lib/rspec-rerun/formatters/failures_formatter.rb
86
+ - lib/rspec-rerun/rspec.rb
92
87
  - lib/rspec-rerun/version.rb
93
88
  - lib/tasks/rspec.rake
94
89
  - rspec-rerun.gemspec
@@ -122,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
117
  version: '0'
123
118
  requirements: []
124
119
  rubyforge_project:
125
- rubygems_version: 2.0.14
120
+ rubygems_version: 2.4.5
126
121
  signing_key:
127
122
  specification_version: 4
128
123
  summary: Re-run failed RSpec tests.