铁路3 rspec问题

铁路3 rspec问题,rspec,bundler,rspec2,Rspec,Bundler,Rspec2,我正在试火车。我正在使用 网站了解更多关于rails3的信息;本教程从一开始就非常好(我对rails2的经验很少) 我与rspec有一个问题,目前阻碍了我的进度。我看到教程推荐使用rspec2.0.0.beta.18 gem;我改为使用安装rspec2.0.0.beta.20 gem bundle install 但是,我发现这个版本的rspec存在问题 我的集成测试rspec如下所示: describe "LayoutLinks" do it "should have a About p

我正在试火车。我正在使用 网站了解更多关于rails3的信息;本教程从一开始就非常好(我对rails2的经验很少)

我与rspec有一个问题,目前阻碍了我的进度。我看到教程推荐使用rspec2.0.0.beta.18 gem;我改为使用安装rspec2.0.0.beta.20 gem

bundle install
但是,我发现这个版本的rspec存在问题 我的集成测试rspec如下所示:

describe "LayoutLinks" do
  it "should have a About page at '/about'" do  
    get '/about'
    response.should have_selector('h1', :content => "About Us")
  end 
end
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
失败看起来像:

describe "LayoutLinks" do
  it "should have a About page at '/about'" do  
    get '/about'
    response.should have_selector('h1', :content => "About Us")
  end 
end
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
(注意:那些看过的人在理解上下文时不会有问题。)

如果我在Gemfile中将rspec版本更改为2.0.0.beta.18并运行rspec,则会出现以下错误

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'
arun@ubuntu-世界:~/Project/Rails/rails3/sample\u app$rspec spec/
/home/arun/.rvm/gems/ruby-1.9.2-p0/gems/bundler-1.0.0/lib/bundler/runtime.rb:27:“设置中的块”:您已经激活了rspec core 2.0.0.beta.20,但您的GEM文件需要rspec core 2.0.0.beta.18。考虑使用捆绑Excel。(Gem::LoadError)
from/home/arun/.rvm/gems/ruby-1.9.2-p0/gems/bundler-1.0.0/lib/bundler/spec_set.rb:12:在“每个块中”
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:在“设置”中
from/home/arun/.rvm/gems/ruby-1.9.2-p0/gems/bundler-1.0.0/lib/bundler.rb:100:在“设置”中
from/home/arun/Project/Rails/rails3/sample\u app/config/boot.rb:8:in`'
from:29:in'require'
from:29:in'require'
from/home/arun/Project/Rails/rails3/sample\u app/config/application.rb:1:in`'
from:29:in'require'
from:29:in'require'
from/home/arun/Project/Rails/rails3/sample\u app/config/environment.rb:2:in`'
from:29:in'require'
from:29:in'require'
from/home/arun/Project/Rails/rails3/sample\u app/spec/spec\u helper.rb:3:in`'
from:29:in'require'
from:29:in'require'
from/home/arun/Project/Rails/rails3/sample\u app/spec/requests/layout\u links\u spec.rb:1:in`'
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:“加载规范文件中的块”
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:在“加载规范文件”中
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:“运行”
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\u in\u进程'
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“自动运行中的块”

第二个错误应该通过在更改文件时重新运行
bundle install
来修复

至于第一个错误,您能发布routes.rb文件中定义“/about”路由的行吗?

我再次运行了“bundle install”,当我查看Gemfile和Gemfile.lock时,无论我使用的是2.0.0.beta.18还是2.0.0.beta.20,我都会找到相应的gems

routes.rb映射/关于属于特定控制器的特定操作。当我在浏览器中访问页面时,我也会得到正确的页面;因此,我认为这不是问题所在。(很遗憾,我现在没有代码,无法将其粘贴到此处)

以下是我无法理解的错误

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)
我知道bundle exec是什么,更不用说如何使用它了


--Arun

您需要使用gem卸载删除其中一个gem:

$gem卸载rspec内核-v2.0.0.beta.20


您还可以使用gem list查看您安装的gems的版本。

Rspec在Hartl教程的11章中一直运行良好。但不知何故,我弄乱了我的gemfille,我开始遇到同样的问题,rspec“堆栈级别太深”,无法通过“捆绑安装”解决。于是我疯狂地做了一个梦

windows> gem uninstall rspec rspec-rails rspec-expectations rspec-mock rspec-core
(所有版本)。'“创业板名单”显示他们确实都走了。然后我执行了一个命令

> 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)
...
这就是我档案中的内容。然而,一个“gem列表-d rspec”仍然显示没有安装rspec或rspec xxx gem以及rspec核心问题

> 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)
但“捆绑列表”显示它已安装。那么,如何让rspec再次工作


更新

我解决了这个问题,但首先我要向阿伦·库马尔(arun kumar)致以最谦卑的歉意,因为他对自己的问题不屑一顾,并在问题和答案之间插手。我认为我的问题是类似的,我的“答案”是最后的位置。 首先,我必须做一个测试

> gem install rspec -v 2.0.0.beta.22
> gem install rspec-rails -v 2.0.0.beta.22
而不是期望bundler这样做。bundler在这里似乎不可靠。这使我对rspec的调用再次起作用,但我仍然必须处理“堆栈级别太深”的问题。这是通过将rspec和rspec rails升级到2.0.1(来自David Chelimski:)来解决的。再次更改我的Gemfile并调用bundle安装没有起作用。我必须卸载所有五个rspec xxx gems,就像上面所说的那样,然后手动执行

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

也许我不需要先卸载,但我确实卸载了。海报很可能已经解决了他的问题,因为那是很久以前的事了,但这里是我的解决方案,可能对其他人有用——回想一下我有Windows Vista64。

我也有同样的问题。此时,来自/spec/requests/layout\u links\u spec.rb的测试都失败,并出现相同的错误(控制器测试工作正常):

在对/spec/request执行一些故障排除之后
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
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
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
bundle exec rake db:test:prepare