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'
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
来源:https://stackoverflow.com/questions/3695504/rails3-rspec-issue