File: naming_spec.rb

package info (click to toggle)
jruby 1.5.1-1%2Bdeb6u1
  • links: PTS, VCS
  • area: non-free
  • in suites: squeeze-lts
  • size: 47,024 kB
  • ctags: 74,144
  • sloc: ruby: 398,155; java: 169,506; yacc: 3,782; xml: 2,469; ansic: 415; sh: 279; makefile: 78; tcl: 40
file content (228 lines) | stat: -rw-r--r-- 7,232 bytes parent folder | download | duplicates (4)
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
require File.dirname(__FILE__) + "/../spec_helper"

import "java_integration.fixtures.MethodNames"

describe "Java static method names" do
  it "should present as both camel-case and ruby-case" do
    methods = MethodNames.methods
    
    methods.should include("lowercase1")
    methods.should include("camelCase1")
    methods.should include("camel_case1")
    methods.should include("camelWithUPPER1")
    methods.should include("camel_with_upper1")
    methods.should include("camelWITHUpper1")
    methods.should include("CAMELWithUpper1")
    
    pending("broken") do
      methods.should_not include("camel_withupper1")
      methods.should_not include("camelwith_upper1")
    end
  end
  
  it "should present javabean properties as attribute readers and writers" do
    methods = MethodNames.methods
    
    methods.should include("getValue1")
    methods.should include("get_value1")
    methods.should include("value1")
    
    methods.should include("setValue1")
    methods.should include("set_value1")
    methods.should include("value1=")
    
    methods.should include("getValues1")
    methods.should include("get_values1")
    methods.should_not include("values1")
    
    methods.should include("setValues1")
    methods.should include("set_values1")
    methods.should_not include("values1=")
  end

  it "should present boolean javabean property accessors as '?' method" do
    methods = MethodNames.methods
    
    methods.should include("isFirst1")
    methods.should include("first1")
    methods.should include("first1?")

    methods.should include("isSecond1")
    methods.should include("second1")
    methods.should include("second1?")
    
    methods.should include("hasThird1")
    methods.should include("has_third1")
    methods.should include("has_third1?")

    methods.should include("hasFourth1")
    methods.should include("has_fourth1");
    methods.should include("has_fourth1?");

    pending("not implemented") do
      methods.should include("third1?")
    end
    methods.should_not include("fourth1?")
  end
  
  it "should not overwrite critical core Ruby methods" do
    pending("need a better way to separate class and instance methods in the java code")
  end
end

describe "Java instance method names" do
  it "should present as both camel-case and ruby-case" do
    methods = MethodNames.instance_methods
    
    methods.should include("lowercase2")
    methods.should include("camelCase2")
    methods.should include("camel_case2")
    methods.should include("camelWithUPPER2")
    methods.should include("camel_with_upper2")
    methods.should include("camelWITHUpper2")
    methods.should include("CAMELWithUpper2")
    
    pending("broken") do
      methods.should_not include("camel_withupper2")
      methods.should_not include("camelwith_upper2")
    end
  end
  
  it "should present javabean properties as attribute readers and writers" do
    methods = MethodNames.instance_methods
    
    methods.should include("getValue2")
    methods.should include("get_value2")
    methods.should include("value2")
    
    methods.should include("setValue2")
    methods.should include("set_value2")
    methods.should include("value2=")
    
    methods.should include("getValues2")
    methods.should include("get_values2")
    methods.should_not include("values2")
    
    methods.should include("setValues2")
    methods.should include("set_values2")
    methods.should_not include("values2=")
  end
  
  it "should treat consecutive caps as part of one property name" do
    methods = MethodNames.instance_methods

    methods.should include("jconsecutive_caps")
    methods.should include("jconsecutive_caps=")
  end
  
  it "should present boolean javabean property accessors as '?' method" do
    methods = MethodNames.instance_methods
    
    methods.should include("isFirst2")
    methods.should include("first2")
    methods.should include("first2?")

    methods.should include("isSecond2")
    methods.should include("second2")
    methods.should include("second2?")
    
    methods.should include("hasThird2")
    methods.should include("has_third2")
    methods.should include("has_third2?")

    methods.should include("hasFourth2")
    methods.should include("has_fourth2")
    methods.should include("has_fourth2?")

    pending("not implemented") do
      methods.should include("third2?")
    end
    methods.should_not include("fourth2?")
  end
  
  it "should not overwrite critical core Ruby methods" do
    obj = MethodNames.new
    
    obj.send(:initialize).should_not == "foo"
    obj.object_id.should_not == "foo"
    obj.__id__.should_not == "foo"
    lambda {obj.__send__}.should raise_error(ArgumentError)
  end
end

describe "Needed implementation methods for concrete classes" do 
  it "should have __id__ method" do 
    ArrayReceiver.new.methods.should include("__id__")
  end
  it "should have __send__ method" do 
    ArrayReceiver.new.methods.should include("__send__")
  end
  it "should have == method" do 
    ArrayReceiver.new.methods.should include("==")
  end
  it "should have inspect method" do 
    ArrayReceiver.new.methods.should include("inspect")
  end
  it "should have respond_to? method" do 
    ArrayReceiver.new.methods.should include("respond_to?")
  end
  it "should have class method" do 
    ArrayReceiver.new.methods.should include("class")
  end
  it "should have methods method" do 
    ArrayReceiver.new.methods.should include("methods")
  end
  it "should have send method" do 
    ArrayReceiver.new.methods.should include("send")
  end
  it "should have equal? method" do 
    ArrayReceiver.new.methods.should include("equal?")
  end
  it "should have eql? method" do 
    ArrayReceiver.new.methods.should include("eql?")
  end
  it "should have to_s method" do 
    ArrayReceiver.new.methods.should include("to_s")
  end
end

describe "Needed implementation methods for interfaces" do 
  it "should have __id__ method" do 
    BeanLikeInterface.new.methods.should include("__id__")
  end
  it "should have __send__ method" do 
    BeanLikeInterface.new.methods.should include("__send__")
  end
  it "should have == method" do 
    BeanLikeInterface.new.methods.should include("==")
  end
  it "should have inspect method" do 
    BeanLikeInterface.new.methods.should include("inspect")
  end
  it "should have respond_to? method" do 
    BeanLikeInterface.new.methods.should include("respond_to?")
  end
  it "should have class method" do 
    BeanLikeInterface.new.methods.should include("class")
  end
  it "should have methods method" do 
    BeanLikeInterface.new.methods.should include("methods")
  end
  it "should have send method" do 
    BeanLikeInterface.new.methods.should include("send")
  end
  it "should have equal? method" do 
    BeanLikeInterface.new.methods.should include("equal?")
  end
  it "should have eql? method" do 
    BeanLikeInterface.new.methods.should include("eql?")
  end
  it "should have to_s method" do 
    BeanLikeInterface.new.methods.should include("to_s")
  end

  it "should be able to access Java methods of core Ruby Methods via $method" do
    MethodNames.new.initialize__method.should == "foo"
    MethodNames.__send____method.should == "foo"
  end
end