Hi list,
I can’t figure out why this doesn’t do what I expected…
Spec file:
context “showing Ruby reference materials” do
it “should open the rspec book in preview” do
require “sean/preview”
class << ApplicationScripting::Preview
def self.reference
preview = double(‘Preview’)
preview.should_receive(:open).with(’…/the-rspec-book_b12_0.pdf’)
end
end
require "sean/vim"
class << ApplicationScripting::Vim
def self.reference
vim = double('Vim')
end
end
VimPlugin::show_ruby_reference_materials
end
end
Library file
class VimPlugin
def self.show_ruby_reference_materials
require “sean/preview”
preview = ApplicationScripting::Preview.reference
preview.open ‘/Users/sean/Downloads/the-rspec-book_b12_0.pdf’
require "sean/vim"
vim_screen = ApplicationScripting::Vim.reference.window(1).screen
require "sean/screen"
another_screen = System::Screen::screens.detect { |s| s !=
vim_screen }
preview.window(1).frame = another_screen.available_frame
preview.activate
end
end
I was hoping that in the spec/test code, the mocked out version would be
called, but it used the regular implementations instead. I’m guessing
that “self” is not being changed in the definitions, but if I open up
the classes like:
module ::ApplicationScripting
class Preview
def self.reference
preview = double(‘Preview’)
preview.should_receive(:open).with(’…/the-rspec-book_b12_0.pdf’)
end
end
end
I get “undefined method `double’ for ApplicationScripting::Preview”
I’m out of ideas and I’m not getting what’s going on on a deeper level
here.
Thanks in advance!
Sean DeNigris