I have just recently started creating some plugins, mainly of the
controller variety. I have been looking for a tutorial or other
documentation detailing how to go about testing these plugins with
RSpec, but have not yet found anything helpful. Can anyone point me
toward such a thing?
I have just recently started creating some plugins, mainly of the
controller variety. I have been looking for a tutorial or other
documentation detailing how to go about testing these plugins with
RSpec, but have not yet found anything helpful. Can anyone point me
toward such a thing?
Create a controller in your specs which uses the plugin in an
exemplary way, then asserts the behaviour of that controller.
Create a controller in your specs which uses the plugin in an
exemplary way, then asserts the behaviour of that controller.
Thanks, Matt. I have some parts of it working now, but am stumped
when trying to call an action. I need to do a post :create, but post
is not a known method. Do you happen to know of a controller plugin
that used RSpec that I could peruse?
Yeah, you need to convince RSpec that the describe blocks youâre using
are describing an ExampleGroup thatâs about a Rails Controller, then
it will mix in the right methods for you. I think you can do something
like:
describe MySpecialTestController, :type => :controller do
end
Thatâs the general idea. I think someone else on the list will be able
to help more than me with the specifics.
As for a plug-in, I donât know any off-hand⊠try a few popular ones
out on github and look for a spec directory in the root I guess.
As for a plug-in, I donât know any off-hand⊠try a few popular ones
out on github and look for a spec directory in the root I guess.
Thanks, again, Matt for taking the time to respond. I was kind of
surprised by how many plugins use test::unit. I did finally find
subdomain_fu [1] and was able to get something working. However, this
approach tests the controller in a project and requires rspec-rails to
be installed for the project. I would really like to be able to test
this independent of a project. So if anyone knows how to test a
controller plugin with RSpec independent of a project, Iâd really
appreciate some pointers.
Thanks, Matt. I have some parts of it working now, but am stumped when
trying to call an action. I need to do a post :create, but post is not a
known method. Do you happen to know of a controller plugin that used
RSpec that I could peruse?
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.
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.
describe MySpecialTestController, :type => :controller do
independent of a project, Iâd really appreciate some pointers.
=================================
describe âindexâ do
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.
So maybe we just need to build a library of helpers that make it easy
to create a modified rails app in Cucumber features?