Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing nested namespaced controller with RSpec 2 and Rails3

I feel that code will speak more than words in this case, so place to The code :

config/routes.rb

namespace :embed do
  namespace :v1 do
    resources :articles
  end
end

app/controllers/embed/v1/articles_controller.rb

class Embed::V1::ArticlesController < ApplicationController
  def index
    render :text => 'ok'
  end
end

spec/controllers/embed/v1/articles_controller_spec.rb

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

describe Embed::V1::ArticlesController do
  it "should do something" do
    get :new
  end
end

Running rspec spec

$ rspec spec
F

Failures:

  1) Embed::V1::ArticlesController should do something
     Failure/Error: get :new
     AbstractController::ActionNotFound:
       The action 'new' could not be found for Embed::V1::ArticlesController
     # ./spec/controllers/embed/v1/articles_controller_spec.rb:5

Finished in 0.01665 seconds
1 example, 1 failure

Any idea why is that? Is there a nested limitation? Accessing the url http://0.0.0.0:3000/embed/v1/articles renders ok as expected.

like image 524
Sébastien Grosjean - ZenCocoon Avatar asked Mar 16 '11 14:03

Sébastien Grosjean - ZenCocoon


2 Answers

You don't have a the new action defined in Embed::V1::ArticlesController, only the index action. You are trying to hit the new action in your specs with get :new.

like image 123
raidfive Avatar answered Nov 08 '22 21:11

raidfive


You should define the action new, in your code you didn't defined in controller the new action and called on rspec the new action!

like image 1
frederico Avatar answered Nov 08 '22 23:11

frederico