[rspec-users] Testing controller plugin
phillipkoebbe at gmail.com
Mon Feb 8 12:20:37 EST 2010
David Chelimsky wrote:
> 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:
> require 'rubygems'
> require 'action_controller/base'
> class SomeController< ActionController::Base
> def index
> 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.
Well, there it is. :)
Thanks, David. I prefer to avoid rabbit holes.
More information about the rspec-users