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 229 230 231 232
|
require File.dirname(__FILE__) + "/../spec_helper"
java_import "java_integration.fixtures.MethodNames"
java_import "java_integration.fixtures.ArrayReceiver"
java_import "java_integration.fixtures.BeanLikeInterface"
describe "Java static method names" do
let(:class_methods) { MethodNames.methods }
it "should present as both camel-case and ruby-case" do
expect(class_methods).to have_strings_or_symbols("lowercase1",
"camelCase1",
"camel_case1",
"camelWithUPPER1",
"camel_with_upper1",
"camelWITHUpper1",
"CAMELWithUpper1")
expect(class_methods).not_to have_strings_or_symbols("camel_withupper1",
"camelwith_upper1")
end
it "keeps all caps in a name together as a single downcased word" do
expect(class_methods).to have_strings_or_symbols("value_objs",
"value_objs=",
"value_objs_here",
"value_objs_here=")
end
it "should present javabean properties as attribute readers and writers" do
expect(class_methods).to have_strings_or_symbols("getValue1",
"get_value1",
"value1",
"setValue1",
"set_value1",
"value1=",
"getValues1",
"get_values1",
"setValues1",
"set_values1")
expect(class_methods).not_to have_strings_or_symbols("values1",
"values1=")
end
it "should present boolean javabean property accessors as '?' method" do
expect(class_methods).to have_strings_or_symbols("isFirst1",
"first1",
"first1?",
"isSecond1",
"second1",
"second1?",
"hasThird1",
"has_third1",
"has_third1?",
"hasFourth1",
"has_fourth1",
"has_fourth1?")
expect(class_methods).not_to have_strings_or_symbols("fourth1?")
end
it "should not overwrite critical core Ruby methods" do
skip("need a better way to separate class and instance methods in the java code")
end
end
describe "Java instance method names" do
let(:members) { MethodNames.instance_methods }
it "should present as both camel-case and ruby-case" do
expect(members).to have_strings_or_symbols("lowercase2",
"camelCase2",
"camel_case2",
"camelWithUPPER2",
"camel_with_upper2",
"camelWITHUpper2",
"CAMELWithUpper2")
expect(members).not_to have_strings_or_symbols("camel_withupper2",
"camelwith_upper2")
end
it "should present javabean properties as attribute readers and writers" do
expect(members).to have_strings_or_symbols("getValue2",
"get_value2",
"value2",
"setValue2",
"set_value2",
"value2=",
"getValues2",
"get_values2",
"setValues2",
"set_values2",
"get_my_value",
"my_value",
"set_my_value",
"my_value=",
"getX",
"get_x",
"x",
"bigO",
"big_o")
expect(members).not_to have_strings_or_symbols("values2",
"values2=",
"get_myvalue",
"set_myvalue",
"myvalue=")
end
it "with colliding is/get property - ruby name does get" do
expect( MethodNames.new.foo? ).to be false
expect( MethodNames.new.foo ).to eql 42
end
it "keeps all caps in a name together as a single downcased word" do
expect(members).to have_strings_or_symbols("value_obj",
"value_obj=",
"value_obj_here",
"value_obj_here=")
end
it "should treat consecutive caps as part of one property name" do
expect(members).to have_strings_or_symbols("jconsecutive_caps",
"jconsecutive_caps=")
end
it "should present boolean javabean property accessors as '?' method" do
expect(members).to have_strings_or_symbols("isFirst2",
"first2",
"first2?",
"isSecond2",
"second2",
"second2?",
"hasThird2",
"has_third2",
"has_third2?",
"hasFourth2",
"has_fourth2",
"has_fourth2?")
expect(members).not_to have_strings_or_symbols("fourth2?")
end
it "should not overwrite critical core Ruby methods" do
obj = MethodNames.new
expect(obj.send(:initialize)).not_to eq("foo")
expect(obj.object_id).not_to eq("foo")
expect(obj.__id__).not_to eq("foo")
expect {obj.__send__}.to raise_error(ArgumentError)
end
end
describe "Needed implementation methods for concrete classes" do
it "should have __id__ method" do
expect(ArrayReceiver.new.methods).to have_strings_or_symbols("__id__")
end
it "should have __send__ method" do
expect(ArrayReceiver.new.methods).to have_strings_or_symbols("__send__")
end
it "should have == method" do
expect(ArrayReceiver.new.methods).to have_strings_or_symbols("==")
end
it "should have inspect method" do
expect(ArrayReceiver.new.methods).to have_strings_or_symbols("inspect")
end
it "should have respond_to? method" do
expect(ArrayReceiver.new.methods).to have_strings_or_symbols("respond_to?")
end
it "should have class method" do
expect(ArrayReceiver.new.methods).to have_strings_or_symbols("class")
end
it "should have methods method" do
expect(ArrayReceiver.new.methods).to have_strings_or_symbols("methods")
end
it "should have send method" do
expect(ArrayReceiver.new.methods).to have_strings_or_symbols("send")
end
it "should have equal? method" do
expect(ArrayReceiver.new.methods).to have_strings_or_symbols("equal?")
end
it "should have eql? method" do
expect(ArrayReceiver.new.methods).to have_strings_or_symbols("eql?")
end
it "should have to_s method" do
expect(ArrayReceiver.new.methods).to have_strings_or_symbols("to_s")
end
end
describe "Needed implementation methods for interfaces" do
it "should have __id__ method" do
expect(BeanLikeInterface.impl {}.methods).to have_strings_or_symbols("__id__")
end
it "should have __send__ method" do
expect(BeanLikeInterface.impl {}.methods).to have_strings_or_symbols("__send__")
end
it "should have == method" do
expect(BeanLikeInterface.impl {}.methods).to have_strings_or_symbols("==")
end
it "should have inspect method" do
expect(BeanLikeInterface.impl {}.methods).to have_strings_or_symbols("inspect")
end
it "should have respond_to? method" do
expect(BeanLikeInterface.impl {}.methods).to have_strings_or_symbols("respond_to?")
end
it "should have class method" do
expect(BeanLikeInterface.impl {}.methods).to have_strings_or_symbols("class")
end
it "should have methods method" do
expect(BeanLikeInterface.impl {}.methods).to have_strings_or_symbols("methods")
end
it "should have send method" do
expect(BeanLikeInterface.impl {}.methods).to have_strings_or_symbols("send")
end
it "should have equal? method" do
expect(BeanLikeInterface.impl {}.methods).to have_strings_or_symbols("equal?")
end
it "should have eql? method" do
expect(BeanLikeInterface.impl {}.methods).to have_strings_or_symbols("eql?")
end
it "should have to_s method" do
expect(BeanLikeInterface.impl {}.methods).to have_strings_or_symbols("to_s")
end
it "should be able to access Java methods of core Ruby Methods via __method" do
expect(MethodNames.new.initialize__method).to eq("foo")
expect(MethodNames.__send____method).to eq("foo")
end
end
|