rspec-retry 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rspec-retry.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,5 @@
1
+ guard 'rspec', :version => 2, :cli => '-c -f d' do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Yusuke Mito
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # RSpec::Retry
2
+
3
+ RSpec::Retry adds ``:retry`` option to rspec example.
4
+ It is for randomly failing example.
5
+ If example has ``:retry``, rspec retry specified times until success.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'rspec-retry'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install rspec-retry
20
+
21
+ require in ``spec_helper.rb``
22
+
23
+ ```ruby
24
+ # spec/spec_helper.rb
25
+ require 'rspec/retry'
26
+
27
+ RSpec.configure do |config|
28
+ config.verbose_retry = true # show retry status in spec process
29
+ end
30
+ ```
31
+
32
+ ## Usage
33
+
34
+ ```ruby
35
+ it 'should randomly success', :retry => 3 do
36
+ rand(2).should == 1
37
+ end
38
+
39
+ # run spec (following log is shown if verbose_retry options is true)
40
+ # RSpec::Retry: 2nd try ./spec/lib/random_spec.rb:49
41
+ # RSpec::Retry: 3rd try ./spec/lib/random_spec.rb:49
42
+ ```
43
+
44
+ ## Contributing
45
+
46
+ 1. Fork it
47
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
48
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
49
+ 4. Push to the branch (`git push origin my-new-feature`)
50
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,42 @@
1
+ require 'rspec/retry/version'
2
+ require 'rspec_ext/rspec_ext'
3
+
4
+ module RSpec
5
+ class Retry
6
+ def self.apply
7
+ RSpec.configure do |config|
8
+ config.add_setting :verbose_retry, :default => false
9
+ config.around(:each) do |example|
10
+ retry_count = example.metadata[:retry] || 1
11
+ retry_count.times do |i|
12
+ if RSpec.configuration.verbose_retry?
13
+ if i > 0
14
+ puts if i == 1
15
+ puts "RSpec::Retry: #{RSpec::Retry.ordinalize(i + 1)} try #{@example.location}"
16
+ end
17
+ end
18
+ @example.clear_exception
19
+ example.run
20
+ break if @example.exception.nil?
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ # borrowed from ActiveSupport::Inflector
27
+ def self.ordinalize(number)
28
+ if (11..13).include?(number.to_i % 100)
29
+ "#{number}th"
30
+ else
31
+ case number.to_i % 10
32
+ when 1; "#{number}st"
33
+ when 2; "#{number}nd"
34
+ when 3; "#{number}rd"
35
+ else "#{number}th"
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ RSpec::Retry.apply
@@ -0,0 +1,5 @@
1
+ module RSpec
2
+ class Retry
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ module RSpec
2
+ module Core
3
+ class Example
4
+ def clear_exception
5
+ @exception = nil
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/rspec/retry/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Yusuke Mito"]
6
+ gem.email = ["y310.1984@gmail.com"]
7
+ gem.description = %q{retry randomly failing example}
8
+ gem.summary = %q{retry randomly failing example}
9
+ gem.homepage = "http://github.com/y310/rspec-retry"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "rspec-retry"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = RSpec::Retry::VERSION
17
+ gem.add_runtime_dependency %{rspec}
18
+ gem.add_development_dependency %q{guard-rspec}
19
+ gem.add_development_dependency %q{pry-debugger}
20
+ end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe RSpec::Retry do
4
+ def count
5
+ @count ||= 0
6
+ @count
7
+ end
8
+
9
+ def count_up
10
+ @count ||= 0
11
+ @count += 1
12
+ end
13
+
14
+ def set_expectations(expectations)
15
+ @expectations = expectations
16
+ end
17
+
18
+ def shift_expectation
19
+ @expectations.shift
20
+ end
21
+
22
+ context 'no retry option' do
23
+ it 'should work' do
24
+ true.should be_true
25
+ end
26
+ end
27
+
28
+ context 'with retry option' do
29
+ before(:each) { count_up }
30
+
31
+ context do
32
+ before(:all) { set_expectations([false, false, true]) }
33
+
34
+ it 'should run example until :retry times', :retry => 3 do
35
+ true.should == shift_expectation
36
+ count.should == 3
37
+ end
38
+ end
39
+
40
+ context do
41
+ before(:all) { set_expectations([false, true, false]) }
42
+
43
+ it 'should stop retrying if example is succeeded', :retry => 3 do
44
+ true.should == shift_expectation
45
+ count.should == 2
46
+ end
47
+ end
48
+
49
+ it 'should success randomly', :retry => 3 do
50
+ rand(3).should == 1
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,7 @@
1
+ require 'rspec'
2
+ require 'rspec/retry'
3
+ require 'pry-debugger'
4
+
5
+ RSpec.configure do |config|
6
+ config.verbose_retry = true
7
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec-retry
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Yusuke Mito
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &70312547608000 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70312547608000
25
+ - !ruby/object:Gem::Dependency
26
+ name: guard-rspec
27
+ requirement: &70312547607540 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70312547607540
36
+ - !ruby/object:Gem::Dependency
37
+ name: pry-debugger
38
+ requirement: &70312547607120 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70312547607120
47
+ description: retry randomly failing example
48
+ email:
49
+ - y310.1984@gmail.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - Guardfile
57
+ - LICENSE
58
+ - README.md
59
+ - Rakefile
60
+ - lib/rspec/retry.rb
61
+ - lib/rspec/retry/version.rb
62
+ - lib/rspec_ext/rspec_ext.rb
63
+ - rspec-retry.gemspec
64
+ - spec/lib/rspec/retry_spec.rb
65
+ - spec/spec_helper.rb
66
+ homepage: http://github.com/y310/rspec-retry
67
+ licenses: []
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 1.8.15
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: retry randomly failing example
90
+ test_files:
91
+ - spec/lib/rspec/retry_spec.rb
92
+ - spec/spec_helper.rb