[rspec-users] Writing specs for a plugin module for ActionController
David Chelimsky
dchelimsky at gmail.com
Tue Aug 5 23:41:41 EDT 2008
On Thu, Jul 31, 2008 at 2:02 PM, Leslie Freeman
<lesliefreeman3 at gmail.com> wrote:
> Hello,
> I'm trying to spec a plugin that includes a module that adds functionality
> to ActionController below is what I've come up with:
>
> # vendor/plugins/custom_attribute_fu/spec/active_record_spec.rb
> require File.dirname(__FILE__) + '/spec_helper'
>
> class TestPerson < ActiveRecord::Base
> end
>
> class TestPeopleController < ActionController::Base
> #calling defines_custom_attributes should add the
> custom_attribute_definitions method, I've defined it explicitly for now to
> just get the tests running
> #defines_custom_attributes
>
> def custom_attribute_definitions
> end
> end
>
> describe TestPeopleController do
>
> describe "handling GET /custom_attribute_definitions" do
>
> before(:each) do
> @controller = TestPeopleController.new
> @request = ActionController::TestRequest.new
> @response = ActionController::TestResponse.new
> end
>
> def do_get
> get :custom_attribute_definitions
> end
>
> it "should be successful" do
> do_get
> response.should be_success
> end
>
> end
> end
>
> When I run the spec I get:
>
> 1)
> ActionView::TemplateError in 'TestPeopleController handling GET
> /custom_attribute_definitions should be successful'
> undefined method `custom_attribute_definitions' for TestPerson(id: integer,
> name: string):Class
>
> What I don't understand is that why get :custom_attribute_definitions is
> trying to call that method on TestPerson rather than TestPersonController.
>
> I'm sure there's a better way to set this up - any advice would be greatly
> appreciated!
I get a very different result. Here's what I did:
$ rails foo
$ cd foo
$ script/plugin install git://github.com/dchelimsky/rspec.git
$ script/plugin install git://github.com/dchelimsky/rspec-rails.git
$ script/generate rspec
$ mkdir vendor/plugins/custom_attribute_fu
$ mkdir vendor/plugins/custom_attribute_fu/spec
$ touch vendor/plugins/custom_attribute_fu/spec/spec_helper.rb
$ touch vendor/plugins/custom_attribute_fu/spec/active_record_spec.rb
Then I added the text you posted above to active_record_spec.rb and
the following to spec_helper.rb:
require File.join(File.dirname(__FILE__), *%w[.. .. .. .. spec spec_helper])
Then, from the RAILS_ROOT:
$ rake spec:plugins
F
1)
ActionView::MissingTemplate in 'TestPeopleController handling GET
/custom_attribute_definitions should be successful'
This is with rails 2.1 and the latest rspec (from git).
Am I doing something different from what you did?
More information about the rspec-users
mailing list