# Why doesn't this work?

**URL:** <https://www.ruby-forum.com/t/why-doesnt-this-work/181988>\
**Category:** Ruby\
**Created:** [January 21, 2010, 5:53am UTC](https://www.ruby-forum.com/t/why-doesnt-this-work/181988 "2010-01-21T05:53:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![DeNigris\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cab0a1/32.png) [@DeNigris\_S](https://www.ruby-forum.com/u/DeNigris_S)\
**Post date:** [January 21, 2010, 5:53am UTC](https://www.ruby-forum.com/t/why-doesnt-this-work/181988/1 "2010-01-21T05:53:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![DeNigris\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cab0a1/32.png) [@DeNigris\_S](https://www.ruby-forum.com/u/DeNigris_S)\
**Post date:** [January 21, 2010, 5:44pm UTC](https://www.ruby-forum.com/t/why-doesnt-this-work/181988/2 "2010-01-21T17:44:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![DeNigris\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cab0a1/32.png) [@DeNigris\_S](https://www.ruby-forum.com/u/DeNigris_S)\
**Post date:** [January 22, 2010, 1:59am UTC](https://www.ruby-forum.com/t/why-doesnt-this-work/181988/3 "2010-01-22T01:59:42Z")

</div>

> 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
