Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add frozen_object_error_class helper

1.8 raises a TypeError when attempting to modify a frozen object,
while 1.9 raises RuntimeError. Many rubyspecs exist in both a 1.8
and 1.9 form due to this difference alone; this helper allows us
to write a single spec for both versions.
  • Loading branch information...
commit af4f2d0f14821cc43d9f27e4620d951381d859e5 1 parent 62292dc
@jfirebaugh jfirebaugh authored
View
9 lib/mspec/helpers/frozen_object_error_class.rb
@@ -0,0 +1,9 @@
+class Object
+
+ # Returns the class of the exception raised when attempting to modify
+ # a frozen object: either TypeError or RuntimeError, depending on the version.
+ #
+ def frozen_object_error_class
+ SpecVersion.new(RUBY_VERSION) < "1.9" ? TypeError : RuntimeError
+ end
+end
View
17 spec/helpers/frozen_object_error_class.rb
@@ -0,0 +1,17 @@
+require 'spec_helper'
+require 'mspec/guards'
+require 'mspec/helpers'
+
+describe "#frozen_object_error_class" do
+ ruby_version_is ''...'1.9' do
+ it "is TypeError" do
+ frozen_object_error_class.should == TypeError
+ end
+ end
+
+ ruby_version_is '1.9' do
+ it "is RuntimeError" do
+ frozen_object_error_class.should == RuntimeError
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.