views:

522

answers:

5

Hey Guys!

I am trying out rails3. I am using railstutorial site to explore more about rails3; the tutorial is very good to begin with (I have minimal experience with rails2).

I have an issue with rspec which is currently blocking my progress. I saw that the tutorial recommended using rspec2.0.0.beta.18 gem; I instead installed rspec2.0.0.beta.20 gem using

bundle install

However I find issues with this version of rspec My rspec for integration_test looks like:

describe "LayoutLinks" do
  it "should have a About page at '/about'" do  
    get '/about'
    response.should have_selector('h1', :content => "About Us")
  end 
end

The failure looks like:

Failures:
  1) LayoutLinks should have a About page at '/about'
     Failure/Error: Unable to find matching line from backtrace
     stack level too deep
     # /home/arun/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/forwardable.rb:185

(NOTE: Those who have looked at Chapter 5 will not have issues understanding the context.)

If I change rspec version to 2.0.0.beta.18 in the Gemfile and run rspec I get the following error

arun@ubuntu-world:~/Project/Rails/rails3/sample_app$ rspec spec/
/home/arun/.rvm/gems/ruby-1.9.2-p0/gems/bundler-1.0.0/lib/bundler/runtime.rb:27:in `block in setup': You have already activated rspec-core 2.0.0.beta.20, but your Gemfile requires rspec-core 2.0.0.beta.18. Consider using bundle exec. (Gem::LoadError)
        from /home/arun/.rvm/gems/ruby-1.9.2-p0/gems/bundler-1.0.0/lib/bundler/spec_set.rb:12:in `block in each'
        from /home/arun/.rvm/gems/ruby-1.9.2-p0/gems/bundler-1.0.0/lib/bundler/spec_set.rb:12:in `each'
        from /home/arun/.rvm/gems/ruby-1.9.2-p0/gems/bundler-1.0.0/lib/bundler/spec_set.rb:12:in `each'
        from /home/arun/.rvm/gems/ruby-1.9.2-p0/gems/bundler-1.0.0/lib/bundler/runtime.rb:17:in `setup'
        from /home/arun/.rvm/gems/ruby-1.9.2-p0/gems/bundler-1.0.0/lib/bundler.rb:100:in `setup'
        from /home/arun/Project/Rails/rails3/sample_app/config/boot.rb:8:in `<top (required)>'
        from <internal:lib/rubygems/custom_require>:29:in `require'
        from <internal:lib/rubygems/custom_require>:29:in `require'
        from /home/arun/Project/Rails/rails3/sample_app/config/application.rb:1:in `<top (required)>'
        from <internal:lib/rubygems/custom_require>:29:in `require'
        from <internal:lib/rubygems/custom_require>:29:in `require'
        from /home/arun/Project/Rails/rails3/sample_app/config/environment.rb:2:in `<top (required)>'
        from <internal:lib/rubygems/custom_require>:29:in `require'
        from <internal:lib/rubygems/custom_require>:29:in `require'
        from /home/arun/Project/Rails/rails3/sample_app/spec/spec_helper.rb:3:in `<top (required)>'
        from <internal:lib/rubygems/custom_require>:29:in `require'
        from <internal:lib/rubygems/custom_require>:29:in `require'
        from /home/arun/Project/Rails/rails3/sample_app/spec/requests/layout_links_spec.rb:1:in `<top (required)>'
        from /home/arun/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/configuration.rb:302:in `load'
        from /home/arun/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/configuration.rb:302:in `block in load_spec_files'
        from /home/arun/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/configuration.rb:302:in `map'
        from /home/arun/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/configuration.rb:302:in `load_spec_files'
        from /home/arun/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/command_line.rb:18:in `run'
        from /home/arun/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/runner.rb:46:in `run_in_process'
        from /home/arun/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/runner.rb:37:in `run'
        from /home/arun/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rspec/core/runner.rb:10:in `block in autorun'
A: 

The second error should be fixed by re-running bundle install whenever you change your Gemfile.

As for the first error, could you post the lines from your routes.rb file where you define the '/about' route?

rspeicher
A: 

Hi Rspeicher,

I ran "bundle install" again and when I look at Gemfile and Gemfile.lock I find the appropriate gems being bundled whether I use 2.0.0.beta.18 or 2.0.0.beta.20.

routes.rb maps /about to some specific action belonging to a specific controller. I also get the correct page when I visit the page in my browser; so I do not think that could be the issue. (Unfortunately I do not have the code with me right now and can't paste it here)

The following is the error which I cannot understand

arun@ubuntu-world:~/Project/Rails/rails3/sample_app$ rspec spec/
/home/arun/.rvm/gems/ruby-1.9.2-p0/gems/bundler-1.0.0/lib/bundler/runtime.rb:27:in `block in setup': You have already activated rspec-core 2.0.0.beta.20, but your Gemfile requires rspec-core 2.0.0.beta.18. Consider using bundle exec. (Gem::LoadError)

I do know what bundle exec is, let alone how to use it...

-- Arun

arun kumar
A: 

You need to remove one of the gems using gem uninstall:

$ gem uninstall rspec-core -v 2.0.0.beta.20

You can also use gem list to view the which versions of the gems you have installed.

Ben Hanzl
A: 

Rspec had been working fine for 11 chapters of Hartl's tutorial. But somehow I messed with my gemfille and I started to get the same problem with rspec "stack levels too deep" and not being able to resolve by a 'bundle install'. So I went wild and did a

windows> gem uninstall rspec rspec-rails rspec-expectations rspec-mock rspec-core

(All versions). 'gem list' showed they were indeed all gone. Then I executed a

> bundle install
...
Using rspec-core (2.0.0.beta.22)
Using rspec-expectations (2.0.0.beta.22)
Using rspec-mocks (2.0.0.beta.22)
Using rspec (2.0.0.beta.22)
Using rspec-rails (2.0.0.beta.22)
...

Which is what is in my Gemfile. However, a 'gem list -d rspec' still shows -no- rspec or rspec-xxx gems installed and rspec-core problems...

> rails g rspec:install       *#for good measure*
...
> rspec -v
C:/Ruby192/lib/ruby/1.9.1/rubygems.rb:762:in `report_activate_error': Could not 
find RubyGem rspec-core (>= 0) (Gem::LoadError)

But 'bundle list' says it is installed. So how do I get rspec working again?


UPDATE

I fixed the problem, but first my humblest apologies to arun kumar for camping on his question and coming in between it and an answer. I thought my problem was similar and that my "answer" would be place at the end.

First of all, I had to do a

> gem install rspec -v 2.0.0.beta.22
> gem install rspec-rails -v 2.0.0.beta.22

instead of expecting bundler to do it. bundler does not seem reliable here. This got my calls to rspec working again, but I still had to deal with "stack levels too deep." That was fixed by upgrading rspec and rspec-rails to 2.0.1 (from David Chelimski: http://www.ruby-forum.com/topic/282245). Again changing my Gemfile and calling bundle-install didn't work. I had to uninstall all five rspec-xxx gems like above and manually do

> gem install rspec -v 2.0.1
> gem install rspec-rails -v 2.0.1

maybe I didn't need to uninstall first, but I did. The poster has likely already fixed his problem since it was so long ago, but here is my solution that may work for others -- recall I have Windows Vista64.

Cab Jones
A: 

Hi Cab Jones,

I run into the same problem. Then I updated the rails to 3.0.1, rspec to 2.0.1, rspec-rails to 2.0.1, webrat to 0.7.2. But when I run the integration tests, it shows the same error again.

Any idea? Thanks.

Lipu