Hello,
I am trying to execute controller spec but it gives me error which
says
@controller is nil: make sure you set it in your test's setup
method.
I tried to search for the solution but till now no success
Following is the description of the controller spec.
describe ChannelCategoriesController do
context âAdminâ do
before(:each) do
@cha_category = ChannelCategory.new
end
it "should delete categories" do
delete :destroy, :id => 1
end
end
end
Please advice
On Fri, May 8, 2009 at 4:03 AM, Amit K. [email protected]
wrote:
Following is the description of the controller spec.
delete :destroy, :id => 1
end
end
end
Please advice
Questions:
- ruby version
- rspec version
- rails version
- OS
- whatâs the path to the file
- how are you running the spec (rake, spec command, etc)
- pls provide a full backtrace
- best in a gist or pastie
- script/spec path/to/file --backtrace
Cheers,
David
Questions:
[âŚ]
- pls provide a full backtrace
Imagine someone looking at the problem report
two years from now. No pastie. Then the
solution (if provided) comes without a complete problem.
Like code without a test.
Put it in an attachment, or whatever, but keep the two together,
please.
Bye,
Kero.
How can I change the world if I canât even change myself?
â Faithless, Salva Mea
On Tue, May 19, 2009 at 3:30 AM, Amit K. [email protected]
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.
}
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.
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?
Hi,
Thanks for quick response
My channels_controller_spec.rb file is inside controller spec only
i.e. PROJECT_ROOT/spec/controllers/channels_controller_spec.rb.
As per your suggestion i removed the setup method and moved
user_attributes under example groups.
but i am getting the same error which says RuntimeError in
âChannelsController Brand Manager should not create channelâ
@controller is nil: make sure you set it in your testâs setup method.
Still confused why is this coming again.
Following is the backtrace(Regarding aâs its a minor prob.will do it)
RuntimeError in âChannelsController Brand Manager should not create
channelâ
@controller is nil: make sure you set it in your testâs setup method.
C:/Program
Files/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_control
ler/test_process.rb:378:in process' C:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_control ler/test_process.rb:376:in
eachâ
C:/Program
Files/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_control
ler/test_process.rb:376:in process' C:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_control ler/test_process.rb:365:in
postâ
./channels_controller_spec1.rb:149:
C:/Program
Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/example/exampl
e_methods.rb:40:in instance_eval' C:/Program Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/example/exampl e_methods.rb:40:in
executeâ
C:/Program Files/ruby/lib/ruby/1.8/timeout.rb:48:in timeout' C:/Program Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/example/exampl e_methods.rb:37:in
executeâ
C:/Program
Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/example/exampl
e_group_methods.rb:207:in run_examples' C:/Program Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/example/exampl e_group_methods.rb:205:in
eachâ
C:/Program
Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/example/exampl
e_group_methods.rb:205:in run_examples' C:/Program Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/example/exampl e_group_methods.rb:103:in
runâ
C:/Program
Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/runner/example
_group_runner.rb:23:in run' C:/Program Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/runner/example _group_runner.rb:22:in
eachâ
C:/Program
Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/runner/example
_group_runner.rb:22:in run' C:/Program Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/runner/options .rb:119:in
run_examplesâ
C:/Program
Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/lib/spec/runner/command
_line.rb:9:in run' C:/Program Files/ruby/lib/ruby/gems/1.8/gems/rspec-1.2.6/bin/spec:4 C:/Program Files/ruby/bin/spec:19:in
loadâ
C:/Program Files/ruby/bin/spec:19
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.
� �}
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.
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?
On Tue, May 19, 2009 at 9:04 AM, Amit K. [email protected]
wrote:
but i am getting the same error which says Ă RuntimeError in
Files/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_control
./channels_controller_spec1.rb:149:
It looks like youâre calling the file from the spec/controllers
directory. Just for fun, step up to the project root and run:
script/spec spec/controllers/channels_controller_spec1.rb
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
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
def user_attributes
{
:login => âfooâ,
:password => âfoobarâ,
:password_confirmation => âfoobarâ,
:email => â[email protected]â,
:privacy => â1â,
:idiom => nil,
:role_id => 2
}
end
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.
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
David C. wrote:
On Tue, May 19, 2009 at 9:04 AM, Amit K. [email protected]
wrote:
but i am getting the same error which says RuntimeError in
Files/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_control
./channels_controller_spec1.rb:149:
It looks like youâre calling the file from the spec/controllers
directory. Just for fun, step up to the project root and run:
script/spec spec/controllers/channels_controller_spec1.rb
Hey It worked thanks a lot.
Can you tell me the difference why it was not running earlier and now it
is running.Just for my understanding.
Amit K. wrote:
David C. wrote:
On Tue, May 19, 2009 at 9:04 AM, Amit K. [email protected]
wrote:
but i am getting the same error which says RuntimeError in
Files/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_control
./channels_controller_spec1.rb:149:
It looks like youâre calling the file from the spec/controllers
directory. Just for fun, step up to the project root and run:
script/spec spec/controllers/channels_controller_spec1.rb
Hey It worked thanks a lot.
Can you tell me the difference why it was not running earlier and now it
is running.Just for my understanding.
It is not the case that i will always run spec from the root project.So
if i want to run from spec/controllers direcrtory then what should i do
since i am getting the error.
On Wed, May 20, 2009 at 1:47 AM, Amit K. [email protected]
wrote:
script/spec spec/controllers/channels_controller_spec1.rb
Hey It worked thanks a lot.
Can you tell me the difference why it was not running earlier and now it
is running.Just for my understanding.
It is not the case that i will always run spec from the root project.So
if i want to run from spec/controllers direcrtory then what should i do
since i am getting the error.
Unfortunately, youâre going to have to run it from the project root
because thatâs the only it works, apparently. You can file a bug
report at http://rspec.lighthouseapp.com if youâre interested.
Cheers,
David
David C. wrote:
On Wed, May 20, 2009 at 1:47 AM, Amit K. [email protected]
wrote:
script/spec spec/controllers/channels_controller_spec1.rb
Hey It worked thanks a lot.
Can you tell me the difference why it was not running earlier and now it
is running.Just for my understanding.
It is not the case that i will always run spec from the root project.So
if i want to run from spec/controllers direcrtory then what should i do
since i am getting the error.
Unfortunately, youâre going to have to run it from the project root
because thatâs the only it works, apparently. You can file a bug
report at http://rspec.lighthouseapp.com if youâre interested.
Cheers,
David
Thank a lot.
But is the case that all controller specs are run from the root
directory.
I had had written spec models and it runs fine from inside the spec
directory.
I will sure file a ticket on the site u mentioned.
Also it will be good if i get to know the reason behind this
On Wed, May 20, 2009 at 2:47 AM, Amit K. [email protected]
wrote:
It is not the case that i will always run spec from the root project.So
Thank a lot.
But is the case that all controller specs are run from the root
directory.
I had had written spec models and it runs fine from inside the spec
directory.
I will sure file a ticket on the site u mentioned.
Also it will be good if i get to know the reason behind this
Itâs not by design. Itâs a bug.