Rails3 rspec 问题

发布于 2024-09-19 00:17:50 字数 4081 浏览 5 评论 0原文

我正在尝试rails3。我正在使用 railstutorial 探索有关 Rails3 的更多信息的网站;该教程非常适合入门(我对rails2 的经验很少)。

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

bundle install

但是我发现此版本的 rspec 存在问题 我的 Integration_test 的 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

(注意:那些看过 第 5 章在理解上下文时不会出现问题。)

如果我在 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'

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'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

赠我空喜 2024-09-26 00:17:51

我也有同样的问题。在第 5 章末尾,来自 /spec/requests/ 的测试layout_links_spec.rb 都因相同的错误而失败(控制器测试工作得很好):

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

在对 /spec/requests/layout_links_spec.rb 文件进行一些故障排除后,似乎在这种情况下使用响应是触发问题的原因。例如,如果文件如下所示,则不会出现错误:

require 'spec_helper'

describe "LayoutLinks" do

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

但从教程复制的文件显示为:

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

一旦调用 response,就会引发错误

这是在 Windows 7 上(我已经尝试在系统级别而不是在 Cygwin 中设置 Ruby、Git、Vim 和其他开发工具)。

Rspeicher - 按照 RailsTutorial.org 的步骤,/config/routes.rb 文件看起来像这样:

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

就像 Arun 所说,这一切都在浏览器中按预期工作,因此问题似乎出在 rspec 中的某个地方或红宝石。我想如果 ruby​​ 安装在 Cygwin 下这不是问题。我希望不必恢复到纯 Cygwin 环境,特别是因为我的 webroot 和项目文件已经在 Cygwin 的虚拟 unix 文件夹结构之外进行管理。

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.

一腔孤↑勇 2024-09-26 00:17:51

每当您更改 Gemfile 时,都应该通过重新运行 bundle install 来修复第二个错误。

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

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?

白首有我共你 2024-09-26 00:17:51

我再次运行“捆绑安装”,当我查看 Gemfile 和 Gemfile.lock 时,我发现无论我使用 2.0.0.beta.18 还是 2.0.0.beta.20,都捆绑了适当的 gem。

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

以下是我无法理解的错误

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是什么,更不用说如何使用它了...--

阿伦

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

維他命╮ 2024-09-26 00:17:51

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

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

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

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.

烂人 2024-09-26 00:17:51

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)
...

Gemfile 中的内容。然而,“gem list -d rspec”仍然显示安装了 -no- rspec 或 rspec-xxx gems 和 rspec-core 问题...

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

但是“bundle list”表示它已安装。那么如何让 rspec 再次工作呢?


更新

我解决了这个问题,但首先我对arun kumar表示最诚挚的歉意,因为他对他的问题犹豫不决,并介于它和答案之间。我认为我的问题是相似的,我的“答案”将放在最后。

首先,我必须做一个

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

而不是期望捆绑器来做。捆绑器在这里似乎不可靠。这让我对 rspec 的调用再次起作用,但我仍然必须处理“堆栈级别太深”的问题。通过将 rspec 和 rspec-rails 升级到 2.0.1(来自 David Chelimski:http:// www.ruby-forum.com/topic/282245)。再次更改我的 Gemfile 并调用bundle-install 不起作用。我必须像上面一样卸载所有五个 rspec-xxx gem,并手动执行,

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

也许我不需要先卸载,但我做到了。发帖者可能已经解决了他的问题,因为这个问题很久以前就已经解决了,但这是我的解决方案,可能对其他人也适用 - 记得我有 Windows Vista64。

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.

乱世争霸 2024-09-26 00:17:51

它绝对与 Windows 或您所在的任何环境无关。我的 Mac 也遇到同样的情况。

我的 routes.rb 文件(来自同一教程)如下所示:

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

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
扮仙女 2024-09-26 00:17:51

你也可以尝试运行

bundle exec rake db:test:prepare

You could also try running

bundle exec rake db:test:prepare
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文