Rspec - undefined method `describe' for main:Object

When i run a spec file i am getting the following error

D:\Diwakar\spec_diwa\spec\controllers>spec sandbox_controller_spec.rb
c:/ruby/lib/ruby/gems/1.8/gems/rspec-0.5.15/lib/spec/api/sugar.rb:17:in
method_ missing': undefined methoddescribe’ for main:Object (NoMethodError)
from ./sandbox_controller_spec.rb:7
from
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:28:in ge m_original_require' from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:28:inre
quire’
from c:/ruby/lib/ruby/gems/1.8/gems/rspec-0.5.15/bin/spec:13
from c:/ruby/lib/ruby/gems/1.8/gems/rspec-0.5.15/bin/spec:7:in
each' from c:/ruby/lib/ruby/gems/1.8/gems/rspec-0.5.15/bin/spec:7 from c:/ruby/bin/spec:19:inload’
from c:/ruby/bin/spec:19

My spec controller is

require File.dirname(FILE) + ‘/…/spec_helper’
#require ‘./…/…/vendor/generators/rspec/lib/rspec_on_rails’
#require ‘sandbox_controller.rb’
require ‘spec’
gem ‘rspec’

describe SandboxController,“handling someaction” do

it “should get real value 10” do

get :someaction

assigns[:value].should equal(10)

end

end

My controller is

class SandboxController < ApplicationController

def someaction

@value = somemethod

end

protected

def somemethod

return 10

end

end

Please help me to solve the issue

On Oct 10, 2008, at 2:56 AM, Mano ah wrote:

   from ./sandbox_controller_spec.rb:7
   from c:/ruby/bin/spec:19:in `load'
   from c:/ruby/bin/spec:19

My spec controller is

require File.dirname(FILE) + ‘/…/spec_helper’

What’s in this file?

#require ‘./…/…/vendor/generators/rspec/lib/rspec_on_rails’

You wont’ need this.

#require ‘sandbox_controller.rb’

You won’t need this one, either

require ‘spec’

Nor this

gem ‘rspec’

Nor this.

end

end

My controller is

Why do you have a controller already?

Scott

Dear Scott,

I am new to rspec and i am confused to test using it.

Can you please help me with an easy example or link to get clear
about it

Regards
M

How to solve the below error

NoMethodError in ‘LoginController index should get successfully’
You have a nil object when you didn’t expect it!
The error occurred while evaluating nil.status
./login_controller_spec.rb:9:

NoMethodError in ‘LoginController index should render 202 file’
undefined method `render_template’ for
#<Spec::Example::ExampleGroup::Subclass_1
:0x47bc128>
./login_controller_spec.rb:13:

Finished in 0.437 seconds

On Oct 10, 2008, at 11:50 PM, Mano ah wrote:

undefined method `render_template’ for
#<Spec::Example::ExampleGroup::Subclass_1
:0x47bc128>
./login_controller_spec.rb:13:

“Spec::Example::ExampleGroup::Subclass_1” - this part suggests it’s
not running as a controller spec. A few things:

  1. Is the file in correct path? It should be in the path
    #{RAILS_ROOT}/spec/controller/my_controller_spec.rb

  2. Have you installed the two plugins, and run “script/generate rspec” ?

  3. (I don’t recommend this, but:) You can force this to run as a
    controller spec by passing a :type => :controller to describe, like so:

describe “my controller”, :type => :controller do

end

  1. Worse comes to worse, try running the generator to get some example
    code:

./script/generate rspec_controller MyController

That should generate a sample spec. You could work from there.

Hope that helps,

Scott

On Oct 10, 2008, at 11:50 PM, Mano ah wrote:

undefined method `render_template’ for
#<Spec::Example::ExampleGroup::Subclass_1
:0x47bc128>
./login_controller_spec.rb:13:

Looks like you’re writing controller specs. Have you checked out the
rspec site? Specifically:

http://rspec.info/documentation/rails/writing/controllers.html

Scott

rails 2.1.1 and rspec 1.1.8 never worked out for me

So i downgraded rails to 1.2.3.

while execiting ruby /script/generate rspec_controller MyController

it ask rails version 2.1.1.

i was getting the describe method error as mention earlier in using
2.1.1

On Oct 11, 2008, at 12:42 AM, Mano ah wrote:

2.1.1
Why don’t you post your spec? It would be a lot easier to help if we
could look at the same thing you were looking at.

Scott

Scott T. wrote:

On Oct 11, 2008, at 12:42 AM, Mano ah wrote:

2.1.1
Why don’t you post your spec? It would be a lot easier to help if we
could look at the same thing you were looking at.

Scott

sorry spec?

On Fri, Oct 10, 2008 at 3:56 AM, Mano ah [email protected] wrote:

c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:28:in `ge

describe SandboxController,“handling someaction” do

@value = somemethod

end

end

Please help me to solve the issue

Sorry, jumping late on this issue.

It appears you’re calling ‘spec’ from the command line, which is
loading your installed gem of RSpec.

Based on the output of the backtrace, it appears to be version 0.5.15

You should have used “ruby script/spec” from the root of your rails
application instead.

Also, if you changed versions of Rails, you need to update
config/environment.rb to match the Rails gem version since you
downgraded to 1.2.3 but forgot to change that file.

I suggest you do this:

gem install rake
gem install rails
gem install rspec
gem install rspec-rails

rails my-test-app
cd my-test-app
ruby script/generate rspec
rake spec

That, at least, should work and not generate empty errors (well, I’ve
skipped database setup, controller and such, please add those after).

HTH,

Luis L.
AREA 17

Human beings, who are almost unique in having the ability to learn from
the experience of others, are also remarkable for their apparent
disinclination to do so.
Douglas Adams

Luis L. wrote:

On Fri, Oct 10, 2008 at 3:56 AM, Mano ah [email protected] wrote:

c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:28:in `ge

describe SandboxController,“handling someaction” do

@value = somemethod

end

end

Please help me to solve the issue

Sorry, jumping late on this issue.

It appears you’re calling ‘spec’ from the command line, which is
loading your installed gem of RSpec.

Based on the output of the backtrace, it appears to be version 0.5.15

You should have used “ruby script/spec” from the root of your rails
application instead.

Thank you for the reply. I done the same and got the below error

** Invoke spec (first_time)
** Execute spec
** Invoke spec:models (first_time)
** Invoke db:test:prepare (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:test:prepare
** Invoke db:test:clone (first_time)
** Invoke db:schema:dump (first_time)
** Invoke environment
** Execute db:schema:dump
** Invoke spec:controllers (first_time)
** Invoke db:test:prepare
** Execute spec:controllers
rake aborted!
RSpec failures
D:/Diwakar/my_spec/config/…/lib/tasks/rspec.rake:13
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:617:in call' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:617:in execute’
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:612:in each' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:612:in execute’
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:578:in
invoke_with_call_c hain' c:/ruby/lib/ruby/1.8/monitor.rb:242:in synchronize’
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:571:in
invoke_with_call_c hain' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:564:in invoke’
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:2019:in
invoke_task' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1997:in top_level’
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1997:in each' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1997:in top_level’
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:2036:in
standard_exceptio n_handling' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1991:in top_level’
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1970:in run' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:2036:in standard_exceptio
n_handling’
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1967:in run' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/bin/rake:31 c:/ruby/bin/rake:19:in load’
c:/ruby/bin/rake:19

Also, if you changed versions of Rails, you need to update
config/environment.rb to match the Rails gem version since you
downgraded to 1.2.3 but forgot to change that file.

I suggest you do this:

gem install rake
gem install rails
gem install rspec
gem install rspec-rails

rails my-test-app
cd my-test-app
ruby script/generate rspec
rake spec

That, at least, should work and not generate empty errors (well, I’ve
skipped database setup, controller and such, please add those after).

HTH,

Luis L.
AREA 17

Human beings, who are almost unique in having the ability to learn from
the experience of others, are also remarkable for their apparent
disinclination to do so.
Douglas Adams

my gem list is

actionmailer (2.1.1, 1.3.3)
actionpack (2.1.1, 1.13.3)
actionwebservice (1.2.3)
activerecord (2.1.1, 1.15.3)
activeresource (2.1.1)
activesupport (2.1.1, 1.4.2)
fxri (0.3.6)
fxruby (1.6.12)
hoe (1.7.0)
hpricot (0.6)
log4r (1.0.5)
rails (1.2.3)
rake (0.8.3)
rspec (1.1.8, 0.5.15)
rspec-rails (1.1.8)
rspec_generator (0.5.15)
rubyforge (1.0.0)
sources (0.0.1)
win32-api (1.0.4)
win32-clipboard (0.4.3)
win32-dir (0.3.2)
win32-eventlog (0.4.6)
win32-file (0.5.4)
win32-file-stat (1.2.7)
win32-process (0.5.3)
win32-sapi (0.1.4)
win32-sound (0.4.1)
win32console (1.1.0)
windows-api (0.2.0)
windows-pr (0.7.2)
ZenTest (3.10.0)

D:\Diwakar\my_spec>

Dude, post your code

I followed the below ways of installation

gem install rake
gem install rails
gem install rspec
gem install rspec-rails

rails my-test-app
cd my-test-app
ruby script/generate rspec

When i used

‘rake spec’

i received no error.

After that I created a controller

then installed the two plugins

ruby script/plugin install
http://rspec.rubyforge.org/svn/tags/CURRENT/rspec
ruby script/plugin install
http://rspec.rubyforge.org/svn/tags/CURRENT/rspec_on_rails

Then i used ‘ruby script/generate rspec_scaffold myspec_con’ which
created the spec for the controller,model etc

Then i used the below command to run the spec file and received the
below error

D:\Diwakar\my_spec\spec>ruby script/spec
controllers/myspec_cons_controller_spec
.rb
ruby: No such file or directory – script/spec (LoadError)

Please give your suggestions

On Sat, Oct 11, 2008 at 10:16 AM, Luis L. [email protected]
wrote:

rails my-test-app
After that I created a controller
through Git repo, please see the install instructions in the website:
I just blew away the contents of CURRENT, leaving a README that points
to relevant information:

http://rspec.rubyforge.org/svn/tags/CURRENT/README

So this confusion over CURRENT should no longer be a problem :slight_smile:

Thank you Pat M.,Douglas Adams,Luis L.,Scott T. for your
kind help.

I have installed the plugins rspec and rspec-rails using git.

I was not running the spec controller from the root thats the main
problem.

I followed all of your useful suggestions and able to build and run a
project

sucessfully.

Thank you once again.

On Sat, Oct 11, 2008 at 7:59 AM, Mano ah [email protected] wrote:

cd my-test-app

then installed the two plugins

ruby script/plugin install
http://rspec.rubyforge.org/svn/tags/CURRENT/rspec
ruby script/plugin install
http://rspec.rubyforge.org/svn/tags/CURRENT/rspec_on_rails

You’re pulling a old SVN repository, latest releases are distributed
through Git repo, please see the install instructions in the website:

Please give your suggestions

You forgot to:

ruby script/generate rspec

This is required for rspec to work, it generates the needed files in
script and also spec folder to make RSpec work.

Please do that and then try executing ruby script/spec.

FYI: There are plenty of tutorials around the web that explain how to
get started with RSpec. I guess english is not your main language and
can be difficult to search for it, but:

google with keywords “rspec rails getting started”:

http://www.jbrains.ca/permalink/127

HTH,

Luis L.
AREA 17

Human beings, who are almost unique in having the ability to learn from
the experience of others, are also remarkable for their apparent
disinclination to do so.
Douglas Adams