rspec-repeat 1.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5f07fba04acb88fd2eaf370bfe12147ffb64a5c1
4
+ data.tar.gz: f8dacce2acc34b8b8114c518077e3203e4fb0579
5
+ SHA512:
6
+ metadata.gz: 0d69bb0efe449044f7aeb62936d289f0eec33a2cac8570484eb48483bfdc2610175310e9dd3badd5edcedb57feaea3544b6b0be80db492b11b2e868ae1e59339
7
+ data.tar.gz: 977fb7e8a6478b352040277329a3397c3ea16b5a05887aebdf274822f778f00cfbc0b1dbd6e4028ce2d4c86b3fbc604b905b18097d892efaf385570221e22c04
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/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.6
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rspec-retry-alt.gemspec
4
+ gemspec
data/HISTORY.md ADDED
@@ -0,0 +1,4 @@
1
+ # v1.0.1
2
+ > Sep 25, 2015
3
+
4
+ - Initial release.
data/README.md ADDED
@@ -0,0 +1,75 @@
1
+ # Rspec::Repeat
2
+
3
+ Repeats an RSpec example until it succeeds.
4
+
5
+ ```rb
6
+ describe 'a stubborn test' do
7
+ include Rspec::Repeat
8
+
9
+ around do |example|
10
+ repeat example, 3.times
11
+ end
12
+
13
+ it 'works' do
14
+ expect(rand(2)).to eq 0
15
+ end
16
+ end
17
+ ```
18
+
19
+ [![Status](https://travis-ci.org/rstacruz/rspec-repeat.svg?branch=master)](https://travis-ci.org/rstacruz/rspec-repeat "See test builds")
20
+
21
+ <br>
22
+
23
+ ## Advanced usage
24
+
25
+ ### Attaching to tags
26
+
27
+ This will allow you to repeat any example thrice by tagging it.
28
+
29
+ ```rb
30
+ # rails_helper.rb or spec_helper.rb
31
+ RSpec.configure do
32
+ config.around :each, :foobar do |example|
33
+ repeat example, 3.times
34
+ end
35
+ end
36
+ ```
37
+
38
+ ```rb
39
+ describe 'stubborn tests', :foobar do
40
+ # ...
41
+ end
42
+ ```
43
+
44
+ ### Attaching to features
45
+
46
+ This will make all `spec/features/` retry thrice. Perfect for stubborn Poltergeist/Selenium tests.
47
+
48
+ ```rb
49
+ # rails_helper.rb or spec_helper.rb
50
+ RSpec.configure do
51
+ config.around :each, type: :feature do
52
+ repeat example, 3.times
53
+ end
54
+ end
55
+ ```
56
+
57
+ <br>
58
+
59
+ ## Acknowledgement
60
+
61
+ Much of this code has been refactored out of [rspec-retry](https://github.com/NoRedInk/rspec-retry) by [@NoRedInk](https://github.com/NoRedInk).
62
+
63
+ <br>
64
+
65
+ ## Thanks
66
+
67
+ **rspec-repeat** © 2015+, Rico Sta. Cruz. Released under the [MIT] License.<br>
68
+ Authored and maintained by Rico Sta. Cruz with help from contributors ([list][contributors]).
69
+
70
+ > [ricostacruz.com](http://ricostacruz.com) &nbsp;&middot;&nbsp;
71
+ > GitHub [@rstacruz](https://github.com/rstacruz) &nbsp;&middot;&nbsp;
72
+ > Twitter [@rstacruz](https://twitter.com/rstacruz)
73
+
74
+ [MIT]: http://mit-license.org/
75
+ [contributors]: http://github.com/rstacruz/rspec-repeat/contributors
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,103 @@
1
+ require 'rspec/repeat/version'
2
+
3
+ module RSpec
4
+ # Allows you to repeat RSpec examples.
5
+ module Repeat
6
+ # Retries an example.
7
+ #
8
+ # include Rspec::Repeat
9
+ #
10
+ # around do |example|
11
+ # repeat example, 3
12
+ # end
13
+ #
14
+ # Available options:
15
+ #
16
+ # - `wait` - seconds to wait between each retry
17
+ # - `verbose` - print messages if true
18
+ # - `exceptions` - if given, only retry exceptions from this list
19
+ # - `clear_let` - when false, don't clear `let`'s
20
+ #
21
+ def repeat(ex, count, options = {})
22
+ Repeater.new(count, options).run(ex, self)
23
+ end
24
+
25
+ # Much of this code is borrowed from:
26
+ # https://github.com/NoRedInk/rspec-retry/blob/master/lib/rspec/retry.rb
27
+ class Repeater
28
+ attr_accessor :count, :wait, :exceptions, :verbose, :clear_let
29
+
30
+ def initialize(count, options = {})
31
+ options.each do |key, val|
32
+ send :"#{key}=", val
33
+ end
34
+
35
+ self.count = count
36
+ self.count = count.times if count.is_a?(Numeric)
37
+ self.verbose = ENV['RSPEC_RETRY_VERBOSE'] if verbose.nil?
38
+ self.clear_let = true if clear_let.nil?
39
+ end
40
+
41
+ def run(ex, ctx)
42
+ example = current_example(ctx)
43
+
44
+ count.each do |i|
45
+ example.instance_variable_set :@exception, nil
46
+ ex.run
47
+ break if example.exception.nil?
48
+ break if matches_exceptions?(exceptions, example.exception)
49
+ print_failure(i, example) if verbose
50
+ clear_memoize(ctx) if clear_let
51
+ sleep wait if wait.to_i > 0
52
+ end
53
+ end
54
+
55
+ # Returns the current example being ran by RSpec
56
+ def current_example(ctx)
57
+ if RSpec.respond_to?(:current_example)
58
+ RSpec.current_example
59
+ else
60
+ ctx.example
61
+ end
62
+ end
63
+
64
+ # Clears memoized stuff out of an ExampleGroup to clear out the `let`s
65
+ def clear_memoize(ctx)
66
+ if ctx.respond_to?(:__init_memoized, true)
67
+ ctx.send :__init_memoized
68
+ else
69
+ ctx.instance_variable_set :@__memoized, nil
70
+ end
71
+ end
72
+
73
+ # Checks if `exception` is in `exceptions`
74
+ def matches_exceptions?(exceptions, exception)
75
+ return unless exceptions
76
+ exceptions.any? do |exception_klass|
77
+ exception.is_a?(exception_klass)
78
+ end
79
+ end
80
+
81
+ def print_failure(i, example)
82
+ msg =
83
+ "RSpec::Repeat: #{nth(i + 1)} try error in #{example.location}:\n" \
84
+ " #{example.exception}\n"
85
+ RSpec.configuration.reporter.message(msg)
86
+ end
87
+
88
+ # borrowed from ActiveSupport::Inflector
89
+ def nth(number)
90
+ if (11..13).include?(number.to_i % 100)
91
+ "#{number}th"
92
+ else
93
+ case number.to_i % 10
94
+ when 1 then "#{number}st"
95
+ when 2 then "#{number}nd"
96
+ when 3 then "#{number}rd"
97
+ else "#{number}th"
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,5 @@
1
+ module RSpec
2
+ module Repeat
3
+ VERSION = "1.0.1"
4
+ end
5
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rspec/repeat/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'rspec-repeat'
8
+ spec.version = RSpec::Repeat::VERSION
9
+ spec.authors = ['Rico Sta. Cruz']
10
+ spec.email = ['rico@ricostacruz.com']
11
+
12
+ spec.summary = %q(Retry an RSpec test until it succeeds)
13
+ spec.description = %q(Retry an RSpec test until it succeeds)
14
+ spec.homepage = 'https://github.com/rstacruz/rspec-repeat'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files`.split("\n").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1.10'
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
+ spec.add_dependency 'rspec', '~> 3.0'
25
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec-repeat
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Rico Sta. Cruz
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-09-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: Retry an RSpec test until it succeeds
56
+ email:
57
+ - rico@ricostacruz.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".travis.yml"
64
+ - Gemfile
65
+ - HISTORY.md
66
+ - README.md
67
+ - Rakefile
68
+ - lib/rspec/repeat.rb
69
+ - lib/rspec/repeat/version.rb
70
+ - rspec-repeat.gemspec
71
+ homepage: https://github.com/rstacruz/rspec-repeat
72
+ licenses:
73
+ - MIT
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.2.3
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: Retry an RSpec test until it succeeds
95
+ test_files: []