must 0.2.7 → 0.2.8
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -0
- data/README +4 -0
- data/Rakefile +2 -0
- data/lib/must/rule.rb +3 -1
- data/lib/must/struct_info.rb +50 -0
- data/lib/must/version.rb +1 -1
- data/must.gemspec +1 -3
- data/spec/spec_helper.rb +15 -0
- data/spec/struct_spec.rb +11 -0
- metadata +24 -10
data/Gemfile
ADDED
data/README
CHANGED
data/Rakefile
CHANGED
data/lib/must/rule.rb
CHANGED
@@ -42,7 +42,8 @@ module Must
|
|
42
42
|
def kind_of(*targets, &block)
|
43
43
|
bool = targets.any?{|klass| is_a?(klass)}
|
44
44
|
block ||= proc {
|
45
|
-
target = targets.map{|i| instance?(i) ? i.class.name : i.name}.join('
|
45
|
+
target = targets.map{|i| instance?(i) ? i.class.name : i.name}.join('|')
|
46
|
+
target = "(#{target})" if targets.size > 1
|
46
47
|
raise Invalid, "expected #{target} but got #{object.class}"
|
47
48
|
}
|
48
49
|
valid?(bool, &block)
|
@@ -104,6 +105,7 @@ module Must
|
|
104
105
|
end
|
105
106
|
|
106
107
|
def struct(target, &block)
|
108
|
+
block ||= proc{ raise Invalid, Must::StructInfo::Differ.new(@object, target, "").execute.to_s }
|
107
109
|
valid?(struct?(target), &block)
|
108
110
|
end
|
109
111
|
|
data/lib/must/struct_info.rb
CHANGED
@@ -75,6 +75,56 @@ module Must
|
|
75
75
|
extend self
|
76
76
|
end
|
77
77
|
|
78
|
+
class Differ
|
79
|
+
attr_reader :a, :b, :path
|
80
|
+
|
81
|
+
def initialize(a, b, path)
|
82
|
+
@a, @b, @path = a, b, path
|
83
|
+
end
|
84
|
+
|
85
|
+
def execute!
|
86
|
+
sa = StructInfo::new(a).inspect
|
87
|
+
sb = StructInfo::new(b).inspect
|
88
|
+
|
89
|
+
unless sa == sb
|
90
|
+
failed("%s expected %s, but got %s" % [path, sb, sa])
|
91
|
+
end
|
92
|
+
|
93
|
+
if a.class == Array
|
94
|
+
max = [a.size, b.size].max
|
95
|
+
(0...max).each do |i|
|
96
|
+
Differ.new(a[i], b[i], "#{path}[#{i}]").execute!
|
97
|
+
end
|
98
|
+
return true
|
99
|
+
end
|
100
|
+
|
101
|
+
if a.class == Hash
|
102
|
+
(a.keys | b.keys).each do |key|
|
103
|
+
Differ.new(a[key], b[key], "#{path}[#{key}]").execute!
|
104
|
+
end
|
105
|
+
return true
|
106
|
+
end
|
107
|
+
|
108
|
+
unless a == b
|
109
|
+
failed("%s expected %s, but got %s" % [path, a.inspect, b.inspect])
|
110
|
+
end
|
111
|
+
|
112
|
+
return nil
|
113
|
+
end
|
114
|
+
|
115
|
+
def execute
|
116
|
+
execute!
|
117
|
+
return nil
|
118
|
+
rescue => err
|
119
|
+
return err
|
120
|
+
end
|
121
|
+
|
122
|
+
private
|
123
|
+
def failed(msg)
|
124
|
+
raise msg
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
78
128
|
######################################################################
|
79
129
|
### StructInfo
|
80
130
|
|
data/lib/must/version.rb
CHANGED
data/must.gemspec
CHANGED
@@ -16,7 +16,5 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
17
|
s.require_paths = ["lib"]
|
18
18
|
|
19
|
-
|
20
|
-
# s.add_development_dependency "rspec"
|
21
|
-
# s.add_runtime_dependency "rest-client"
|
19
|
+
s.add_development_dependency "rspec"
|
22
20
|
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rspec'
|
3
|
+
|
4
|
+
require File.dirname(__FILE__) + '/../init'
|
5
|
+
|
6
|
+
RSpec.configure do |config|
|
7
|
+
# == Mock Framework
|
8
|
+
#
|
9
|
+
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|
10
|
+
#
|
11
|
+
# config.mock_with :mocha
|
12
|
+
# config.mock_with :flexmock
|
13
|
+
# config.mock_with :rr
|
14
|
+
config.mock_with :rspec
|
15
|
+
end
|
data/spec/struct_spec.rb
ADDED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: must
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 7
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 8
|
10
|
+
version: 0.2.8
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- maiha
|
@@ -15,10 +15,22 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
date: 2013-02-22 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rspec
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
type: :development
|
33
|
+
version_requirements: *id001
|
22
34
|
description: add Object#must method to constrain its origin and conversions
|
23
35
|
email:
|
24
36
|
- maiha@wota.jp
|
@@ -29,6 +41,7 @@ extensions: []
|
|
29
41
|
extra_rdoc_files: []
|
30
42
|
|
31
43
|
files:
|
44
|
+
- Gemfile
|
32
45
|
- README
|
33
46
|
- Rakefile
|
34
47
|
- init.rb
|
@@ -38,13 +51,14 @@ files:
|
|
38
51
|
- lib/must/struct_info.rb
|
39
52
|
- lib/must/version.rb
|
40
53
|
- must.gemspec
|
54
|
+
- spec/spec_helper.rb
|
55
|
+
- spec/struct_spec.rb
|
41
56
|
- test/coerced_test.rb
|
42
57
|
- test/duck_test.rb
|
43
58
|
- test/match_test.rb
|
44
59
|
- test/must_test.rb
|
45
60
|
- test/struct_info_test.rb
|
46
61
|
- test/struct_test.rb
|
47
|
-
has_rdoc: true
|
48
62
|
homepage: http://github.com/maiha/must
|
49
63
|
licenses: []
|
50
64
|
|
@@ -74,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
88
|
requirements: []
|
75
89
|
|
76
90
|
rubyforge_project:
|
77
|
-
rubygems_version: 1.
|
91
|
+
rubygems_version: 1.8.15
|
78
92
|
signing_key:
|
79
93
|
specification_version: 3
|
80
94
|
summary: a runtime specification tool
|