redcard 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ .rbx
2
+ Gemfile.lock
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ script: RUBYLIB=lib bundle exec rspec
3
+ rvm:
4
+ - 1.8.7
5
+ - 1.9.2
6
+ - 1.9.3
7
+ - 2.0.0
8
+ - rbx-nightly-18mode
9
+ - rbx-nightly-19mode
10
+ - jruby-18mode
11
+ - jruby-19mode
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify gem dependencies in redcard.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Brian Ford. All rights reserved.
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,73 @@
1
+ # RedCard
2
+
3
+ RedCard provides a standard way to ensure that the running Ruby implementation
4
+ matches the desired language version, implementation, and implementation
5
+ version.
6
+
7
+
8
+ ## Why Do We Need It?
9
+
10
+ Once upon a time, Ruby was a very simple universe. There was a single Ruby
11
+ implementation and a single stable version. Now there are multiple current
12
+ language versions, multiple implementations, and numerous versions of those
13
+ multiple implementations.
14
+
15
+ In an ideal world, every Ruby implementation would provide the same features
16
+ and all such features would have consistent behavior. In the real world, this
17
+ is not the case. Hence, the need arises to have some facility for restricting
18
+ the conditions under which an application or library runs. RedCard provides
19
+ various mechanisms for specifying what language version, implementation, and
20
+ implementation version are required.
21
+
22
+
23
+ NOTE: In this documentation, Ruby version specifies the version of the Ruby
24
+ programming language itself. Historically, the word "Ruby" could have applied
25
+ to the language or the original implementation of the language. We refer to
26
+ the original implementation as MRI or Matz's Ruby Implementation. RedCard
27
+ distinguishes between Ruby language versions, Ruby implementations, and
28
+ implementation versions.
29
+
30
+
31
+ ## Be Liberal
32
+
33
+ RedCard provides an API for specifying multiple implementations and versions.
34
+
35
+ RedCard.check *requirements
36
+
37
+ The parameter, requirements, is an Array of Symbols or Strings with an
38
+ optional final Hash of implementations as keys and implementation versions as
39
+ values.
40
+
41
+ The following examples illustrate this:
42
+
43
+ # Requires any version JRuby or Rubinius
44
+ RedCard.check :rubinius, :jruby
45
+
46
+ # Requires Ruby language 1.9 and MRI or Rubinius
47
+ RedCard.check :mri, :rubinius, "1.9"
48
+
49
+ # Requires Ruby language 1.9.3 or 2.0
50
+ RedCard.check "1.9.3", "2.0"
51
+
52
+ # Requires Ruby language 1.9 and Rubinius version 2.0
53
+ RedCard.check "1.9", :rubinius => "2.0"
54
+
55
+
56
+ ## Be Conservative
57
+
58
+ RedCard provides some convenience files that define restrictive requirements.
59
+ Using these, you can easily restrict the application to a single language
60
+ version, implementation, and implementation version.
61
+
62
+ The following examples illustrate this:
63
+
64
+ # Requires at minimum Ruby version 1.9 but accepts anything greater
65
+ require 'redcard/1.9'
66
+
67
+ # Requires Rubinius 2.0
68
+ require 'redcard/rubinius/2.0'
69
+
70
+ # Requires Ruby 1.9 and Rubinius
71
+ require 'redcard/1.9'
72
+ require 'redcard/rubinius'
73
+
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'bundler/setup'
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
@@ -0,0 +1,3 @@
1
+ require 'redcard'
2
+
3
+ RedCard.verify "1.8"
@@ -0,0 +1,3 @@
1
+ require 'redcard'
2
+
3
+ RedCard.verify "1.9"
@@ -0,0 +1,3 @@
1
+ require 'redcard'
2
+
3
+ RedCard.verify "2.0"
@@ -0,0 +1,17 @@
1
+ class RedCard
2
+ class Engine
3
+ def initialize(engine, candidate)
4
+ @engine = engine.to_s
5
+ @candidate = candidate.to_s
6
+ end
7
+
8
+ def valid?
9
+ case @engine
10
+ when "rbx"
11
+ @candidate == "rbx" or @candidate == "rubinius"
12
+ else
13
+ @candidate == @engine
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ require 'redcard'
2
+
3
+ RedCard.verify :ironruby
@@ -0,0 +1,3 @@
1
+ require 'redcard'
2
+
3
+ RedCard.verify :jruby => "1.7"
@@ -0,0 +1,3 @@
1
+ require 'redcard'
2
+
3
+ RedCard.verify :jruby
@@ -0,0 +1,3 @@
1
+ require 'redcard'
2
+
3
+ RedCard.verify :maglev
@@ -0,0 +1,3 @@
1
+ require 'redcard'
2
+
3
+ RedCard.verify :rubinius => "2.0"
@@ -0,0 +1,3 @@
1
+ require 'redcard'
2
+
3
+ RedCard.verify :rubinius
@@ -0,0 +1,3 @@
1
+ require 'redcard'
2
+
3
+ RedCard.verify :topaz
@@ -0,0 +1,41 @@
1
+ class RedCard
2
+ VERSION = "1.0.0"
3
+
4
+ class Version
5
+ def initialize(version, candidate)
6
+ @version_spec = version.to_str
7
+ @version = convert @version_spec
8
+
9
+ case candidate
10
+ when Range
11
+ @minimum_spec = candidate.begin.to_str
12
+ @maximum_spec = candidate.end.to_str
13
+ @exclusive = candidate.exclude_end?
14
+
15
+ @minimum = convert @minimum_spec
16
+ @maximum = convert @maximum_spec
17
+ else
18
+ @minimum = convert candidate.to_str
19
+ @maximum = nil
20
+ @exclusive = nil
21
+ end
22
+ end
23
+
24
+ def valid?
25
+ return false unless @version >= @minimum
26
+ return true if @maximum.nil?
27
+
28
+ if @exclusive
29
+ return @version < @maximum
30
+ else
31
+ return @version <= @maximum
32
+ end
33
+ end
34
+
35
+ def convert(string)
36
+ major, minor, tiny, patch = string.split "."
37
+ parts = [major, minor, tiny, patch].map { |x| x.to_i }
38
+ ("1%03d%03d%03d%05d" % parts).to_i
39
+ end
40
+ end
41
+ end
data/lib/redcard.rb ADDED
@@ -0,0 +1,100 @@
1
+ require 'redcard/version'
2
+ require 'redcard/engine'
3
+
4
+ class RedCard
5
+ class InvalidRubyVersionError < Exception; end
6
+ class InvalidRubyEngineError < Exception; end
7
+ class UnknownRubyEngineError < Exception; end
8
+ class InvalidRubyError < Exception; end
9
+
10
+ def self.check(*requirements)
11
+ new(*requirements).check
12
+ end
13
+
14
+ def self.verify(*requirements)
15
+ card = new(*requirements)
16
+ unless card.check
17
+ raise card.error, card.message
18
+ end
19
+ end
20
+
21
+ def self.engine
22
+ (defined?(RUBY_ENGINE) && RUBY_ENGINE) || "ruby"
23
+ end
24
+
25
+ def self.engine_version
26
+ case engine
27
+ # when "ironruby"
28
+ # TODO
29
+ when "jruby"
30
+ Object.const_get :JRUBY_VERSION
31
+ # when "maglev"
32
+ # TODO
33
+ when "rbx"
34
+ if defined?(::Rubinius)
35
+ Object.const_get(:Rubinius).const_get(:VERSION)
36
+ end
37
+ when "ruby"
38
+ RUBY_VERSION
39
+ when "topaz"
40
+ if defined?(::Topaz)
41
+ Object.const_get(:Topaz).const_get(:VERSION)
42
+ end
43
+ else
44
+ raise UnknownRubyEngineError, "#{engine} is not recognized"
45
+ end
46
+ end
47
+
48
+
49
+ attr_reader :error, :message
50
+
51
+ def initialize(*requirements)
52
+ @engine_versions = requirements.last.kind_of?(Hash) ? requirements.pop.to_a : []
53
+ @engines = requirements.select { |x| x.kind_of? Symbol }
54
+ @versions = requirements.select { |x| x.kind_of? String or x.kind_of? Range }
55
+ end
56
+
57
+ def check
58
+ unless @engines.empty? or
59
+ @engines.any? { |x| Engine.new(RedCard.engine, x).valid? }
60
+ invalid_engine
61
+ return false
62
+ end
63
+
64
+ unless @versions.empty? or
65
+ @versions.any? { |x| Version.new(RUBY_VERSION, x).valid? }
66
+ invalid_ruby_version
67
+ return false
68
+ end
69
+
70
+ return true if @engine_versions.empty?
71
+
72
+ @engine_versions.map! do |e, v|
73
+ [Engine.new(RedCard.engine, e), Version.new(RedCard.engine_version, v)]
74
+ end
75
+
76
+ return true if @engine_versions.any? do |engine, version|
77
+ engine.valid? and version.valid?
78
+ end
79
+
80
+ invalid_engine_version
81
+ return false
82
+ end
83
+
84
+ private
85
+
86
+ def invalid_ruby_version
87
+ @error = InvalidRubyVersionError
88
+ @message = "#{RUBY_VERSION} is not supported"
89
+ end
90
+
91
+ def invalid_engine
92
+ @error = InvalidRubyEngineError
93
+ @message = "#{RedCard.engine} is not supported"
94
+ end
95
+
96
+ def invalid_engine_version
97
+ @error = InvalidRubyError
98
+ @message = "#{RedCard.engine} version #{RedCard.engine_version} is not supported"
99
+ end
100
+ end
data/redcard.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'redcard/version'
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = "redcard"
6
+ gem.version = "#{RedCard::VERSION}"
7
+ gem.authors = ["Brian Shirai"]
8
+ gem.email = ["brixen@gmail.com"]
9
+ gem.homepage = "https://github.com/brixen/redcard"
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) unless File.extname(f) == ".bat" }.compact
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.require_paths = ["lib"]
15
+ gem.summary = <<-EOS
16
+ RedCard provides a standard way to ensure that the running Ruby implementation
17
+ matches the desired language version, implementation, and implementation
18
+ version.
19
+ EOS
20
+ gem.has_rdoc = true
21
+ gem.extra_rdoc_files = %w[ README.md LICENSE ]
22
+ gem.rubygems_version = %q{1.3.5}
23
+ gem.rubyforge_project = 'http://rubyforge.org/projects/mspec'
24
+
25
+ gem.rdoc_options << '--title' << 'MSpec Gem' <<
26
+ '--main' << 'README' <<
27
+ '--line-numbers'
28
+
29
+ gem.add_development_dependency "rake", "~> 0.9"
30
+ gem.add_development_dependency "rspec", "~> 2.8"
31
+ end
32
+
data/spec/1.9_spec.rb ADDED
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Ruby version requirement" do
4
+ before do
5
+ redcard_save_state
6
+ redcard_unload "redcard/1.9"
7
+ end
8
+
9
+ after do
10
+ redcard_restore_state
11
+ end
12
+
13
+ it "succeeds if RUBY_VERSION is 1.9.0" do
14
+ redcard_version "1.9.0"
15
+ expect { require 'redcard/1.9' }.not_to raise_error
16
+ end
17
+
18
+ it "succeeds if RUBY_VERSION is 1.9.9" do
19
+ redcard_version "1.9.9"
20
+ expect { require 'redcard/1.9' }.not_to raise_error
21
+ end
22
+
23
+ it "succeeds if RUBY_VERSION is 1.10.0" do
24
+ redcard_version "1.10.0"
25
+ expect { require 'redcard/1.9' }.not_to raise_error
26
+ end
27
+
28
+ it "succeeds if RUBY_VERSION is 2.0.0" do
29
+ redcard_version "2.0.0"
30
+ expect { require 'redcard/1.9' }.not_to raise_error
31
+ end
32
+
33
+ it "raises an InvalidRubyVersionError if RUBY_VERSION is less than 1.9" do
34
+ redcard_version "1.8.9"
35
+ expect { require 'redcard/1.9' }.to raise_error(RedCard::InvalidRubyVersionError)
36
+ end
37
+ end
@@ -0,0 +1,111 @@
1
+ require 'spec_helper'
2
+
3
+ describe "RedCard.check" do
4
+ before do
5
+ redcard_save_state
6
+ end
7
+
8
+ after do
9
+ redcard_restore_state
10
+ end
11
+
12
+ context "when RUBY_VERSION is '2.10.1'" do
13
+ before do
14
+ redcard_version "2.10.1"
15
+ end
16
+
17
+ it "returns true for '2.0'" do
18
+ expect(RedCard.check("2.0")).to be_true
19
+ end
20
+
21
+ it "returns true for '2.0.0'" do
22
+ expect(RedCard.check("2.0.0")).to be_true
23
+ end
24
+
25
+ it "returns true for '2.9.10'" do
26
+ expect(RedCard.check("2.9.10")).to be_true
27
+ end
28
+
29
+ it "returns true for '2.10.1'" do
30
+ expect(RedCard.check("2.10.1")).to be_true
31
+ end
32
+
33
+ it "returns true for '1.9.100'" do
34
+ expect(RedCard.check("1.9.100")).to be_true
35
+ end
36
+
37
+ it "returns true for '1.8.10'" do
38
+ expect(RedCard.check("1.8.10")).to be_true
39
+ end
40
+
41
+ it "returns false for '2.10.2'" do
42
+ expect(RedCard.check("2.10.2")).to be_false
43
+ end
44
+
45
+ it "returns true for '1.8.10'..'2.10.1'" do
46
+ expect(RedCard.check("1.8.10".."2.10.1")).to be_true
47
+ end
48
+
49
+ it "returns true for '1.8.10'..'2.10.2'" do
50
+ expect(RedCard.check("1.8.10".."2.10.2")).to be_true
51
+ end
52
+
53
+ it "returns true for '1.8.10'..'2.11'" do
54
+ expect(RedCard.check("1.8.10".."2.11")).to be_true
55
+ end
56
+
57
+ it "returns false for '2.10.2'..'2.11.2'" do
58
+ expect(RedCard.check("2.10.2"..."2.11.2")).to be_false
59
+ end
60
+
61
+ it "returns false for '1.8.10'...'2.10.1'" do
62
+ expect(RedCard.check("1.8.10"..."2.10.1")).to be_false
63
+ end
64
+
65
+ context "when RUBY_ENGINE is 'rbx'" do
66
+ before do
67
+ redcard_engine "rbx"
68
+ end
69
+
70
+ it "returns true for '1.9', :rbx" do
71
+ expect(RedCard.check("1.9", :rbx)).to be_true
72
+ end
73
+
74
+ it "returns false for '1.9', :topaz" do
75
+ expect(RedCard.check("1.9", :topaz)).to be_false
76
+ end
77
+
78
+ context "when Rubinius::VERSION is '2.0.0'" do
79
+ before do
80
+ redcard_engine_version "2.0.0"
81
+ end
82
+
83
+ it "returns true for '1.9', :rbx => '2.0'" do
84
+ expect(RedCard.check("1.9", :rbx => "2.0")).to be_true
85
+ end
86
+
87
+ it "returns true for '1.9', :rbx => '1.2.4'" do
88
+ expect(RedCard.check("1.9", :rbx => "1.2.4")).to be_true
89
+ end
90
+
91
+ it "returns false for '1.9', :rbx => '2.1'" do
92
+ expect(RedCard.check("1.9", :rbx => "2.1")).to be_false
93
+ end
94
+ end
95
+ end
96
+ end
97
+
98
+ context "when RUBY_ENGINE is 'rbx'" do
99
+ before do
100
+ redcard_engine "rbx"
101
+ end
102
+
103
+ it "returns true for :rbx" do
104
+ expect(RedCard.check(:rbx)).to be_true
105
+ end
106
+
107
+ it "returns false for :topaz" do
108
+ expect(RedCard.check(:topaz)).to be_false
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Rubinius version requirement" do
4
+ before do
5
+ redcard_save_state
6
+ redcard_unload "redcard/rubinius/2.0"
7
+ end
8
+
9
+ after do
10
+ redcard_restore_state
11
+ end
12
+
13
+ it "succeeds if RUBY_ENGINE is 'rbx' and Rubinius::VERSION is greater than or equal to 2.0" do
14
+ redcard_engine "rbx"
15
+ redcard_engine_version "2.0.0"
16
+ expect { require 'redcard/rubinius/2.0' }.not_to raise_error
17
+ end
18
+
19
+ it "raises an InvalidRubyEngineError if RUBY_ENGINE is 'topaz'" do
20
+ redcard_engine "topaz"
21
+ redcard_engine_version "2.0.0"
22
+ expect { require 'redcard/rubinius/2.0' }.to raise_error(RedCard::InvalidRubyError)
23
+ end
24
+
25
+ it "raises an InvalidEngineVersionError if Rubinius::VERSION is less than 2.0" do
26
+ redcard_engine "rbx"
27
+ redcard_engine_version "1.2.4"
28
+ expect { require 'redcard/rubinius/2.0' }.to raise_error(RedCard::InvalidRubyError)
29
+ end
30
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Ruby engine requirement" do
4
+ before do
5
+ redcard_save_state
6
+ redcard_unload "redcard/rubinius"
7
+ end
8
+
9
+ after do
10
+ redcard_restore_state
11
+ end
12
+
13
+ it "succeeds if RUBY_ENGINE is 'rbx'" do
14
+ redcard_engine "rbx"
15
+ expect { require 'redcard/rubinius' }.not_to raise_error
16
+ end
17
+
18
+ it "raises an InvalidRubyEngineError if RUBY_ENGINE is 'topaz'" do
19
+ redcard_engine "topaz"
20
+ expect { require 'redcard/rubinius' }.to raise_error(RedCard::InvalidRubyEngineError)
21
+ end
22
+ end
@@ -0,0 +1,94 @@
1
+ require 'redcard'
2
+
3
+ RSpec.configure do |config|
4
+ config.expect_with :rspec do |c|
5
+ c.syntax = [:should, :expect]
6
+ end
7
+ end
8
+
9
+ class RedCard
10
+ module Specs
11
+ @verbose = nil
12
+ @ruby_version = nil
13
+ @engine = nil
14
+ @engine_version = nil
15
+
16
+ def self.save_state
17
+ @verbose = $VERBOSE
18
+ $VERBOSE = nil
19
+ @ruby_version = RUBY_VERSION
20
+ @ruby_engine = RedCard.engine
21
+ end
22
+
23
+ def self.save_engine_version
24
+ @engine_version = RedCard.engine_version
25
+ end
26
+
27
+ def self.restore_state
28
+ $VERBOSE = nil
29
+ Object.const_set :RUBY_VERSION, @ruby_version
30
+
31
+ engine_version = @engine_version ? @engine_version : nil
32
+ Object.const_set :RUBY_ENGINE, @ruby_engine
33
+
34
+ $VERBOSE = @verbose
35
+ end
36
+
37
+ def self.version=(version)
38
+ Object.const_set :RUBY_VERSION, version
39
+ end
40
+
41
+ def self.engine=(engine)
42
+ Object.const_set :RUBY_ENGINE, engine
43
+ end
44
+
45
+ def self.engine_version=(version)
46
+ case RedCard.engine
47
+ # when "ironruby"
48
+ # TODO
49
+ when "jruby"
50
+ Object.const_set :JRUBY_VERSION, version
51
+ # when "maglev"
52
+ # TODO
53
+ when "rbx"
54
+ unless defined?(::Rubinius)
55
+ Object.const_set :Rubinius, Module.new
56
+ end
57
+ Object.const_get(:Rubinius).const_set(:VERSION, version)
58
+ when "ruby"
59
+ RUBY_VERSION
60
+ when "topaz"
61
+ unless defined?(::Topaz)
62
+ Object.const_set :Topaz, Module.new
63
+ end
64
+ Object.const_get(:Topaz).const_set(:VERSION, version)
65
+ end
66
+ end
67
+ end
68
+ end
69
+
70
+ def redcard_save_state
71
+ RedCard::Specs.save_state
72
+ end
73
+
74
+ def redcard_restore_state
75
+ RedCard::Specs.restore_state
76
+ end
77
+
78
+ def redcard_unload(path)
79
+ $".delete "#{path}.rb"
80
+ $".delete File.expand_path("../../lib/#{path}.rb", __FILE__)
81
+ end
82
+
83
+ def redcard_version(version)
84
+ RedCard::Specs.version = version
85
+ end
86
+
87
+ def redcard_engine(engine)
88
+ RedCard::Specs.engine = engine
89
+ end
90
+
91
+ def redcard_engine_version(version)
92
+ RedCard::Specs.save_engine_version
93
+ RedCard::Specs.engine_version = version
94
+ end
@@ -0,0 +1,112 @@
1
+ require 'spec_helper'
2
+
3
+ describe "RedCard.verify" do
4
+ before do
5
+ redcard_save_state
6
+ end
7
+
8
+ after do
9
+ redcard_restore_state
10
+ end
11
+
12
+ context "when RUBY_VERSION is '2.10.1'" do
13
+ before do
14
+ redcard_version "2.10.1"
15
+ end
16
+
17
+ it "returns nil for '2.0'" do
18
+ expect(RedCard.verify("2.0")).to be_nil
19
+ end
20
+
21
+ it "returns nil for '2.0.0'" do
22
+ expect(RedCard.verify("2.0.0")).to be_nil
23
+ end
24
+
25
+ it "returns nil for '2.9.10'" do
26
+ expect(RedCard.verify("2.9.10")).to be_nil
27
+ end
28
+
29
+ it "returns nil for '2.10.1'" do
30
+ expect(RedCard.verify("2.10.1")).to be_nil
31
+ end
32
+
33
+ it "returns nil for '1.9.100'" do
34
+ expect(RedCard.verify("1.9.100")).to be_nil
35
+ end
36
+
37
+ it "returns nil for '1.8.10'" do
38
+ expect(RedCard.verify("1.8.10")).to be_nil
39
+ end
40
+
41
+ it "raises an InvalidRubyVersionError for '2.10.2'" do
42
+ expect { RedCard.verify("2.10.2") }.to raise_error(RedCard::InvalidRubyVersionError)
43
+ end
44
+
45
+ it "returns nil for '1.8.10'..'2.10.1'" do
46
+ expect(RedCard.verify("1.8.10".."2.10.1")).to be_nil
47
+ end
48
+
49
+ it "returns nil for '1.8.10'..'2.10.2'" do
50
+ expect(RedCard.verify("1.8.10".."2.10.2")).to be_nil
51
+ end
52
+
53
+ it "returns nil for '1.8.10'..'2.11'" do
54
+ expect(RedCard.verify("1.8.10".."2.11")).to be_nil
55
+ end
56
+
57
+ it "raises an InvalidRubyVersionError for '2.10.2'..'2.11.2'" do
58
+ expect { RedCard.verify("2.10.2"..."2.11.2") }.to raise_error(RedCard::InvalidRubyVersionError)
59
+ end
60
+
61
+ it "raises an InvalidRubyVersionError for '1.8.10'...'2.10.1'" do
62
+ expect { RedCard.verify("1.8.10"..."2.10.1") }.to raise_error(RedCard::InvalidRubyVersionError)
63
+ end
64
+
65
+ context "when RUBY_ENGINE is 'rbx'" do
66
+ before do
67
+ redcard_engine "rbx"
68
+ end
69
+
70
+ it "returns nil for '1.9', :rbx" do
71
+ expect(RedCard.verify("1.9", :rbx)).to be_nil
72
+ end
73
+
74
+ it "raises an InvalidRubyEngineError for '1.9', :topaz" do
75
+ expect { RedCard.verify("1.9", :topaz) }.to raise_error(RedCard::InvalidRubyEngineError)
76
+ end
77
+
78
+ context "when Rubinius::VERSION is '2.0.0'" do
79
+ before do
80
+ redcard_engine_version "2.0.0"
81
+ end
82
+
83
+ it "returns nil for '1.9', :rbx => '2.0'" do
84
+ expect(RedCard.verify("1.9", :rbx => "2.0")).to be_nil
85
+ end
86
+
87
+ it "returns nil for '1.9', :rbx => '1.2.4'" do
88
+ expect(RedCard.verify("1.9", :rbx => "1.2.4")).to be_nil
89
+ end
90
+
91
+ it "raises an InvalidRubyError for '1.9', :rbx => '2.1'" do
92
+ expect { RedCard.verify("1.9", :rbx => "2.1") }.to raise_error(RedCard::InvalidRubyError)
93
+ end
94
+ end
95
+ end
96
+ end
97
+
98
+ context "when RUBY_ENGINE is 'rbx'" do
99
+ before do
100
+ redcard_engine "rbx"
101
+ end
102
+
103
+ it "returns nil for :rbx" do
104
+ expect(RedCard.verify(:rbx)).to be_nil
105
+ end
106
+
107
+ it "raises an InvalidRubyEngineError for :topaz" do
108
+ expect { RedCard.verify(:topaz) }.to raise_error(RedCard::InvalidRubyEngineError)
109
+ end
110
+ end
111
+ end
112
+
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: redcard
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Brian Shirai
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '0.9'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '0.9'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '2.8'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '2.8'
46
+ description:
47
+ email:
48
+ - brixen@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files:
52
+ - README.md
53
+ - LICENSE
54
+ files:
55
+ - .gitignore
56
+ - .travis.yml
57
+ - Gemfile
58
+ - LICENSE
59
+ - README.md
60
+ - Rakefile
61
+ - lib/redcard.rb
62
+ - lib/redcard/1.8.rb
63
+ - lib/redcard/1.9.rb
64
+ - lib/redcard/2.0.rb
65
+ - lib/redcard/engine.rb
66
+ - lib/redcard/ironruby.rb
67
+ - lib/redcard/jruby.rb
68
+ - lib/redcard/jruby/1.7.rb
69
+ - lib/redcard/maglev.rb
70
+ - lib/redcard/rubinius.rb
71
+ - lib/redcard/rubinius/2.0.rb
72
+ - lib/redcard/topaz.rb
73
+ - lib/redcard/version.rb
74
+ - redcard.gemspec
75
+ - spec/1.9_spec.rb
76
+ - spec/check_spec.rb
77
+ - spec/rubinius/2.0_spec.rb
78
+ - spec/rubinius_spec.rb
79
+ - spec/spec_helper.rb
80
+ - spec/verify_spec.rb
81
+ homepage: https://github.com/brixen/redcard
82
+ licenses: []
83
+ post_install_message:
84
+ rdoc_options:
85
+ - --title
86
+ - MSpec Gem
87
+ - --main
88
+ - README
89
+ - --line-numbers
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ! '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project: http://rubyforge.org/projects/mspec
106
+ rubygems_version: 1.8.24
107
+ signing_key:
108
+ specification_version: 3
109
+ summary: RedCard provides a standard way to ensure that the running Ruby implementation
110
+ matches the desired language version, implementation, and implementation version.
111
+ test_files:
112
+ - spec/1.9_spec.rb
113
+ - spec/check_spec.rb
114
+ - spec/rubinius/2.0_spec.rb
115
+ - spec/rubinius_spec.rb
116
+ - spec/spec_helper.rb
117
+ - spec/verify_spec.rb
118
+ has_rdoc: true