Why doesn't this work?

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

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

Well, this is a long shot, but I’m guessing the method ‘double’ which
you
use several times in your code, doesn’t exists. I think the error
message is
pretty clear. To say any more than that, we’d need more information.

Well, this is a long shot, but I’m guessing the method ‘double’ which you
use several times in your code, doesn’t exists. I think the error message is
pretty clear. To say any more than that, we’d need more information.

Thanks for taking a shot, but the method definitely exists - use it
elsewhere in the same file. A little more explanation - it is a method
from Rspec, which is included earlier with require “spec”

The problem is that if I use “class << ApplicationScripting::Preview,”
the new functionality never gets used, but if I use “module
::ApplicationScripting; class Preview;” I can no longer use “double”
inside the class. I tried requiring spec again inside the function as
well as fully qualifying it with Spec::Mocks::ExampleMethods.

Sean