rails3 rspec issue

蹲街弑〆低调 提交于 2019-12-05 19:50:44

I'm having the same problem. At the end of Chapter 5, tests from /spec/requests/layout_links_spec.rb are all failing with the same error (the controller tests work just fine):

Failure/Error: Unable to find matching line from backtrace 
stack level too deep
# C:/Ruby192/lib/ruby/1.9.1/forwardable.rb:185

After doing a little troubleshooting on the /spec/requests/layout_links_spec.rb file, it appears that using response within this context is what triggers the problem. For example, there is no error if the file reads as follows:

require 'spec_helper'

describe "LayoutLinks" do

    it "should run tests properly from this file" do
        get '/'
    end
end

But the file as copied from the tutorial reads:

require 'spec_helper'

describe "LayoutLinks" do

  it "should have a Home page at '/'" do
    get '/'
    response.should have_selector('title', :content => "Home")
  end

  it "should have a Contact page at '/contact'" do
    get '/contact'
    response.should have_selector('title', :content => "Contact")
  end

  it "should have an About page at '/about'" do
    get '/about'
    response.should have_selector('title', :content => "About")
  end

  it "should have a Help page at '/help'" do
    get '/help'
    response.should have_selector('title', :content => "Help")
  end
end

The error is thrown as soon as response is called

This is on Windows 7 (I've attempted to setup Ruby, Git, Vim, and other development tools at the system level rather than within Cygwin).

Rspeicher - following RailsTutorial.org's steps, the /config/routes.rb file looks something like this:

SampleApp::Application.routes.draw do
 get "users/new"

 match '/signup', :to => 'users#new'

 match '/contact', :to => 'pages#contact'
 match '/about', :to => 'pages#about'
 match '/help', :to => 'pages#help'

 root :to => 'pages#home'
end

like Arun says, this all works as intended in the browser, so the issue seems to be somewhere within rspec or ruby. I suppose this isn't a problem if ruby is installed under Cygwin. I was hoping to not have to revert to a pure Cygwin environment, especially since my webroot and project files are already managed outside of Cygwin's virtual unix folder structure.

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.

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?

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

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.

It definitely has nothing to do with Windows or any environment you have there. I am experiencing the same thing with my Mac.

my routes.rb file (From the same tutorial) looks like this:

SampleApp::Application.routes.draw do

  resources :users

  match '/signup', :to => 'users#new'
  match '/contact', :to => 'pages#contact'
  match '/about', :to => 'pages#about'
  match '/help', :to => 'pages#help'

end

You could also try running

bundle exec rake db:test:prepare
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!