[rspec-users] Error in executing controller spec

David Chelimsky dchelimsky at gmail.com
Tue May 19 09:21:47 EDT 2009


On Tue, May 19, 2009 at 3:30 AM, Amit Kulkarni <lists at ruby-forum.com> wrote:
> Ruby version : 1.8.6 (2007-03-13 patchlevel 0) [i386-mswin32]
> rspec - 1.2.4
> rails - 2.1.2
> OS - Vista Home
> I am running a single file by the command
> spec channels_controller(filename)_spec.rb

Where is this file? For rspec-rails to know that it's supposed to be a
controller spec, it either needs to be inside the
PROJECT_ROOT/spec/controllers directory, or you need to change the
describe declaration to this:

describe ChannelsController, :type => :controller do

>
> Contents of the file:
>
> require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
>
> def setup
>  @controller  = ChannelsController.new
>  @request     = ActionController::TestRequest.new
>  @response    = ActionController::TestResponse.new
> end

Get rid of this setup. First of all, RSpec does this for you
automatically inside controller example groups. Secondly, this is
outside any example group (describe block), so it's not related to
anything anyway.

>
> def user_attributes
>    {
>      :login => 'foo',
>      :password => 'foobar',
>      :password_confirmation => 'foobar',
>      :email => 'foo at dibistore.it',
>      :privacy => '1',
>      :idiom => nil,
>      :role_id => 2
>    }
> end

I'd move user_attributes inside the example group too. That way it's
scoped. If not, it's going to be available to (and possibly in
conflict with) any files that get loaded after this one.

> describe ChannelsController do
>    fixtures :channels, :users
>    context "Brand Manager" do
>    @user = User.find_by_login("amit")
>      it "should not create channel" do
>        user = User.new
>        user.attributes = user_attributes
>        post :create, :channel => {:brand_name => 'by manager'}
>      end
>    end
> end
>
> Now when i run this file i get error which says
> RuntimeError in 'ChannelsController Brand Manager should not create
> chnnel'
> @controller is nil: mke sure you set it in your test's setup method.

Uh, where are all the 'a's in the backtrace?

> Backtrace is as follows:
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/ctionpck-2.1.2/lib/ction_controller/
> test_process.rb:378:in `process'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/ctionpck-2.1.2/lib/ction_controller/
> test_process.rb:376:in `ech'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/ctionpck-2.1.2/lib/ction_controller/
> test_process.rb:376:in `process'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/ctionpck-2.1.2/lib/ction_controller/
> test_process.rb:365:in `post'
> ./chnnels_controller_spec.rb:141:
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.4/lib/spec/exmple/exmple_m
> ethods.rb:41:in `instnce_evl'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.4/lib/spec/exmple/exmple_m
> ethods.rb:41:in `execute'
> C:/Progrm Files/ruby/lib/ruby/1.8/timeout.rb:48:in `timeout'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.4/lib/spec/exmple/exmple_m
> ethods.rb:38:in `execute'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.4/lib/spec/exmple/exmple_g
> roup_methods.rb:203:in `run_exmples'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.4/lib/spec/exmple/exmple_g
> roup_methods.rb:201:in `ech'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.4/lib/spec/exmple/exmple_g
> roup_methods.rb:201:in `run_exmples'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.4/lib/spec/exmple/exmple_g
> roup_methods.rb:99:in `run'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.4/lib/spec/runner/exmple_g
> roup_runner.rb:23:in `run'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.4/lib/spec/runner/exmple_g
> roup_runner.rb:22:in `ech'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.4/lib/spec/runner/exmple_g
> roup_runner.rb:22:in `run'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.4/lib/spec/runner/options.
> rb:119:in `run_exmples'
> C:/Progrm
> Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.4/lib/spec/runner/commnd_l
> ine.rb:9:in `run'
> C:/Progrm Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.4/bin/spec:4
> C:/Progrm Files/ruby/bin/spec:19:in `lod'
> C:/Progrm Files/ruby/bin/spec:19
>
> Please Advice
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>


More information about the rspec-users mailing list