Search code examples
ruby-on-rails-3rspec2refinerycms

How to write RefineryCMS controller tests without RoutingError


An Rspec test like this (actually taken from RefineryCMS' own test suite)

require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

module Refinery
  describe FastController do
    it "should render the wymiframe template" do
      get :wymiframe
      response.should be_success
    end
  end
end

Results in the following error:

Failure/Error: get :wymiframe
ActionController::RoutingError:
  No route matches {:controller=>"refinery/fast", :action=>"wymiframe"}
# ./spec/controllers/fast_controller_spec.rb:6:in `block (2 levels) in <module:Refinery>'

In this case, I'm using refinery 2.0.8 with Rspec 2.11, and the relevant section after running rake routes looks like:

wymiframe GET     /wymiframe(/:id)(.:format)        refinery/fast#wymiframe

I have tried a few other controller Rspecs which also fail with routing errors. I am of course trying to write tests for my own extra methods I am adding to vanilla Refinery controllers, but just thought I'd see if I could get a controller test working for a totally fresh refinery install.

This must be a simple mistake! Any suggestions?


Solution

  • I stumbled upon this by accident. Instead of:

    get :wymiframe
    

    I needed to use:

    get :wymiframe, { use_route: :any_old_thing }
    

    I don't know why this worked - especially since for "any_old_thing", I really used nothing meaninful or connected tomy project at all. But, it seems to have worked, and now I can test my controllers.