On Mon, Feb 8, 2010 at 11:58 AM, Phillip K.
[email protected] wrote:
help more than me with the specifics.
project. So if anyone knows how to test a controller plugin with RSpec
independent of a project, I’d really appreciate some pointers.
The problem I’ve run into in trying to spec controller extensions in
isolation is that Rails controllers are not self-contained objects:
they need a bunch of surrounding state set up for them to work
properly. The testing facilities that ship with Rails hide that all
from you, but they do a lot of work for you in every test method, or
rspec code example.
In theory, you should be able to say:
class SomeController < ActionController::Base
render :text => “this text”
describe SomeController do
describe “index” do
it “returns some text” do
c = SomeController.new
c.index.should == “this text”
When you do, however, you get this:
uninitialized constant ActionController::Metal (NameError)
Try to solve that and you’ll be starting down a deep rabbit hole. And
even if you do solve that, the next rails release may well break
whatever you did to solve it. The safest bet is to spec your plugin in
the context of a complete rails app.
That said, I’d love to make this easier to do with rspec, but I won’t
have cycles to drive this for quite some time. If anyone else is
interested in driving this, speak up and I’ll be happy to assist.