Permalink
Browse files

Handle exception differencies between 1.8 and 1.9

* This solution should also work for jruby, rbx etc.
  • Loading branch information...
1 parent 6592ba2 commit 1548bc9c87ba0db58a5a595465f011c1208a45f4 Markus Schirp committed Jul 19, 2012
Showing with 20 additions and 1 deletion.
  1. +20 −1 spec/shared/freeze_method_behavior.rb
View
21 spec/shared/freeze_method_behavior.rb
@@ -1,4 +1,22 @@
shared_examples_for 'a #freeze method' do
+ let(:sample_exception) do
+ begin
+ object.dup.freeze.instance_variable_set(:@foo,:bar)
+ rescue => exception
+ exception
+ end
+ end
+
+ let(:expected_exception_class) do
+ # Ruby 1.8 blows up with TypeError Ruby 1.9 with RuntimeError
+ sample_exception.class
+ end
+
+ let(:expected_exception_message) do
+ # Ruby 1.8 blows up with a different message than Ruby 1.9
+ sample_exception.message
+ end
+
it_should_behave_like 'an idempotent method'
it 'returns object' do
@@ -7,7 +25,8 @@
it 'prevents future modifications' do
subject
- expect { object.instance_variable_set(:@foo,:bar) }.to raise_error(RuntimeError,"can't modify frozen #{object.class.inspect}")
+ expectation = raise_error(expected_exception_class,expected_exception_message)
+ expect { object.instance_variable_set(:@foo,:bar) }.to(expectation)
end
its(:frozen?) { should be(true) }

0 comments on commit 1548bc9

Please sign in to comment.