This repository has been archived by the owner on Nov 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
versionable_spec.rb
98 lines (77 loc) · 2.36 KB
/
versionable_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe Versionable do
it "does seemingly nothing by default" do
class Unmolested
include Versionable
def foo; :foo; end
end
Unmolested.new.foo.should == :foo
end
describe ".version" do
it "takes a version number" do
class Versioned
include Versionable
def foo; :past_foo; end
def baz; :baz; end
version "1"
def foo; :foo; end
def self.bar; :bar; end
end
end
it "rejects bad version numbers" do
lambda do
class Versioned
version "chowder!"
end
end.should raise_error ArgumentError
end
it "rejects non-increasing version numbers" do
lambda do
class Versioned; version "0"; end
end.should raise_error ArgumentError
lambda do
class Versioned; version "1"; end
end.should raise_error ArgumentError
end
it "takes a block for versions after the default" do
class Versioned
version "2" do
def foo; :future_foo; end
end
version "3" do
def foo; :far_future_foo; end
end
end
end
it "rejects blockless calls after block ones" do
lambda do
class Versioned; version "4"; end
end.should raise_error Versionable::VersioningError
end
end
describe "[]" do
it "sends versions to classes" do
Unmolested['0'].should be_a Class
end
it "sends the default version to itself" do
Unmolested['0'].should == Unmolested
Versioned['1'].should == Versioned
end
it "sends other versions to similar classes, representing older or newer functionality" do
Versioned['0'].should_not == Versioned
Versioned['0'].new.foo.should == :past_foo
Versioned['1'].bar.should == :bar
lambda { Versioned['0'].bar }.should raise_error NoMethodError
Versioned['2'].should_not == Versioned
Versioned['2'].new.foo.should == :future_foo
Versioned['3'].new.foo.should == :far_future_foo
end
it "takes comparator expressions" do
Versioned[">= 0"].should == Versioned['3']
Versioned["<= 2"].should == Versioned['2']
Versioned["< 2"].should == Versioned['1']
Versioned["= 0"].should == Versioned['0']
Versioned["> 0"].should == Versioned['3']
end
end
end