Forum: RSpec rspec - undefined method `describe' for main:Object

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
76e01275c026bca5c46b2cb5e1ce174a?d=identicon&s=25 Mano ah (manoah)
on 2008-10-10 08:56

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 method `describe' 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:in `re
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:in `load'
        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
944f769c99deff7aa8bc3b5b93830b7a?d=identicon&s=25 Scott Taylor (Guest)
on 2008-10-10 15:46
(Received via mailing list)
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
76e01275c026bca5c46b2cb5e1ce174a?d=identicon&s=25 Mano ah (manoah)
on 2008-10-11 05:16
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
76e01275c026bca5c46b2cb5e1ce174a?d=identicon&s=25 Mano ah (manoah)
on 2008-10-11 05:50
How to solve the below error

1)
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:

2)
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
944f769c99deff7aa8bc3b5b93830b7a?d=identicon&s=25 Scott Taylor (Guest)
on 2008-10-11 06:04
(Received via mailing list)
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/cont...

Scott
944f769c99deff7aa8bc3b5b93830b7a?d=identicon&s=25 Scott Taylor (Guest)
on 2008-10-11 06:09
(Received via mailing list)
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

4. 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
76e01275c026bca5c46b2cb5e1ce174a?d=identicon&s=25 Mano ah (manoah)
on 2008-10-11 06:42
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
944f769c99deff7aa8bc3b5b93830b7a?d=identicon&s=25 Scott Taylor (Guest)
on 2008-10-11 06:53
(Received via mailing list)
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
76e01275c026bca5c46b2cb5e1ce174a?d=identicon&s=25 Mano ah (manoah)
on 2008-10-11 07:12
Scott Taylor 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?
E7cff3cfd41c495e1012227d7dc24202?d=identicon&s=25 Luis Lavena (luislavena)
on 2008-10-11 07:29
(Received via mailing list)
On Fri, Oct 10, 2008 at 3:56 AM, Mano ah <lists@ruby-forum.com> 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 Lavena
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
76e01275c026bca5c46b2cb5e1ce174a?d=identicon&s=25 Mano ah (manoah)
on 2008-10-11 08:44
Luis Lavena wrote:
> On Fri, Oct 10, 2008 at 3:56 AM, Mano ah <lists@ruby-forum.com> 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 Lavena
> 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
76e01275c026bca5c46b2cb5e1ce174a?d=identicon&s=25 Mano ah (manoah)
on 2008-10-11 08:53
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>
42172acdf3c6046f84d644cb0b94642c?d=identicon&s=25 Pat Maddox (pergesu)
on 2008-10-11 12:45
(Received via mailing list)
Dude, post your code
76e01275c026bca5c46b2cb5e1ce174a?d=identicon&s=25 Mano ah (manoah)
on 2008-10-11 12:59
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
E7cff3cfd41c495e1012227d7dc24202?d=identicon&s=25 Luis Lavena (luislavena)
on 2008-10-11 17:16
(Received via mailing list)
On Sat, Oct 11, 2008 at 7:59 AM, Mano ah <lists@ruby-forum.com> 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:

http://rspec.info

>
> 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
http://github.com/dchelimsky/rspec-rails/wikis

HTH,
--
Luis Lavena
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
5d38ab152e1e3e219512a9859fcd93af?d=identicon&s=25 David Chelimsky (Guest)
on 2008-10-11 17:42
(Received via mailing list)
On Sat, Oct 11, 2008 at 10:16 AM, Luis Lavena <luislavena@gmail.com>
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 :)
76e01275c026bca5c46b2cb5e1ce174a?d=identicon&s=25 Mano ah (manoah)
on 2008-10-14 08:32
Thank you Pat Maddox,Douglas Adams,Luis Lavena,Scott Taylor 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.
This topic is locked and can not be replied to.