Why doesn't this work?

D

DeNigris Sean

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 =3D 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 =3D 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 =3D ApplicationScripting::preview.reference
preview.open =
'/Users/sean/Downloads/the-rspec-book_b12_0.pdf'

require "sean/vim"
vim_screen =3D =
ApplicationScripting::Vim.reference.window(1).screen

require "sean/screen"
another_screen =3D System::Screen::screens.detect { |s| =
s !=3D vim_screen }
preview.window(1).frame =3D =
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 =3D 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
 
W

Walton Hoops

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.
 
D

DeNigris Sean

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=
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,067
Latest member
HunterTere

Latest Threads

Top