Module: Opal::RSpec::Compatibility
- Defined in:
- opal/opal/rspec/fixes/opal/compatibility.rb
Defined Under Namespace
Modules: ModuleCase, ModuleCase2, ModuleConstTest, MultModSuper1, MultModSuper2, MultModSuper3 Classes: ConstTest, ModuleCase3, MultModSuperClass
Constant Summary collapse
- TEST_CLASS =
Class.new do class ClassWithinClassNewWorks end def self.does_class_exist? Compatibility.const_defined? :ClassWithinClassNewWorks end end
Class Method Summary collapse
-
.and_works_with_lhs_nil? ⇒ Boolean
https://github.com/opal/opal/issues/1090, fixed in Opal 0.9.
-
.class_descendant_of_self_fixed? ⇒ Boolean
https://github.com/opal/opal/issues/1077, fixed in Opal 0.9.
-
.class_within_class_new_works? ⇒ Boolean
https://github.com/opal/opal/issues/1110, fixed in Opal 0.9.
-
.clones_singleton_methods? ⇒ Boolean
https://github.com/opal/opal/commit/78016aa11955e4cff3d6bbf06f1222d40b03a9e6, fixed in Opal 0.9.
- .constant_resolution_works_right? ⇒ Boolean
- .empty_regex_works? ⇒ Boolean
-
.exception_exception_method_works? ⇒ Boolean
https://github.com/opal/opal/pull/1151, should be fixed in Opal 0.9.
- .exception_inspect_matches? ⇒ Boolean
-
.fail_raise_matches_mri? ⇒ Boolean
https://github.com/opal/opal/pull/1117, status pending.
-
.full_class_names? ⇒ Boolean
https://github.com/opal/opal/issues/1079, fixed in Opal 0.9.
-
.is_constants_a_clone? ⇒ Boolean
https://github.com/opal/opal/issues/1080, fixed in Opal 0.9.
- .is_set_coerced_to_array? ⇒ Boolean
-
.is_struct_hash_correct? ⇒ Boolean
https://github.com/opal/opal/pull/1123, SHOULD be fixed in Opal 0.9.
-
.lambda_zero_arg_throws_arg_error? ⇒ Boolean
MRI does does, Opal does not yet.
- .module_case_works_right? ⇒ Boolean
- .multiline_regex_works? ⇒ Boolean
- .multiple_module_include_super_works_right? ⇒ Boolean
- .ostruct_works_right? ⇒ Boolean
-
.pp_uses_stdout_default? ⇒ Boolean
https://github.com/opal/opal/pull/1104, fixed in Opal 0.9.
- .regex_case_compare_works? ⇒ Boolean
- .set_has_superset? ⇒ Boolean
-
.undef_within_exec_works? ⇒ Boolean
Fixed in Opal 0.9.
Class Method Details
.and_works_with_lhs_nil? ⇒ Boolean
https://github.com/opal/opal/issues/1090, fixed in Opal 0.9
53 54 55 56 |
# File 'opal/opal/rspec/fixes/opal/compatibility.rb', line 53 def self.and_works_with_lhs_nil? value = nil (value && nil) == nil end |
.class_descendant_of_self_fixed? ⇒ Boolean
https://github.com/opal/opal/issues/1077, fixed in Opal 0.9
48 49 50 |
# File 'opal/opal/rspec/fixes/opal/compatibility.rb', line 48 def self.class_descendant_of_self_fixed? !(String < String) end |
.class_within_class_new_works? ⇒ Boolean
https://github.com/opal/opal/issues/1110, fixed in Opal 0.9
95 96 97 |
# File 'opal/opal/rspec/fixes/opal/compatibility.rb', line 95 def self.class_within_class_new_works? TEST_CLASS.does_class_exist? end |
.clones_singleton_methods? ⇒ Boolean
https://github.com/opal/opal/commit/78016aa11955e4cff3d6bbf06f1222d40b03a9e6, fixed in Opal 0.9
5 6 7 8 9 10 11 12 13 14 |
# File 'opal/opal/rspec/fixes/opal/compatibility.rb', line 5 def self.clones_singleton_methods? obj = Object.new def obj.special() :the_one end clone = obj.clone clone.respond_to?(:special) && clone.special == :the_one end |
.constant_resolution_works_right? ⇒ Boolean
144 145 146 147 148 149 150 151 |
# File 'opal/opal/rspec/fixes/opal/compatibility.rb', line 144 def self.constant_resolution_works_right? begin ModuleConstTest::ConstTest.new false rescue true end end |
.empty_regex_works? ⇒ Boolean
119 120 121 122 123 124 125 126 |
# File 'opal/opal/rspec/fixes/opal/compatibility.rb', line 119 def self.empty_regex_works? empty = // begin empty. == 0 && empty.match('foo').to_s == '' rescue false end end |
.exception_exception_method_works? ⇒ Boolean
https://github.com/opal/opal/pull/1151, should be fixed in Opal 0.9
159 160 161 |
# File 'opal/opal/rspec/fixes/opal/compatibility.rb', line 159 def self.exception_exception_method_works? Exception.respond_to?(:exception) && Exception.exception.is_a?(Exception) end |
.exception_inspect_matches? ⇒ Boolean
154 155 156 |
# File 'opal/opal/rspec/fixes/opal/compatibility.rb', line 154 def self.exception_inspect_matches? Exception.new.inspect == '#<Exception: Exception>' end |
.fail_raise_matches_mri? ⇒ Boolean
https://github.com/opal/opal/pull/1117, status pending
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'opal/opal/rspec/fixes/opal/compatibility.rb', line 72 def self.fail_raise_matches_mri? ex = nil %x{ try { #{fail} } catch(e) { #{ex} = e; } } ex.is_a? RuntimeError end |
.full_class_names? ⇒ Boolean
https://github.com/opal/opal/issues/1079, fixed in Opal 0.9
31 32 33 |
# File 'opal/opal/rspec/fixes/opal/compatibility.rb', line 31 def self.full_class_names? Opal::RSpec::Compatibility.to_s == 'Opal::RSpec::Compatibility' end |
.is_constants_a_clone? ⇒ Boolean
https://github.com/opal/opal/issues/1080, fixed in Opal 0.9
42 43 44 45 |
# File 'opal/opal/rspec/fixes/opal/compatibility.rb', line 42 def self.is_constants_a_clone? mod = Opal::RSpec::Compatibility `#{mod.constants} !== #{mod.constants}` end |
.is_set_coerced_to_array? ⇒ Boolean
59 60 61 62 63 64 65 66 67 68 69 |
# File 'opal/opal/rspec/fixes/opal/compatibility.rb', line 59 def self.is_set_coerced_to_array? require 'set' obj = Object.new def obj.splat(*data) return data[0] end obj.splat(*Set.new(Set.new([:foo, :bar]))) == :foo end |
.is_struct_hash_correct? ⇒ Boolean
https://github.com/opal/opal/pull/1123, SHOULD be fixed in Opal 0.9
36 37 38 39 |
# File 'opal/opal/rspec/fixes/opal/compatibility.rb', line 36 def self.is_struct_hash_correct? s = Struct.new(:id) s.new(1) == s.new(1) end |
.lambda_zero_arg_throws_arg_error? ⇒ Boolean
MRI does does, Opal does not yet
221 222 223 224 225 |
# File 'opal/opal/rspec/fixes/opal/compatibility.rb', line 221 def self.lambda_zero_arg_throws_arg_error? !(lambda { 3 } === lambda { 4 }) rescue true end |
.module_case_works_right? ⇒ Boolean
182 183 184 185 |
# File 'opal/opal/rspec/fixes/opal/compatibility.rb', line 182 def self.module_case_works_right? instance = ModuleCase3.new ModuleCase === instance && instance.kind_of?(ModuleCase) end |
.multiline_regex_works? ⇒ Boolean
114 115 116 |
# File 'opal/opal/rspec/fixes/opal/compatibility.rb', line 114 def self.multiline_regex_works? /foo.bar/m.match("foo\nbar").to_a == ["foo\nbar"] end |
.multiple_module_include_super_works_right? ⇒ Boolean
208 209 210 211 212 |
# File 'opal/opal/rspec/fixes/opal/compatibility.rb', line 208 def self.multiple_module_include_super_works_right? MultModSuperClass.new.stuff == :howdy rescue false end |
.ostruct_works_right? ⇒ Boolean
164 165 166 167 168 169 |
# File 'opal/opal/rspec/fixes/opal/compatibility.rb', line 164 def self.ostruct_works_right? require 'ostruct' s = OpenStruct.new(:exist? => true) s.respond_to? :exist? end |
.pp_uses_stdout_default? ⇒ Boolean
https://github.com/opal/opal/pull/1104, fixed in Opal 0.9
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'opal/opal/rspec/fixes/opal/compatibility.rb', line 17 def self.pp_uses_stdout_default? require 'stringio' require 'pp' stdout = $stdout $stdout = StringIO.new msg = 'opal-rspec - checking pp/pretty print features' PP.pp msg $stdout.string == "\"#{msg}\"\n" ensure $stdout = stdout end |
.regex_case_compare_works? ⇒ Boolean
129 130 131 132 133 134 135 |
# File 'opal/opal/rspec/fixes/opal/compatibility.rb', line 129 def self.regex_case_compare_works? begin (/abc/ === nil) == false && (/abc/ === /abc/) == false rescue false end end |
.set_has_superset? ⇒ Boolean
215 216 217 218 |
# File 'opal/opal/rspec/fixes/opal/compatibility.rb', line 215 def self.set_has_superset? require 'set' Set.new.respond_to?(:superset?) end |
.undef_within_exec_works? ⇒ Boolean
Fixed in Opal 0.9
100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'opal/opal/rspec/fixes/opal/compatibility.rb', line 100 def self.undef_within_exec_works? klass = Class.new do def end end klass.class_exec do undef end !klass.new.respond_to? :bar end |