I have a module with two methods for marshaling objects.
The following rspec code is used to test this module:
----- Start Code -----
require ‘…/code/fmutil.rb’
require ‘…/code/fmgrid.rb’
require ‘…/code/serial.rb’
start test of Serial Module
describe Serial do
describe “Given a grid with the block test pattern” do
before(:all) do
cfg01 = Fmconfig.new
grid01 = Grid.makeempty(cfg01,500,20)
cfg01.list[:cellhight].times do |y|
cfg01.list[:cellwidth].times do |x|
grid01[x,y].elevation = x+10*(y+1)
end
end
end
describe “restored serialized grid object” do
it “matches origional grid object.” do
grid02 = Grid.allocate
Serial.write(grid01,“testtemp01”)
grid02 = Serial.read(grid02,“testtemp01”)
grid01[9,9].elevation.should == grid02[9,9].elevation
end
end
end
end
----- End Code -----
But when I run it it seems that the Grid object created in the
before(:all) hook is not available to the example [see below].
Why is this?
----- Start Run -----
rich@richlaptop2:~/Documents/fakemap/rspec$ rspec serialgrid.rb
Serial
Given a grid with the block test pattern
restored serialized grid object
matches origional grid object. (FAILED - 1)
Failures:
- Serial Given a grid with the block test pattern restored
serialized grid object matches origional grid object.
Failure/Error: Serial.write(grid01,“testtemp01”)
NameError:
undefined local variable or method `grid01’ for
#RSpec::Core::ExampleGroup::Nested_1::Nested_1::Nested_1:0xb7677a0c./serialgrid.rb:20
Finished in 0.00698 seconds
1 example, 1 failure
rich@richlaptop2:~/Documents/fakemap/rspec$
----- End Run -----
I am running rspec 2.4.0 and ruby 1.8.7
–
Rich P.
[email protected]