rspec-versioned 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +51 -0
- data/Rakefile +2 -0
- data/lib/rspec/versioned/version.rb +5 -0
- data/lib/rspec/versioned.rb +103 -0
- data/rspec-versioned.gemspec +24 -0
- data/spec/spec_helper.rb +8 -0
- data/spec/versioned_spec.rb +74 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MTYxOGQ0MTBmOTVlZjNjYmI5NzU5MDc0YWEwNDcyODg1YThkNDVmMQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MTMwNzYzNmJlY2EwYjZmOTZiZThhMzA1YmRkOGFiYzhiZjYwZGU3ZA==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
YTg3YzkyMmFiNjFkZTI4MmJlZGVjOGRlNDhhMGUyOTNiMmQ2NDAzY2I5NGJi
|
10
|
+
MTFhMDgwOWU2ODVjNGM5OGY0NDQ0ZThlMGFiYzBmZTczZGE2YTlmNTQzZDg0
|
11
|
+
ZGU4OGMwYzdjNGMwNmVmY2JjZGYyMWQ0ZjFjOGFiMzVjMjU4ZTI=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YWQzMTdhNjBlMzk2NWZhNTBlZWFkZGEyZWNmMDEyYjMyNGFjYjA4MzFmZjQy
|
14
|
+
MTNmM2FjOTZlZjNjNjgwZjZhM2Q5MTNmYTY1MTY1MWZhMmU3MTEyMzljZDg5
|
15
|
+
NzllNjYxMjU0ODI4NTI5ZGRmMDcxNWQzMGYwMDRlZGZhMjE5NmQ=
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
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
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 ddayal-fiksu
|
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,51 @@
|
|
1
|
+
# RSpec::Versioned
|
2
|
+
|
3
|
+
Inspired by [RSpec::Retry](https://github.com/y310/rspec-retry), Rspec::Versioned allows RSpec examples and example groups to easily be repeated over different API versions using the [versioned_blocks](https://github.com/devend711/versioned_blocks) gem. Just add the `:versions` option to an example:
|
4
|
+
|
5
|
+
it 'tests multiple API versions', versions:{from:2, to:4} do |example|
|
6
|
+
expect(example.version.uri).to include example.version.number.to_s
|
7
|
+
end
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
gem 'rspec-versioned'
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install rspec-versioned
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
See [versioned_blocks' documentation](https://github.com/devend711/versioned_blocks) for info about how to set a base URI and define ranges for the versions you want to test. Simply pass those options to an RSpec example group or a specific example, like this:
|
26
|
+
|
27
|
+
VersionedBlocks.base_uri = 'http://www.api.com'
|
28
|
+
|
29
|
+
it 'tests multiple API versions', versions:{to:3} do |example|
|
30
|
+
...
|
31
|
+
|
32
|
+
context 'when the API version is between 2 and 4', versions:{from:2, to:4} do
|
33
|
+
it 'tests multiple API versions' do |example|
|
34
|
+
...
|
35
|
+
|
36
|
+
it 'tests a different base URI', versions:{only:1, base_uri:'http://www.api2.com', override:true} do |example|
|
37
|
+
...
|
38
|
+
|
39
|
+
Examples returned from the block will respond to `version.number` and a `version.uri` where `version.uri` will be the string `"#{VersionedBlocks.base_uri}/v#{version.number}"`
|
40
|
+
|
41
|
+
Rspec::Versioned can add the version it's currently testing to RSpec's output messages. Just add this line to your RSpec config:
|
42
|
+
|
43
|
+
config.notify_version_number = true
|
44
|
+
|
45
|
+
## Contributing
|
46
|
+
|
47
|
+
1. Fork it ( https://github.com/[my-github-username]/rspec-versioned/fork )
|
48
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
49
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
50
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
51
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
require "rspec/versioned/version"
|
2
|
+
require 'rspec/core'
|
3
|
+
require 'rspec_ext/rspec_ext'
|
4
|
+
require 'versioned_blocks'
|
5
|
+
|
6
|
+
module RSpec
|
7
|
+
class Versioned
|
8
|
+
def self.apply
|
9
|
+
RSpec.configure do |config|
|
10
|
+
config.add_setting :notify_version_number, :default => false
|
11
|
+
config.add_setting :clear_lets_on_failure, :default => true
|
12
|
+
|
13
|
+
fetch_current_example = RSpec.respond_to?(:current_example) ?
|
14
|
+
proc { RSpec.current_example } : proc { |context| context.example }
|
15
|
+
|
16
|
+
config.around(:each) do |ex| # ex is a Procsy
|
17
|
+
notify_version_number = ex.metadata[:notify_version_number] || RSpec.configuration.notify_version_number
|
18
|
+
|
19
|
+
example = fetch_current_example.call(self)
|
20
|
+
example.new_version_info
|
21
|
+
|
22
|
+
run_example = Proc.new do |v, uri|
|
23
|
+
example.clear_exception
|
24
|
+
example.version.set(v, uri)
|
25
|
+
ex.run
|
26
|
+
RSpec.configuration.reporter.message("RSpec::Versioned testing /v#{v}") if notify_version_number
|
27
|
+
end
|
28
|
+
|
29
|
+
if ex.metadata.has_key?(:versions)
|
30
|
+
if ex.metadata[:versions][:base_uri] || (VersionedBlocks.base_uri && VersionedBlocks.base_uri!='') # we have a URI
|
31
|
+
versioned_block(ex.metadata[:versions]) do |v, uri|
|
32
|
+
run_example.call v,uri
|
33
|
+
end
|
34
|
+
else # we don't have a URI
|
35
|
+
versioned_block(ex.metadata[:versions]) do |v|
|
36
|
+
run_example.call v
|
37
|
+
end
|
38
|
+
end
|
39
|
+
else # didn't specify any versions...just run the test!
|
40
|
+
ex.run
|
41
|
+
end
|
42
|
+
self.clear_lets if clear_lets
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
module HasVersionInfo
|
50
|
+
def new_version_info
|
51
|
+
@version_info = VersionInfoHolder.new
|
52
|
+
end
|
53
|
+
|
54
|
+
def version
|
55
|
+
@version_info
|
56
|
+
end
|
57
|
+
|
58
|
+
def clear_exception
|
59
|
+
@exception = nil
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
module RSpec
|
64
|
+
module Core
|
65
|
+
class Example
|
66
|
+
@version_info
|
67
|
+
|
68
|
+
include HasVersionInfo
|
69
|
+
|
70
|
+
class Procsy
|
71
|
+
@version_info
|
72
|
+
|
73
|
+
include HasVersionInfo
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
class VersionInfoHolder
|
80
|
+
attr_reader :number
|
81
|
+
|
82
|
+
def uri
|
83
|
+
return @uri if !@uri.nil?
|
84
|
+
raise VersionedBlocksException, "Undefined URI!"
|
85
|
+
end
|
86
|
+
|
87
|
+
def set(v_number, uri=nil)
|
88
|
+
@number = v_number
|
89
|
+
@uri = uri
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
module RSpec
|
94
|
+
module Core
|
95
|
+
class ExampleGroup
|
96
|
+
def clear_lets
|
97
|
+
@__memoized = {}
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
RSpec::Versioned.apply
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rspec/versioned/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rspec-versioned"
|
8
|
+
spec.version = Rspec::Versioned::VERSION
|
9
|
+
spec.authors = ["devend711"]
|
10
|
+
spec.email = ["devend711@gmail.com"]
|
11
|
+
spec.summary = "Run tests over whatever API versions you want"
|
12
|
+
#spec.description = %q{TODO: Write a longer description. Optional.}
|
13
|
+
spec.homepage = "https://github.com/devend711/rspec-versioned"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "versioned_blocks"
|
24
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'rspec/versioned' do
|
4
|
+
it 'can run a normal example' do
|
5
|
+
expect(1).to eq 1
|
6
|
+
end
|
7
|
+
|
8
|
+
context 'without asking for URI' do
|
9
|
+
before :all do
|
10
|
+
@count = 1
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'can run an example and get a version number', versions:{only:1} do |ex|
|
14
|
+
expect(ex.version.number).to eq 1
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'can run an example and get version numbers for a range of versions', versions:{to:3} do |ex|
|
18
|
+
expect(ex.version.number).to eq(@count)
|
19
|
+
@count += 1
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'after setting a URI' do
|
24
|
+
before :all do
|
25
|
+
@count = 1
|
26
|
+
VersionedBlocks.base_uri = "http://api.com"
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'can run an example and get a version number', versions:{only:1} do |ex|
|
30
|
+
expect(ex.version.uri).to include ex.version.number.to_s
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'can override base_uri', versions:{only:1, base_uri:'http://api2.com', override:true} do |ex|
|
34
|
+
expect(ex.version.uri).to include 'http://api2.com'
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'can run an example and get version numbers and URIs for a range of versions', versions:{to:3} do |ex|
|
38
|
+
expect(ex.version.uri).to include('api.com')
|
39
|
+
expect(ex.version.uri).to include(ex.version.number.to_s)
|
40
|
+
expect(ex.version.number).to eq(@count)
|
41
|
+
@count += 1
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'nested examples' do
|
46
|
+
before :all do
|
47
|
+
@outer_count = 1
|
48
|
+
@always_1 = 1
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'nested', versions:{from:2, to:4} do
|
52
|
+
it 'runs the correct amount of times' do |ex|
|
53
|
+
@outer_count += 1
|
54
|
+
expect(@outer_count).to eq ex.version.number
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'only runs once for this one', versions:{only:1} do
|
58
|
+
expect(@always_1).to eq 1
|
59
|
+
@always_1 += 1
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'another nested' do
|
63
|
+
before :all do
|
64
|
+
@inner_count = 1
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'runs the correct amount of times' do |ex|
|
68
|
+
@inner_count += 1
|
69
|
+
expect(@inner_count).to eq ex.version.number
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec-versioned
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- devend711
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-10 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.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: versioned_blocks
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- devend711@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- lib/rspec/versioned.rb
|
68
|
+
- lib/rspec/versioned/version.rb
|
69
|
+
- rspec-versioned.gemspec
|
70
|
+
- spec/spec_helper.rb
|
71
|
+
- spec/versioned_spec.rb
|
72
|
+
homepage: https://github.com/devend711/rspec-versioned
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ! '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.2.2
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: Run tests over whatever API versions you want
|
96
|
+
test_files:
|
97
|
+
- spec/spec_helper.rb
|
98
|
+
- spec/versioned_spec.rb
|