3

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'
4

7 に答える 7

2

私は同じ問題を抱えています。第 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ファイルで少しトラブルシューティングを行った後、responseこのコンテキスト内で使用すると問題が発生するようです。たとえば、ファイルが次のようになっている場合、エラーは発生しません。

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 に ruby​​ がインストールされていれば問題ないと思います。純粋な Cygwin 環境に戻す必要がないように願っていました。特に、Webroot とプロジェクト ファイルが Cygwin の仮想 UNIX フォルダー構造の外で既に管理されているためです。

于 2010-11-12T14:57:25.113 に答える
0

それは間違いなく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
于 2010-11-14T19:58:38.247 に答える
0

実行することもできます

bundle exec rake db:test:prepare
于 2013-07-03T23:09:43.120 に答える
0

「bundle install」を再度実行し、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の使い方は言うまでもなく、bundle execが何であるかは知っています...

-- アルン

于 2010-09-14T11:38:39.583 に答える
0

gem uninstall を使用して、gem の 1 つを削除する必要があります。

$ gem アンインストール rspec-core -v 2.0.0.beta.20

gem list を使用して、インストールした gem のバージョンを表示することもできます。

于 2010-09-29T01:28:30.287 に答える
0

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

しかし、「バンドルリスト」にはインストールされていると表示されます。では、rspec を再び機能させるにはどうすればよいでしょうか。


アップデート

私は問題を修正しましたが、最初に arun kumarが彼の質問に固執し、質問と回答の間に割り込んでしまったことを心からお詫び申し上げます。私の問題は似ていて、私の「答え」は最後にあると思いました。

まず第一に、私はしなければならなかった

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

バンドラーがそれを行うことを期待する代わりに。bundler はここでは信頼できないようです。これにより、rspec への呼び出しが再び機能するようになりましたが、「スタック レベルが深すぎる」​​ことに対処する必要がありました。これは、rspec と rspec-rails を 2.0.1 にアップグレードすることで修正されました (David Chelimski から: http://www.ruby-forum.com/topic/282245 )。Gemfile を再度変更して bundle-install を呼び出しても機能しませんでした。上記のように5つのrspec-xxx gemをすべてアンインストールし、手動でアンインストールする必要がありました

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

最初にアンインストールする必要はなかったかもしれませんが、アンインストールしました。投稿者はかなり前に問題を解決した可能性がありますが、他の人にも役立つ可能性のある私の解決策を次に示します。Windows Vista64 を使用していることを思い出してください。

于 2010-10-23T05:48:18.263 に答える
0

bundle install2 番目のエラーは、Gemfile を変更するたびに再実行して修正する必要があります。

最初のエラーについては、「/about」ルートを定義する routes.rb ファイルの行を投稿していただけますか?

于 2010-09-12T20:04:21.367 に答える