Skip to content

Commit

Permalink
test/insulation.rb: updated for Ruby 1.9
Browse files Browse the repository at this point in the history
* classes and constants defined in an insulated test are not accessible
  outside the test (due to change in operation of instance_eval in 1.9).
* tests run differently in 1.8 and 1.9 and give appropriate messages
  for each
* methods in this class: D18 and D19 for version-sensitive test
  descriptions; hopefully migrate this functionality to core attest soon.
  • Loading branch information
gsinclair committed Jul 18, 2010
1 parent 19d2187 commit 10928d7
Showing 1 changed file with 49 additions and 9 deletions.
58 changes: 49 additions & 9 deletions test/insulation.rb
Expand Up @@ -11,6 +11,26 @@ def answer
end
end

def ruby_version
case RUBY_VERSION
when /^1.8/ then :v18
when /^1.9/ then :v19
else raise "Unknown version of Ruby: #{RUBY_VERSION}"
end
end

def D18(text, &block)
if ruby_version == :v18
D text, &block
end
end

def D19(text, &block)
if ruby_version == :v19
D text, &block
end
end

D "Modules" do
D "We can 'extend Insulation' in a non-insulated test" do
extend Insulation
Expand Down Expand Up @@ -112,37 +132,49 @@ def empty_string?(str) str.strip.size == 0 end
end

D "Classes" do
D! "We can define classes in an insulated test..." do
D! "We can define classes in an INSULATED test (class A)..." do
class A
def bar() 5 end
end
a = A.new
T { a.bar == 5 }
end

D "...and also in a non-insulated test" do
D "...and also in a NON-INSULATED test (class B)" do
class B
def bar() 9 end
end
b = B.new
T { b.bar == 9 }
end

D "We can reuse the classes defined in both the above sub-tests" do
D18 "(1.8) We can reuse class A" do
a = A.new
T { a.bar() == 5 }
end

D19 "(1.9) We CAN'T reuse class A (it was insulated)" do
E(NameError) { a = A.new }
end

D "We can reuse class B" do
b = B.new
T { b.bar == 9 }
end
end # "Classes"

D "Classes (again)" do
D "We can reuse the classes defined in the above test" do
D18 "(1.8) We can reuse class A and class B" do
a = A.new
T { a.bar() == 5 }
b = B.new
T { b.bar() == 9 }
end

D19 "(1.9) We CAN'T reuse class A and class B (they were insulated)" do
E(NameError) { a = A.new }
E(NameError) { b = B.new }
end
end


Expand All @@ -155,21 +187,29 @@ def bar() 9 end
JENNY = :jenny
end
end
D "Those constants are accessible in a different test" do

D18 "(1.8) FRED is available outside its insulated test" do
T { FRED == :fred }
T { JENNY == :jenny }
D! "(even an insulated one)" do
T { FRED == :fred }
T { JENNY == :jenny }
end
end
end

D19 "(1.9) FRED is NOT available outside its insulated test" do
E(NameError) { FRED == :fred }
end
end # "Constants"

D "Constants (again)" do
D "FRED and JENNY are accessible here too" do
D18 "(1.8) FRED and JENNY are accessible here too" do
T { FRED == :fred }
T { JENNY == :jenny }
end

D19 "(1.9) FRED and JENNY are NOT accessible here (top-level test is insulated)" do
E(NameError) { FRED == :fred }
E(NameError) { JENNY == :jenny }
end
end


Expand Down

0 comments on commit 10928d7

Please sign in to comment.