[rspec-users] Problems with testing nested routes using mocking

Jesper Laursen powerlauer at gmail.com
Mon Oct 1 18:33:02 EDT 2007

2007/10/1, Jarkko Laine <jarkko at jlaine.net>:
> On 1.10.2007, at 18.25, Jesper Laursen wrote:
> > Okay, now it seems til work.
> > The problem has what I have to place:
> >      @domain.virtual_hosts.should_receive(:find).with
> > ("1").and_return(@virtual_host)
> > in the before, because the  "do_get" method was using it, in all it-
> > blocks.
> >
> > I just think that my before are pretty big.
> > And I have to copy it for every describtion.
> You could wrap it in a helper method in a module that you can include
> and call in the specs instead of repeating all the lines.

Yes, I know, but not all the code have to be used every time.
Now I have a new problem. It know work in a browser, but if i am
running autotest, this error raise:

/opt/local/bin/ruby -S script/spec -O spec/spec.opts

ActionView::TemplateError in '/virtual_hosts/show.rhtml should render
attributes in <p>'
edit_virtual_host_url failed to generate from
{:controller=>"virtual_hosts", :domain_id=>"1001", :action=>"edit"},
expected: {:controller=>"virtual_hosts", :action=>"edit"}, diff:
On line #92 of app/views/virtual_hosts/show.rhtml

    89: </p>
    92: <%= link_to 'Edit', edit_virtual_host_path(@virtual_host) %> |
    93: <%= link_to 'Back', virtual_hosts_path %>

my before do in show.rhtml_sprec.rb looks like this
  before do
    @domain = mock_model(Domain)

    @virtual_host = mock_model(VirtualHost)

    assigns[:domains] = @domain
    assigns[:virtual_host] = @virtual_host

More information about the rspec-users mailing list